Advertisement
SvetlanPetrova

GamingStore SoftUni

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