Helena12

GamingStore

Jan 23rd, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.60 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GamingStore {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double currentBalance = Double.parseDouble(scanner.nextLine());
  8.         double gamePrice = 0;
  9.         double currentSum = 0;
  10.  
  11.         while (true) {
  12.            String gameName = scanner.nextLine();
  13.  
  14.             if (gameName.equalsIgnoreCase("Game Time")) {
  15.                 if (currentBalance == 0) {
  16.                     System.out.println("Out of money!");
  17.                     break;
  18.                 } else {
  19.                     System.out.printf("Total spent: $%.2f. Remaining: $%.2f",
  20.                             currentSum, currentBalance);
  21.                     break;
  22.                 }
  23.             }
  24.             switch (gameName) {
  25.                 case "OutFall 4":
  26.                     gamePrice = 39.99;
  27.  
  28.                     if (currentBalance >= gamePrice) {
  29.  
  30.                         System.out.printf("Bought %s%n", gameName);
  31.                         currentBalance -= gamePrice;
  32.                         currentSum += gamePrice;
  33.                     } else {
  34.                         System.out.println("Too Expensive");
  35.                     }
  36.                     break;
  37.                 case "CS: OG":
  38.                     gamePrice = 15.99;
  39.  
  40.                     if (currentBalance >= gamePrice) {
  41.  
  42.                         System.out.printf("Bought %s%n", gameName);
  43.                         currentBalance -= gamePrice;
  44.                         currentSum += gamePrice;
  45.                     } else {
  46.                         System.out.println("Too Expensive");
  47.                     }
  48.                     break;
  49.                 case "Zplinter Zell":
  50.                     gamePrice = 19.99;
  51.  
  52.                     if (currentBalance >= gamePrice) {
  53.  
  54.                         System.out.printf("Bought %s%n", gameName);
  55.                         currentBalance -= gamePrice;
  56.                         currentSum += gamePrice;
  57.                     } else {
  58.                         System.out.println("Too Expensive");
  59.                     }
  60.                     break;
  61.                 case "Honored 2":
  62.                     gamePrice = 59.99;
  63.  
  64.                     if (currentBalance >= gamePrice) {
  65.  
  66.                         System.out.printf("Bought %s%n", gameName);
  67.                         currentBalance -= gamePrice;
  68.                         currentSum += gamePrice;
  69.                     } else {
  70.                         System.out.println("Too Expensive");
  71.                     }
  72.                     break;
  73.                 case "RoverWatch":
  74.                     gamePrice = 29.99;
  75.  
  76.                     if (currentBalance >= gamePrice) {
  77.  
  78.                         System.out.printf("Bought %s%n", gameName);
  79.                         currentBalance -= gamePrice;
  80.                         currentSum += gamePrice;
  81.                     } else {
  82.                         System.out.println("Too Expensive");
  83.                     }
  84.                     break;
  85.                 case "RoverWatch Origins Edition":
  86.                     gamePrice = 39.99;
  87.  
  88.                     if (currentBalance >= gamePrice) {
  89.  
  90.                         System.out.printf("Bought %s%n", gameName);
  91.                         currentBalance -= gamePrice;
  92.                         currentSum += gamePrice;
  93.                     } else {
  94.                         System.out.println("Too Expensive");
  95.                     }
  96.                     break;
  97.                 default:
  98.                     System.out.println("Not Found");
  99.                     break;
  100.             }
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment