Advertisement
desislava_topuzakova

Untitled

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