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