Advertisement
Guest User

Untitled

a guest
May 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. package BasicsSyntax;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Gaming_Store {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. double balance = Double.parseDouble(scanner.nextLine());
  10.  
  11. double price = 0;
  12. String input = scanner.nextLine();
  13. boolean isFound = true;
  14. double totalSpent = 0;
  15.  
  16. while (!input.equals("Game Time")) {
  17.  
  18. switch (input) {
  19. case "OutFall 4":
  20. isFound = true;
  21. price = 39.99;
  22. break;
  23. case "CS: OG":
  24. isFound=true;
  25. price = 15.99;
  26. break;
  27. case "Zplinter Zell":
  28. isFound = true;
  29. price = 19.99;
  30. break;
  31. case "Honored 2":
  32. isFound=true;
  33. price = 59.99;
  34. break;
  35. case "RoverWatch":
  36.  
  37. price = 29.99;
  38. break;
  39. case "RoverWatch Origins Edition":
  40. isFound=true;
  41. price = 39.99;
  42. break;
  43. default:
  44. isFound = false;
  45. System.out.println("Not Found");
  46. System.out.println();
  47. break;
  48. }
  49.  
  50. if (isFound) {
  51. System.out.printf("Bought %s%n", input);
  52.  
  53. }
  54. if (balance <= 0){
  55. System.out.print("Out of money!");
  56.  
  57. } else if (balance < price) {
  58. System.out.println("Too Expensive");
  59. }
  60.  
  61. totalSpent += price;
  62. balance -= price;
  63. input = scanner.nextLine();
  64. }
  65. if (balance > 0) {
  66. System.out.printf("Total spent: $%.2f. ", totalSpent);
  67. System.out.printf("Remaining: $%.2f", balance);
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement