Advertisement
Guest User

Untitled

a guest
Apr 25th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GameStore {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double money = Double.parseDouble(scanner.nextLine());
  8.         String input = scanner.nextLine();
  9.         double price;
  10.         boolean isBroke = false;
  11.         double totalSpent = 0;
  12.  
  13.         while (!"Game Time".equals(input)){
  14.             switch (input) {
  15.                 case "OutFall 4":
  16.                     price = 39.99;
  17.                     break;
  18.                 case "CS: GO":
  19.                     price = 15.99;
  20.                     break;
  21.                 case "Zplinter Zell":
  22.                     price = 19.99;
  23.                     break;
  24.                 case "Honored 2":
  25.                     price = 59.99;
  26.                     break;
  27.                 case "RoverWatch":
  28.                     price = 29.99;
  29.                     break;
  30.                 case "RoverWatch Origins Edition":
  31.                     price = 39.99;
  32.                     break;
  33.                 default:
  34.                     System.out.println("Not Found");
  35.                     input = scanner.nextLine();
  36.                     continue;
  37.             }
  38.             if (money < price){
  39.                 System.out.println("Too Expensive");
  40.  
  41.             }else {
  42.                 System.out.printf("Bought %s%n", input);
  43.                 totalSpent += price;
  44.                 money -= price;
  45.             }
  46.  
  47.             if (money == 0){
  48.                 System.out.println("Out of money!");
  49.                 isBroke = true;
  50.                 break;
  51.             }
  52.             input = scanner.nextLine();
  53.         }
  54.         if (!isBroke){
  55.             System.out.printf("Total spent: $%.2f. Remaining: $%.2f", totalSpent, money);
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement