Advertisement
Guest User

Fishing Boat

a guest
Apr 9th, 2020
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.28 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*Description
  4. Tony and his friends decided to rent a boat - the rent depends on the season and the number of fishermen.
  5. The price on the basis of season:
  6. Spring - 3000 $
  7. Summer and autumn - 4200 $
  8. Winter - 2600 $
  9. The price on the basis of number of fishermen uses discount:
  10. If the group is up to 6 people (inclusive) - 10% discount
  11. If the group members are in range [7…11] - 15% discount
  12. If the group is 12 or more people - 25% discount
  13. The fishermen use another 5 % discount if they are even number except when it is NOT autumn – then they do NOT have additional discount.
  14. Write a program to calculate whether the fishermen will gather enough money.
  15. Input
  16. The input is consists of exactly 3 lines:
  17. The budget of the group - real number in range [1…8000]
  18. Season - String : "Spring", "Summer", "Autumn", "Winter"
  19. Number of fishermen - integer in range [4…18]
  20. Output
  21. Print on the console a single line:
  22. If the budget IS enough: "Yes! You have {money left} dollars left."
  23. If the budget IS NOT enough: "Not enough money! You need {money needed} dollars."
  24. The prices should be formatted to the second decimal point. */
  25.  
  26. public class FishingBoat {
  27.  
  28.     public static void main(String[] args) {
  29.         Scanner scanner = new Scanner(System.in);
  30.         double groupBudget = scanner.nextDouble();
  31.         scanner.nextLine();
  32.         String season = scanner.nextLine();
  33.         int fishermanNumber = scanner.nextInt();
  34.        
  35.         //prices
  36.         int seasonPrice = 0;
  37.         int discount = 0;
  38.         double totalP = 0;
  39.         double s = 0;
  40.         double moneyLeft = 0;
  41.        
  42.         switch (season) {
  43.         case "Spring":
  44.             seasonPrice = 3000;
  45.            
  46.             if(fishermanNumber <= 6)
  47.             discount += 10;
  48.            
  49.             if(fishermanNumber >= 7 && fishermanNumber <= 11)
  50.             discount += 15;
  51.            
  52.             if(fishermanNumber >= 12)
  53.             discount += 25;
  54.        
  55.             s = 100-discount;
  56.             totalP = (s*seasonPrice)/100;
  57.            
  58.             if(fishermanNumber % 2 == 0) {
  59.             discount = 5;
  60.             s = 100-discount;
  61.             totalP = (s*totalP)/100;
  62.             }
  63.            
  64.             if(groupBudget < totalP) {
  65.             moneyLeft = totalP - groupBudget;
  66.             System.out.printf("Not enough money! You need %.2f dollars.", moneyLeft);          
  67.             } else {
  68.             moneyLeft = groupBudget - totalP;  
  69.             System.out.printf("Yes! You have %.2f dollars left.", moneyLeft);
  70.             }
  71.             break;
  72.         case "Summer":
  73.             seasonPrice = 4200;
  74.            
  75.             if(fishermanNumber <= 6)
  76.             discount += 10;
  77.            
  78.             if(fishermanNumber >= 7 && fishermanNumber <= 11)
  79.             discount += 15;
  80.            
  81.             if(fishermanNumber >= 12)
  82.             discount += 25;
  83.            
  84.             s = 100-discount;
  85.             totalP = (s*seasonPrice)/100;
  86.            
  87.            if(fishermanNumber % 2 == 0) {
  88.             discount = 5;
  89.             s = 100-discount;
  90.             totalP = (s*totalP)/100;
  91.             }
  92.            
  93.             if(groupBudget < totalP) {
  94.             moneyLeft = totalP - groupBudget;
  95.             System.out.printf("Not enough money! You need %.2f dollars.", moneyLeft);          
  96.             } else {
  97.             moneyLeft = groupBudget - totalP;  
  98.             System.out.printf("Yes! You have %.2f dollars left.", moneyLeft);
  99.             }
  100.             break;
  101.         case "Autumn":
  102.             seasonPrice = 4200;        
  103.             if(fishermanNumber <= 6)
  104.             discount += 10;
  105.            
  106.             if(fishermanNumber >= 7 && fishermanNumber <= 11)
  107.             discount += 15;
  108.            
  109.             if(fishermanNumber >= 12)
  110.             discount += 25;
  111.            
  112.             s = 100-discount;
  113.             totalP = (s*seasonPrice)/100;
  114.  
  115.            
  116.             if(groupBudget < totalP) {
  117.             moneyLeft = totalP - groupBudget;
  118.             System.out.printf("Not enough money! You need %.2f dollars.", moneyLeft);          
  119.             } else {
  120.             moneyLeft = groupBudget - totalP;  
  121.             System.out.printf("Yes! You have %.2f dollars left.", moneyLeft);
  122.             }
  123.             break;
  124.         case "Winter":
  125.             seasonPrice = 2600;
  126.            
  127.             if(fishermanNumber <= 6)
  128.             discount += 10;
  129.            
  130.             if(fishermanNumber >= 7 && fishermanNumber <= 11)
  131.             discount += 15;
  132.            
  133.             if(fishermanNumber >= 12)
  134.             discount += 25;
  135.            
  136.             s = 100-discount;
  137.             totalP = (s*seasonPrice)/100;
  138.  
  139.             if(fishermanNumber % 2 == 0) {
  140.             discount = 5;
  141.             s = 100-discount;
  142.             totalP = (s*totalP)/100;
  143.             }
  144.            
  145.             if(groupBudget < totalP) {
  146.             moneyLeft = totalP - groupBudget;
  147.             System.out.printf("Not enough money! You need %.2f dollars.", moneyLeft);          
  148.             } else {
  149.             moneyLeft = groupBudget - totalP;  
  150.             System.out.printf("Yes! You have %.2f dollars left.", moneyLeft);
  151.             }          
  152.             break;
  153.         }
  154.  
  155.     }
  156.  
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement