Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

VarshilovNikolay avatar VarshilovNikolay 0 Точки

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);
            }

        }



    }
}

 

 

 Не изглежда много добре ... 

Благодаря предварително

Тагове:
0
Programming Basics
aggeorgiev avatar aggeorgiev 326 Точки
Това е моето решение от изпита 100/100:

import java.util.Scanner;

/*** Created by AiKiHack on 07-05-2017 11:33 in project exam_07_05_2017 ***/

public class e_03_schoolVac {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        String season = cin.nextLine();
        String groupType = cin.nextLine();
        int count = Integer.parseInt(cin.nextLine());
        int nights = Integer.parseInt(cin.nextLine());
        String sport = "";
        double discount = 0;
        if (count >= 50) {
            discount = 0.5;
        } else if(count >= 20){
            discount = 0.15;
        } else if(count >= 10){
            discount = 0.05;
        }

        double price = 0;

        if (groupType.equals("boys")) {
            if (season.equals("Winter")) {
                price = (9.6 * count * nights) * (1 - discount);
                sport = "Judo";
            } else if(season.equals("Spring")){
                price = (7.2 * count * nights) * (1 - discount);
                sport = "Tennis";
            } else if(season.equals("Summer")){
                price = (15.0 * count * nights) * (1 - discount);
                sport = "Football";
            }
        } else if(groupType.equals("girls")){
            if (season.equals("Winter")) {
                price = (9.6 * count * nights) * (1 - discount);
                sport = "Gymnastics";
            } else if(season.equals("Spring")){
                price = (7.2 * count * nights) * (1 - discount);
                sport = "Athletics";
            } else if(season.equals("Summer")){
                price = (15.0 * count * nights) * (1 - discount);
                sport = "Volleyball";
            }
        } else {
            if (season.equals("Winter")) {
                price = (10.0 * count * nights) * (1 - discount);
                sport = "Ski";
            } else if(season.equals("Spring")){
                price = (9.5 * count * nights) * (1 - discount);
                sport = "Cycling";
            } else if(season.equals("Summer")){
                price = (20.0 * count * nights) * (1 - discount);
                sport = "Swimming";
            }
        }

        System.out.printf("%s %.2f lv.", sport, price);
    }
}
0
Missing avatar Missing 1 Точки
import java.util.Scanner;

public class p03 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String season = scanner.nextLine();
        String groupType = scanner.nextLine();
        int children = Integer.parseInt(scanner.nextLine());
        int nights = Integer.parseInt(scanner.nextLine());
        double nightPrice = 0;
        String sport = "";
        if (groupType.equals("girls")) {
            switch (season) {
                case "Winter":
                    nightPrice = nights * children * 9.60;
                    sport = "Gymnastics";
                    break;
                case "Spring":
                    nightPrice = nights * children * 7.20;
                    sport = "Athletics";
                    break;
                case "Summer":
                    nightPrice = nights * children * 15;
                    sport = "Volleyball";
                    break;
            }
        } else if (groupType.equals("mixed")) {

            switch (season) {
                case "Winter":
                    nightPrice = nights * children * 10.0;
                    sport = "Ski";
                    break;
                case "Spring":
                    nightPrice = nights * children * 9.50;
                    sport = "Cycling";
                    break;
                case "Summer":
                    nightPrice = nights * children * 20.0;
                    sport = "Swimming";
                    break;
            }

        }  else if (groupType.equals("boys")) {

            switch (season) {
                case "Winter":
                    nightPrice = nights * children * 9.60;
                    sport = "Judo";
                    break;
                case "Spring":
                    nightPrice = nights * children * 7.20;
                    sport = "Tennis";
                    break;
                case "Summer":
                    nightPrice = nights * children * 15;
                    sport = "Football";
                    break;
            }

        }

        if (children >= 50) {
            nightPrice = nightPrice * 0.5;
        } else if (children >=20 && children < 50) {
            nightPrice = nightPrice - (nightPrice * 0.15);
        } else if (children >= 10 && children < 20) {
            nightPrice = nightPrice - (nightPrice * 0.05);
        }

        System.out.printf("%s %.2f lv.", sport, nightPrice);


    }
}

Това е моето решение. 

0
DilyanaGeorgieva avatar DilyanaGeorgieva 81 Точки

Аз я реших като написах if-esle if за сезоните, вложен if-else if(и switch става) за вида група(момчета, момичета, смесена), където си определих спорта и цените. Написах формулата за цената на лагера. След това if-else if  за бройката и отстъпките и накрая печат.

https://pastebin.com/4ysdVWzm

0
18/05/2017 10:34:40
detkov avatar detkov 3 Точки

Не е хубав кода, особено това, че на всеки иф елс изкарваш в конзолата. по-добре да оставиш изхода отделно най-отдолу .

проблема е някъде 20-ти ред;

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);
                 System.out.printf("%.2f lv.",nightsPrice);   <------ това липсваше.

Сметнал си го, но не си написал да го изкара на конзолата.

Приятен ден.

0
18/05/2017 12:24:25
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.