Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3.  
  4. public class GameStore3 {
  5. public static void main(String[] args) {
  6.  
  7. Scanner input = new Scanner(System.in);
  8. int ids[] = new int[100];
  9. double sum = 0;
  10. int nm = 0;
  11. int index = 0;
  12. while (true) {
  13. System.out.print("**********************************************************************"
  14. + "\n* Welcome to Gaming Center :) *"
  15. + "\n* -------------------------- *"
  16. + "\n* Please enter one of the following options: *"
  17. + "\n* 1) add ==> this allows you to add a game to inventory *"
  18. + "\n* 2) sell ==> this allows you to sell games to a customer *"
  19. + "\n* 3) exit ==> to end this program *"
  20. + "\n* *"
  21. + "\n**********************************************************************\n");
  22. System.out.print("Enter your option :> ");
  23. String choice = input.nextLine();
  24. if (choice.equals("add")) {
  25. while (true) {
  26. System.out.print("Please, enter game id (-1 to end): ");
  27. int id = input.nextInt();
  28. if (id == -1) {
  29. break;
  30. } else {
  31. ids[(index++)] = id;
  32. }
  33. }
  34. } else if (choice.equals("sell")) {
  35. if (index <= 0) {
  36. System.out.print("Sorry. There are no more games in store :(\n");
  37. }
  38.  
  39. else {
  40. while (true) {
  41. System.out.print("Please, enter the game id (-1 to end): ");
  42. int id = input.nextInt();
  43. if (id == -1) {
  44. break;
  45. } else {
  46. boolean exists = false;
  47. for (int i = 0; i < ids.length; i++) {
  48. if (ids[i] == id)
  49. exists = true;
  50. ids[i] = 0;
  51. }
  52. if (exists) {
  53. System.out.print("Please, enter the price of next game: \n");
  54. sum += input.nextDouble();
  55. nm += 1;
  56. } else {
  57. System.out.print("Sorry the id you inserted doesnt exist\n");
  58. }
  59. }
  60. }
  61. System.out.print("Total price before discount: " + sum + "SR" + "\nYour discount is: "
  62. + ((nm <= 2) ? "0.0SR" : sum * 0.2 + "SR") + "\nTotal price after discount: "
  63. + ((nm <= 2) ? sum : sum * 0.8 + "SR\n"));
  64.  
  65.  
  66. }
  67. } else if (choice.equals("exit")) {
  68. System.out.print("Thanks. Goodbye!");
  69. break;
  70. } else {
  71. System.out.print(choice == "add");
  72. }
  73.  
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement