Fishing Boat проблем
Здравейе, решавам задачата по два различи начина и Judge все ми дава 60/100 и немога да си видя грешката, на на показаните в задачата проверки работи правилно.
import java.util.Scanner;
public class FishingBoat {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int budget = Integer.parseInt(scanner.nextLine());
String season = scanner.nextLine();
int fishingMen = Integer.parseInt(scanner.nextLine());
double priceBoat = 0;
double discount = 0;
if (season.equals("Spring")) {
priceBoat = 3000;
} else if (season.equals("Summer") || season.equals("Autumn")) {
priceBoat = 4200;
} else {
priceBoat = 2600;
}
if (fishingMen <= 6) {
discount = priceBoat * 0.1;
} else if (fishingMen <= 11) {
discount = priceBoat * 0.15;
} else {
discount = priceBoat * 0.25;
}
if (fishingMen % 2 == 0 && !season.equals("Autumn")) {
discount = discount * 0.95;
}
double lastPrice = priceBoat - discount;
double moneyLeft = budget - lastPrice;
if (budget >= lastPrice) {
System.out.printf("Yes! You have %.2f leva left.", moneyLeft);
} else {
System.out.printf("Not enough money! You need %.2f leva.", Math.abs(moneyLeft));
}
}
}
Здрасти и така го променям и пак 60/100
. А и аз го разбирам, че когато са четен брой тогава не добавям 5% към отстъпката.
discount = discount + (discount * 0.05);
Видях се грешката, много ти благодаря за съдействието, ето го и кода
import java.util.Scanner; public class FishingBoat { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int budget = Integer.parseInt(scanner.nextLine()); String season = scanner.nextLine(); int fishingMen = Integer.parseInt(scanner.nextLine()); double priceBoat = 0; double discount = 0; if (season.equals("Spring")) { priceBoat = 3000; } else if (season.equals("Summer") || season.equals("Autumn")) { priceBoat = 4200; } else { priceBoat = 2600; } if (fishingMen <= 6) { discount = priceBoat * 0.1; } else if (fishingMen <= 11) { discount = priceBoat * 0.15; } else { discount = priceBoat * 0.25; } double lastPrice = priceBoat - discount; if (fishingMen % 2 == 0 && !season.equals("Autumn")) { lastPrice = lastPrice - (lastPrice * 0.05); } double moneyLeft = budget - lastPrice; if (budget >= lastPrice) { System.out.printf("Yes! You have %.2f leva left.", moneyLeft); } else { System.out.printf("Not enough money! You need %.2f leva.", Math.abs(moneyLeft)); } } }