Advertisement
meteor4o

#Java-Fund 03. Gaming Store

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