Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 gamePrice = 0;
- double currentSum = 0;
- while (true) {
- String gameName = scanner.nextLine();
- if (gameName.equalsIgnoreCase("Game Time")) {
- if (currentBalance == 0) {
- System.out.println("Out of money!");
- break;
- } else {
- System.out.printf("Total spent: $%.2f. Remaining: $%.2f",
- currentSum, currentBalance);
- break;
- }
- }
- switch (gameName) {
- case "OutFall 4":
- gamePrice = 39.99;
- if (currentBalance >= gamePrice) {
- System.out.printf("Bought %s%n", gameName);
- currentBalance -= gamePrice;
- currentSum += gamePrice;
- } else {
- System.out.println("Too Expensive");
- }
- break;
- case "CS: OG":
- gamePrice = 15.99;
- if (currentBalance >= gamePrice) {
- System.out.printf("Bought %s%n", gameName);
- currentBalance -= gamePrice;
- currentSum += gamePrice;
- } else {
- System.out.println("Too Expensive");
- }
- break;
- case "Zplinter Zell":
- gamePrice = 19.99;
- if (currentBalance >= gamePrice) {
- System.out.printf("Bought %s%n", gameName);
- currentBalance -= gamePrice;
- currentSum += gamePrice;
- } else {
- System.out.println("Too Expensive");
- }
- break;
- case "Honored 2":
- gamePrice = 59.99;
- if (currentBalance >= gamePrice) {
- System.out.printf("Bought %s%n", gameName);
- currentBalance -= gamePrice;
- currentSum += gamePrice;
- } else {
- System.out.println("Too Expensive");
- }
- break;
- case "RoverWatch":
- gamePrice = 29.99;
- if (currentBalance >= gamePrice) {
- System.out.printf("Bought %s%n", gameName);
- currentBalance -= gamePrice;
- currentSum += gamePrice;
- } else {
- System.out.println("Too Expensive");
- }
- break;
- case "RoverWatch Origins Edition":
- gamePrice = 39.99;
- if (currentBalance >= gamePrice) {
- System.out.printf("Bought %s%n", gameName);
- currentBalance -= gamePrice;
- currentSum += gamePrice;
- } else {
- System.out.println("Too Expensive");
- }
- break;
- default:
- System.out.println("Not Found");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment