-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowcaseGame.java
54 lines (51 loc) · 1.5 KB
/
ShowcaseGame.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Written by Noah Shaw
*/
import java.util.Scanner;
public class ShowcaseGame {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Create a showcase
boolean gameOver = false;
//Game loop
while(gameOver != true)
{
//Greeting
System.out.println("Welcome to the showcase showdown!"
+ "\nYour prizes are: ");
//Construct the showcase and print it
Showcase showcase = new Showcase();
//Get the player's guess
System.out.println("You must guess the total cost of all items without going over!"
+ "\nPlease enter your guess:");
Scanner keyboard = new Scanner(System.in);
double guess = keyboard.nextDouble();
System.out.println("Your guess was " + guess + " and the actual price was " + showcase.addShowcase());
//Check the guess
if(guess <= showcase.addShowcase())
{
if(guess >= showcase.addShowcase() - 2000)
{
System.out.println("Your guess was under! You win!");
}
else
{
System.out.println("That guess was WAY off! You lose!");
}
}
else if(guess > showcase.addShowcase())
{
System.out.println("That guess was over! You lose!");
}
//Ask if the player wants to play again
System.out.println("Would you like to play again? Enter 'no' to quit.");
keyboard.nextLine();
//Play again or end game
if(keyboard.nextLine().equalsIgnoreCase("no"))
{
gameOver = true;
System.out.println("Thanks for playing!");
}
}
}
}