Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /*Description
- Tony and his friends decided to rent a boat - the rent depends on the season and the number of fishermen.
- The price on the basis of season:
- Spring - 3000 $
- Summer and autumn - 4200 $
- Winter - 2600 $
- The price on the basis of number of fishermen uses discount:
- If the group is up to 6 people (inclusive) - 10% discount
- If the group members are in range [7…11] - 15% discount
- If the group is 12 or more people - 25% discount
- The fishermen use another 5 % discount if they are even number except when it is NOT autumn – then they do NOT have additional discount.
- Write a program to calculate whether the fishermen will gather enough money.
- Input
- The input is consists of exactly 3 lines:
- The budget of the group - real number in range [1…8000]
- Season - String : "Spring", "Summer", "Autumn", "Winter"
- Number of fishermen - integer in range [4…18]
- Output
- Print on the console a single line:
- If the budget IS enough: "Yes! You have {money left} dollars left."
- If the budget IS NOT enough: "Not enough money! You need {money needed} dollars."
- The prices should be formatted to the second decimal point. */
- public class FishingBoat {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double groupBudget = scanner.nextDouble();
- scanner.nextLine();
- String season = scanner.nextLine();
- int fishermanNumber = scanner.nextInt();
- //prices
- int seasonPrice = 0;
- int discount = 0;
- double totalP = 0;
- double s = 0;
- double moneyLeft = 0;
- switch (season) {
- case "Spring":
- seasonPrice = 3000;
- if(fishermanNumber <= 6)
- discount += 10;
- if(fishermanNumber >= 7 && fishermanNumber <= 11)
- discount += 15;
- if(fishermanNumber >= 12)
- discount += 25;
- s = 100-discount;
- totalP = (s*seasonPrice)/100;
- if(fishermanNumber % 2 == 0) {
- discount = 5;
- s = 100-discount;
- totalP = (s*totalP)/100;
- }
- if(groupBudget < totalP) {
- moneyLeft = totalP - groupBudget;
- System.out.printf("Not enough money! You need %.2f dollars.", moneyLeft);
- } else {
- moneyLeft = groupBudget - totalP;
- System.out.printf("Yes! You have %.2f dollars left.", moneyLeft);
- }
- break;
- case "Summer":
- seasonPrice = 4200;
- if(fishermanNumber <= 6)
- discount += 10;
- if(fishermanNumber >= 7 && fishermanNumber <= 11)
- discount += 15;
- if(fishermanNumber >= 12)
- discount += 25;
- s = 100-discount;
- totalP = (s*seasonPrice)/100;
- if(fishermanNumber % 2 == 0) {
- discount = 5;
- s = 100-discount;
- totalP = (s*totalP)/100;
- }
- if(groupBudget < totalP) {
- moneyLeft = totalP - groupBudget;
- System.out.printf("Not enough money! You need %.2f dollars.", moneyLeft);
- } else {
- moneyLeft = groupBudget - totalP;
- System.out.printf("Yes! You have %.2f dollars left.", moneyLeft);
- }
- break;
- case "Autumn":
- seasonPrice = 4200;
- if(fishermanNumber <= 6)
- discount += 10;
- if(fishermanNumber >= 7 && fishermanNumber <= 11)
- discount += 15;
- if(fishermanNumber >= 12)
- discount += 25;
- s = 100-discount;
- totalP = (s*seasonPrice)/100;
- if(groupBudget < totalP) {
- moneyLeft = totalP - groupBudget;
- System.out.printf("Not enough money! You need %.2f dollars.", moneyLeft);
- } else {
- moneyLeft = groupBudget - totalP;
- System.out.printf("Yes! You have %.2f dollars left.", moneyLeft);
- }
- break;
- case "Winter":
- seasonPrice = 2600;
- if(fishermanNumber <= 6)
- discount += 10;
- if(fishermanNumber >= 7 && fishermanNumber <= 11)
- discount += 15;
- if(fishermanNumber >= 12)
- discount += 25;
- s = 100-discount;
- totalP = (s*seasonPrice)/100;
- if(fishermanNumber % 2 == 0) {
- discount = 5;
- s = 100-discount;
- totalP = (s*totalP)/100;
- }
- if(groupBudget < totalP) {
- moneyLeft = totalP - groupBudget;
- System.out.printf("Not enough money! You need %.2f dollars.", moneyLeft);
- } else {
- moneyLeft = groupBudget - totalP;
- System.out.printf("Yes! You have %.2f dollars left.", moneyLeft);
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement