Advertisement
desislava_topuzakova

Untitled

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