Advertisement
sanyakasarova

Fishing Boat

Aug 26th, 2021
1,268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int budget = Integer.parseInt(scanner.nextLine());
  8.         String season = scanner.nextLine();
  9.         int numberFishermen = Integer.parseInt(scanner.nextLine());
  10.  
  11.         // Initialize a variable for the price and set it to 0 at first:
  12.         double boatRentalPrice = 0;
  13.  
  14.         // Then perform a series of checks and change the price according to the season:
  15.         if (season.equals("Spring")){
  16.             boatRentalPrice = 3000;
  17.         }
  18.         else if (season.equals("Summer") || season.equals("Autumn")){
  19.             boatRentalPrice = 4200;
  20.         }
  21.         else if (season.equals("Winter")){
  22.             boatRentalPrice = 2600;
  23.         }
  24.  
  25.         // Perform a series of checks to see how many fishermen are on the boat. Apply the discounts accordingly:
  26.         if (numberFishermen <= 6){
  27.             boatRentalPrice -= boatRentalPrice * 0.10; // Remove 10%
  28.             // 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)
  29.         }
  30.         else if (numberFishermen >= 7 && numberFishermen <= 11){
  31.             boatRentalPrice -= boatRentalPrice * 0.15;
  32.         }
  33.         else if (numberFishermen >= 12){
  34.             boatRentalPrice -= boatRentalPrice * 0.25;
  35.         }
  36.  
  37.         // 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!
  38.         if (numberFishermen % 2 == 0 && !season.equals("Autumn")){
  39.             boatRentalPrice -= boatRentalPrice * 0.05;
  40.         }
  41.  
  42.         // And finally, check if their budget is enough and print the messages:
  43.         if (boatRentalPrice <= budget){
  44.             System.out.printf("Yes! You have %.2f dollars left.", (budget - boatRentalPrice));
  45.         }
  46.         else{
  47.             System.out.printf("Not enough money! You need %.2f dollars.", (boatRentalPrice - budget));
  48.         }
  49.     }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement