ShadowZek

Untitled

Jan 31st, 2019
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class ShowcaseGame {
  3.  
  4. public static final int theGoodRange = 2000;
  5. public static void main(String[] args) {
  6. Scanner keyboard = new Scanner(System.in);
  7. //Instance of Showcase to be passed to the class.
  8. Showcase gameShow = new Showcase();
  9. //Loop for playing the game.
  10. while (true)
  11. {
  12. //Printing the prizes to the user.
  13. System.out.println("Welcome to the Showcase Game."
  14. + "\nHere are the 5 prizes that you could win:");
  15. Prize[] showPrizes = gameShow.choosePrizes();
  16. double prizeCost = 0.0;
  17. for (int i = 0; i < showPrizes.length; i++)
  18. {
  19. System.out.println(showPrizes[i].getName());
  20. prizeCost += showPrizes[i].getPrice();
  21. }
  22. //Collecting user guess, and whether they win or not.
  23. System.out.println("Please enter a guess as to how much these items cost.");
  24. int guess = keyboard.nextInt();
  25. double calc = Math.abs(prizeCost - guess);
  26. if (calc <= theGoodRange)
  27. {
  28. System.out.println("Your guess: " + guess + ", the actual retail price: " + prizeCost
  29. + "\nYour guess was within an acceptable range. You win the Showcase!");
  30. }
  31. else
  32. {
  33. System.out.println("Your guess: " + guess + ", the actual retail price: " + prizeCost
  34. + "\nYour guess was either under an acceptable range or over the retail price. You lose the Showcase.");
  35. }
  36. //Statement for continuing the game or not.
  37. System.out.println("Would you like to play again? Enter no to quit.");
  38. String response = keyboard.nextLine();
  39. if (response.equalsIgnoreCase("no"))
  40. {
  41. System.out.println("Goodbye.");
  42. keyboard.close();
  43. break;
  44. }
  45. }
  46. }
  47. }
Add Comment
Please, Sign In to add comment