Programming Basics Exam - 7 May 2017 , Задача 3. Ученически лагер
Здравейте на всички, моля за малко помощ по конкретната задача. Задачата ми мина в Джъджа 90/100 , но като цяло хич не си харесвам кода и знам, че има и по-лесен начин за решение на задачата. Ако може за насоки и за решението да си го разцъкам и аз.
Ето и моя код:
import java.util.Scanner; /** * Created by Nico on 5/17/2017. */ public class SchoolCamp { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String season = scanner.nextLine(); String group = scanner.nextLine(); int students = Integer.parseInt(scanner.nextLine()); int nights = Integer.parseInt(scanner.nextLine()); if (season.equals("Spring") && group.equals("girls")){ System.out.print("Athletics "); double nightsPrice = students * nights * 7.20; if (students >= 50){ nightsPrice = nightsPrice - (nightsPrice * 0.50); }else if (students >= 20 && students < 50) { nightsPrice = nightsPrice - (nightsPrice * 0.15); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 10 && students < 20){ nightsPrice = nightsPrice - (nightsPrice * 0.05); System.out.printf("%.2f lv.",nightsPrice); }else { System.out.printf("%.2f lv.",nightsPrice); } } if (season.equals("Spring") && group.equals("boys")){ System.out.print("Tennis "); double nightsPrice = students * nights * 7.20; if (students >= 50){ nightsPrice = nightsPrice - (nightsPrice * 0.50); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 20 && students < 50) { nightsPrice = nightsPrice - (nightsPrice * 0.15); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 10 && students < 20){ nightsPrice = nightsPrice - (nightsPrice * 0.05); System.out.printf("%.2f lv.",nightsPrice); }else { System.out.printf("%.2f lv.",nightsPrice); } } if (season.equals("Spring") && group.equals("mixed")){ System.out.print("Cycling "); double nightsPrice = students * nights * 9.50; if (students >= 50){ nightsPrice = nightsPrice - (nightsPrice * 0.50); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 20 && students < 50) { nightsPrice = nightsPrice - (nightsPrice * 0.15); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 10 && students < 20){ nightsPrice = nightsPrice - (nightsPrice * 0.05); System.out.printf("%.2f lv.",nightsPrice); }else { System.out.printf("%.2f lv.",nightsPrice); } } if (season.equals("Winter") && group.equals("girls")){ System.out.print("Gymnastics "); double nightsPrice = students * nights * 9.60; if (students >= 50){ nightsPrice = nightsPrice - (nightsPrice * 0.50); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 20 && students < 50) { nightsPrice = nightsPrice - (nightsPrice * 0.15); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 10 && students < 20){ nightsPrice = nightsPrice - (nightsPrice * 0.05); System.out.printf("%.2f lv.",nightsPrice); }else { System.out.printf("%.2f lv.",nightsPrice); } } if (season.equals("Winter") && group.equals("boys")){ System.out.print("Judo "); double nightsPrice = students * nights * 9.60; if (students >= 50){ nightsPrice = nightsPrice - (nightsPrice * 0.50); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 20 && students < 50) { nightsPrice = nightsPrice - (nightsPrice * 0.15); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 10 && students < 20){ nightsPrice = nightsPrice - (nightsPrice * 0.05); System.out.printf("%.2f lv.",nightsPrice); }else { System.out.printf("%.2f lv.",nightsPrice); } } if (season.equals("Winter") && group.equals("mixed")){ System.out.print("Ski "); double nightsPrice = students * nights * 10.0; if (students >= 50){ nightsPrice = nightsPrice - (nightsPrice * 0.50); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 20 && students < 50) { nightsPrice = nightsPrice - (nightsPrice * 0.15); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 10 && students < 20){ nightsPrice = nightsPrice - (nightsPrice * 0.05); System.out.printf("%.2f lv.",nightsPrice); }else { System.out.printf("%.2f lv.",nightsPrice); } } if (season.equals("Summer") && group.equals("girls")){ System.out.print("Volleyball "); double nightsPrice = students * nights * 15.0; if (students >= 50){ nightsPrice = nightsPrice - (nightsPrice * 0.50); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 20 && students < 50) { nightsPrice = nightsPrice - (nightsPrice * 0.15); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 10 && students < 20){ nightsPrice = nightsPrice - (nightsPrice * 0.05); System.out.printf("%.2f lv.",nightsPrice); }else { System.out.printf("%.2f lv.",nightsPrice); } } if (season.equals("Summer") && group.equals("boys")){ System.out.print("Football "); double nightsPrice = students * nights * 15.0; if (students >= 50){ nightsPrice = nightsPrice - (nightsPrice * 0.50); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 20 && students < 50) { nightsPrice = nightsPrice - (nightsPrice * 0.15); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 10 && students < 20){ nightsPrice = nightsPrice - (nightsPrice * 0.05); System.out.printf("%.2f lv.",nightsPrice); }else { System.out.printf("%.2f lv.",nightsPrice); } } if (season.equals("Summer") && group.equals("mixed")){ System.out.print("Swimming "); double nightsPrice = students * nights * 20.0; if (students >= 50){ nightsPrice = nightsPrice - (nightsPrice * 0.50); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 20 && students < 50) { nightsPrice = nightsPrice - (nightsPrice * 0.15); System.out.printf("%.2f lv.",nightsPrice); }else if (students >= 10 && students < 20){ nightsPrice = nightsPrice - (nightsPrice * 0.05); System.out.printf("%.2f lv.",nightsPrice); }else { System.out.printf("%.2f lv.",nightsPrice); } } } }
Не изглежда много добре ...
Благодаря предварително