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