Guest User

GamingStore

a guest
Oct 1st, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. package Tech_03;
  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 currentBalance = Double.parseDouble(scanner.nextLine());
  9. double sum = 0;
  10. double price = 0;
  11.  
  12. while(true){
  13. String game = scanner.nextLine();
  14. if(game.equals("Game Time")){
  15. break;
  16. }
  17. switch (game) {
  18. case "OutFall 4":
  19. price += 39.99;
  20. sum = currentBalance - price;
  21. if (currentBalance < price) {
  22. System.out.println("Too expensive");
  23. } else {
  24. System.out.println(String.format("Bought %s", game));
  25. }
  26. break;
  27. case "CS: OG":
  28. price += 15.99;
  29. sum = currentBalance - price;
  30. if (currentBalance < price) {
  31. System.out.println("Too expensive");
  32. } else {
  33. System.out.println(String.format("Bought %s", game));
  34. }
  35. break;
  36. case "Zplinter Zell":
  37. price += 19.99;
  38. sum = currentBalance - price;
  39. if (currentBalance < price) {
  40. System.out.println("Too expensive");
  41. } else {
  42. System.out.println(String.format("Bought %s", game));
  43. }
  44. break;
  45. case "Honored 2":
  46. price += 59.99;
  47. sum = currentBalance - price;
  48. if (currentBalance < price) {
  49. System.out.println("Too expensive");
  50. } else {
  51. System.out.println(String.format("Bought %s", game));
  52. }
  53. break;
  54. case "RoverWatch":
  55. price += 29.99;
  56. sum = currentBalance - price;
  57. if (currentBalance < price) {
  58. System.out.println("Too expensive");
  59. } else {
  60. System.out.println(String.format("Bought %s", game));
  61. }
  62. break;
  63. case "RoverWatch Origins Edition":
  64. price += 39.99;
  65. sum = currentBalance - price;
  66. if (currentBalance < price) {
  67. System.out.println("Too expensive");
  68. } else {
  69. System.out.println(String.format("Bought %s", game));
  70. }
  71. break;
  72. default:
  73. System.out.println("Not found");
  74. }
  75.  
  76. if(sum <= 0){
  77. System.out.println("Out of money");
  78. }
  79.  
  80. }
  81.  
  82. if(sum != 0) {
  83. System.out.printf("Total spent: $%.2f. Remaining: $%.2f", price, currentBalance - price);
  84. }
  85. }
  86. }
Add Comment
Please, Sign In to add comment