Advertisement
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 price;
- double spend = 0;
- String game = "";
- // String game = scanner.nextLine();
- while (!"Game time".equalsIgnoreCase(game = scanner.nextLine())) {
- price = 0;
- if (currentBalance == 0) {
- System.out.println("Out of money!");
- break;
- }
- if (game.equals("OutFall 4")) {
- price = 39.99;
- } else if (game.equals("CS: OG")) {
- price = 15.99;
- } else if (game.equals("Zplinter Zell")) {
- price = 19.99;
- } else if (game.equals("Honored 2")) {
- price = 59.99;
- } else if (game.equals("RoverWatch")) {
- price = 29.99;
- } else if (game.equals("RoverWatch Origins Edition")) {
- price = 39.99;
- } else {
- System.out.println("Not Found");
- }
- if (currentBalance >= price && price > 0) {
- spend += price;
- currentBalance -= price;
- System.out.printf("Bought %s%n", game);
- } else if (price > currentBalance && price > 0) {
- System.out.println("Too Expensive");
- }
- }
- if (currentBalance > 0) {
- System.out.printf("Total spent: $%.2f. Remaining: $%.2f", spend, currentBalance);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement