Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- double money = Double.parseDouble(sc.nextLine());
- double spentMoney = 0.0;
- boolean isValid = true;
- String game = sc.nextLine();
- while(!game.equalsIgnoreCase("game time")) {
- double priceGame = 0.0;
- switch (game) {
- case "OutFall 4":
- priceGame = 39.99;
- isValid = true;
- break;
- case "CS: OG":
- priceGame = 15.99;
- isValid = true;
- break;
- case "Zplinter Zell":
- priceGame = 19.99;
- isValid = true;
- break;
- case "Honored 2":
- priceGame = 59.99;
- isValid = true;
- break;
- case "RoverWatch":
- priceGame = 29.99;
- isValid = true;
- break;
- case "RoverWatch Origins Edition":
- priceGame = 39.99;
- isValid = true;
- break;
- default:
- System.out.println("Not Found");
- isValid = false;
- break;
- }
- if (money >= priceGame && isValid) {
- spentMoney += priceGame;
- money -= priceGame;
- System.out.println("Bought " + game);
- } else if (priceGame > money) {
- System.out.println("Too Expensive");
- }
- if (money == 0) {
- System.out.println("Out of money!");
- return;
- }
- game = sc.nextLine();
- }
- if (game.equalsIgnoreCase("game time")) {
- System.out.printf("Total spent: $%.2f. Remaining: $%.2f", spentMoney, money);
- }
- // System.out.print(b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement