Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ShowcaseGame {
- public static final int theGoodRange = 2000;
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- //Instance of Showcase to be passed to the class.
- Showcase gameShow = new Showcase();
- //Loop for playing the game.
- while (true)
- {
- //Printing the prizes to the user.
- System.out.println("Welcome to the Showcase Game."
- + "\nHere are the 5 prizes that you could win:");
- Prize[] showPrizes = gameShow.choosePrizes();
- double prizeCost = 0.0;
- for (int i = 0; i < showPrizes.length; i++)
- {
- System.out.println(showPrizes[i].getName());
- prizeCost += showPrizes[i].getPrice();
- }
- //Collecting user guess, and whether they win or not.
- System.out.println("Please enter a guess as to how much these items cost.");
- int guess = keyboard.nextInt();
- double calc = Math.abs(prizeCost - guess);
- if (calc <= theGoodRange)
- {
- System.out.println("Your guess: " + guess + ", the actual retail price: " + prizeCost
- + "\nYour guess was within an acceptable range. You win the Showcase!");
- }
- else
- {
- System.out.println("Your guess: " + guess + ", the actual retail price: " + prizeCost
- + "\nYour guess was either under an acceptable range or over the retail price. You lose the Showcase.");
- }
- //Statement for continuing the game or not.
- System.out.println("Would you like to play again? Enter no to quit.");
- String response = keyboard.nextLine();
- if (response.equalsIgnoreCase("no"))
- {
- System.out.println("Goodbye.");
- keyboard.close();
- break;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment