+ Нов въпрос
AntoanMashkov 2 Точки

## Fishing Boat problem

```Judge ми дава 86/100 някой има ли идея къде ми е грешката ? Благодаря.

import java.util.Scanner;

public class Puppy {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int budget = Integer.parseInt(scanner.nextLine());
String season = scanner.nextLine();
int fishermanCount = Integer.parseInt(scanner.nextLine());
double price = 0;

if (season.equals("Spring")) {
price = 3000;
if (fishermanCount <= 6) {
price = price - price * 0.1;
} else if (fishermanCount >= 7 && fishermanCount <= 11) {
price = price - price * 0.15;
} else if (fishermanCount >= 12) {
price = price - price * 0.25;
}
if (fishermanCount % 2 == 0) {
price = price - price * 0.05;
}
if (budget < price) {
System.out.printf("Not enough money! You need %.2f leva.", Math.abs(price - budget));
} else if (budget > price) {
System.out.printf("Yes! You have %.2f leva left.", Math.abs(price - budget));
}
} else if (season.equals("Summer")) {
price = 4200;
if (fishermanCount <= 6) {
price = price - price * 0.1;
} else if (fishermanCount >= 7 && fishermanCount <= 11) {
price = price - price * 0.15;
} else if (fishermanCount >= 12) {
price = price - price * 0.25;
}
if (fishermanCount % 2 == 0) {
price = price - price * 0.05;
}
if (budget < price) {
System.out.printf("Not enough money! You need %.2f leva.", Math.abs(price - budget));
} else if (budget > price) {
System.out.printf("Yes! You have %.2f leva left.", Math.abs(price - budget));
}
} else if (season.equals("Autumn")) {
price = 4200;
if (fishermanCount <= 6) {
price = price - price * 0.1;
} else if (fishermanCount >= 7 && fishermanCount <= 11) {
price = price - price * 0.15;
} else if (fishermanCount >= 12) {
price = price - price * 0.25;
}
if (budget < price) {
System.out.printf("Not enough money! You need %.2f leva.", Math.abs(price - budget));
} else if (budget > price) {
System.out.printf("Yes! You have %.2f leva left.", Math.abs(price - budget));
}
} else if (season.equals("Winter")) {
price = 2600;
if (fishermanCount <= 6) {
price = price - price * 0.1;
} else if (fishermanCount >= 7 && fishermanCount <= 11) {
price = price - price * 0.15;
} else if (fishermanCount >= 12) {
price = price - price * 0.25;
}
if (fishermanCount % 2 == 0) {
price = price - price * 0.05;
}
if (budget < price) {
System.out.printf("Not enough money! You need %.2f leva.", Math.abs(price - budget));
} else if (budget > price) {
System.out.printf("Yes! You have %.2f leva left.", Math.abs(price - budget));
}
}
}
}```
Тагове:
0
svephoto 1061 Точки

Здравей, AntoanMashkov,

Причината е, че при всяка проверка за отпечатване на съобщение след като провериш за

`budget < price`

задаваш само

`budget > price`

и сътветно не покриваш случаи, в които

`budget >= price`

Можеш да решиш проблема и за 4-те проверки директно с else например така:

```            if (budget < price) {
System.out.printf("Not enough money! You need %.2f leva.", Math.abs(price - budget));
} else {
System.out.printf("Yes! You have %.2f leva left.", Math.abs(price - budget));
}```

След това вече ще стигнеш до 100/100. Вариант е и с

`else if (budget >= price)`

но това е равносилно на else.

0
26/09/2021 15:18:12