Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package src;
- import java.util.Scanner;
- public class GamingStore {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double currentBalance = Double.parseDouble(scanner.nextLine());
- double remaining = 0;
- while (true) {
- String game = scanner.nextLine();
- if (game.equals("Game Time")) {
- break;
- }
- double price = 0;
- switch (game) {
- case "OutFall 4":
- case "RoverWatch Origins Edition":
- price = 39.99;
- break;
- case "CS: OG":
- price = 15.99;
- break;
- case "Zplinter Zell":
- price = 19.99;
- break;
- case "Honored 2":
- price = 59.99;
- break;
- case "RoverWatch":
- price = 29.99;
- break;
- default:
- System.out.println("Not Found");
- continue;
- }
- if (price > currentBalance) {
- System.out.println("Too Expensive");
- continue;
- }
- currentBalance -= price;
- remaining += price;
- System.out.printf("Bought %s%n", game);
- if (currentBalance == 0) {
- System.out.println("Out of money!");
- return;
- }
- }
- System.out.printf("Total spent: $%.2f. Remaining: $%.2f", remaining, currentBalance);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment