Didart

Gaming Store

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