Задача Toy Store от Java Lab 20.10: някой успя ли да я реши?
Здравейте колеги,
Решавам задачата с магазина за детски играчки от лаб-а днес, 20 октомври.
Задачата не е задължителна, но е интересна.
Та, кодът работи и с двете проверки, но джъдж нещо не го харесва. За съжаление не мога да разбера какво точно не е наред при проверките, защото получавам това съобщение:
The process executing your submission for this test may not have received the output successfully. Please try to submit again the same solution. If the result does not change, then search the error in the submission itself.
Може ли някой да удари едно рамо и да каже къде бъркам...
Ето го и кодът, не е оптимално форматиран, но нали все пак се учим...:
import java.util.Scanner; public class ToyStore { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double HolidayPrice = Double.parseDouble(scanner.nextLine()); int puzzles = Integer.parseInt(scanner.nextLine()); int dolls = Integer.parseInt(scanner.nextLine()); int teddyBears = Integer.parseInt(scanner.nextLine()); int minions = Integer.parseInt(scanner.nextLine()); int trucks = Integer.parseInt(scanner.nextLine()); int ToysAmount = (puzzles+dolls+teddyBears+minions+trucks); double toysSales = (puzzles*2.6 + dolls*3 + teddyBears*4.1 + minions*8.2 + trucks*2); if (ToysAmount>50){ double profitAfterRent = (toysSales*0.75)*0.9; { if (profitAfterRent >= HolidayPrice) { System.out.printf("Yes!" + " " + "%.2f" + " lv left.", (profitAfterRent - HolidayPrice)); } }} else if(ToysAmount<50){ double profitNoDiscount = toysSales*0.9;{ if(profitNoDiscount>=HolidayPrice){ System.out.printf("Yes!"+" "+"%.2f" + " lv left.", (profitNoDiscount-HolidayPrice)); }else { System.out.printf("Not enough money!" + " " + "%.2f" + " lv needed.", (HolidayPrice - profitNoDiscount)); }}}}}
Благодаря на ентусиастите!
Руми
import java.util.Scanner;
public class Toy_Shop{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double puzzel_price = 2.60;
double dole_price = 3;
double bear_price = 4.10;
double minion_price = 8.20;
double truck_price = 2;
double trip = Double.parseDouble(scanner.nextLine());
double puzzel_count = Double.parseDouble(scanner.nextLine());
double dole_count = Double.parseDouble(scanner.nextLine());
double bear_count = Double.parseDouble(scanner.nextLine());
double minion_count = Double.parseDouble(scanner.nextLine());
double truck_count = Double.parseDouble(scanner.nextLine());
double total_count = puzzel_count + dole_count + bear_count + minion_count + truck_count;
double total_revenue = ( puzzel_count * puzzel_price ) + ( dole_count * dole_price) + ( bear_count * bear_price) + ( minion_count * minion_price) + ( truck_count * truck_price);
if ((total_count >= 50) & (total_revenue * 0.75 * 0.9) >= trip ) {
System.out.printf("Yes! %.2f lv left.", (total_revenue * 0.75 * 0.9) - trip);
} else if ((total_count < 50) & (total_revenue * 0.9) >= trip ) {
System.out.printf("Yes! %.2f lv left.", (total_revenue * 0.9) - trip);
} else if ( (total_count >= 50) & (total_revenue * 0.75 * 0.9) < trip ) {
System.out.printf("Not enough money! %.2f lv needed.", trip - (total_revenue * 0.75 * 0.9));
} else if ( (total_count < 50) & (total_revenue * 0.9) < trip ) {
System.out.printf("Not enough money! %.2f lv needed.", trip - (total_revenue * 0.9));
}
}
}
Благодаря,
Реорганизирах if проверката по подобен на твоя начин и този път се получи.