Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int budget = Integer.parseInt(scanner.nextLine());
- String season = scanner.nextLine();
- int numberFishermen = Integer.parseInt(scanner.nextLine());
- // Initialize a variable for the price and set it to 0 at first:
- double boatRentalPrice = 0;
- // Then perform a series of checks and change the price according to the season:
- if (season.equals("Spring")){
- boatRentalPrice = 3000;
- }
- else if (season.equals("Summer") || season.equals("Autumn")){
- boatRentalPrice = 4200;
- }
- else if (season.equals("Winter")){
- boatRentalPrice = 2600;
- }
- // Perform a series of checks to see how many fishermen are on the boat. Apply the discounts accordingly:
- if (numberFishermen <= 6){
- boatRentalPrice -= boatRentalPrice * 0.10; // Remove 10%
- // Another way to do this is the following: boatRentalPrice *= 0.90; (we just take 90% instead of removing 10% - it will give the same result)
- }
- else if (numberFishermen >= 7 && numberFishermen <= 11){
- boatRentalPrice -= boatRentalPrice * 0.15;
- }
- else if (numberFishermen >= 12){
- boatRentalPrice -= boatRentalPrice * 0.25;
- }
- // 5% discount if the number of fishermen is even, be careful with the additional condition - this discount should NOT be applied if it's Autumn!
- if (numberFishermen % 2 == 0 && !season.equals("Autumn")){
- boatRentalPrice -= boatRentalPrice * 0.05;
- }
- // And finally, check if their budget is enough and print the messages:
- if (boatRentalPrice <= budget){
- System.out.printf("Yes! You have %.2f dollars left.", (budget - boatRentalPrice));
- }
- else{
- System.out.printf("Not enough money! You need %.2f dollars.", (boatRentalPrice - budget));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement