Write a FULL  Java procedural program for one human player to play a “Higher or Lower” card game. In this game, each card has a value from 1..10 inclusive. There are 4 of each value in the deck, i.e., 40 cards in total. Cards are not replaced in the deck once drawn, i.e., no more than 4 of each value will be drawn. The program starts by asking the player for a target score. The game proceeds in a series of rounds with the program repeatedly drawing and showing a card from the deck to the player one at a time. Each time, it asks the player to enter "h" (higher) or "l" (lower) to guess whether the next card drawn will be higher or lower in value. The player gains a point if they guess correctly. The game continues until the player guesses incorrectly or the target score is reached. When the game ends, it prints either a "You win!" or a "Nice try, you scored …” message as illustrated below. The image provided shows  two examples of the required program behaviour: (bold is keyboard input by the player):  Hint: you could start by considering how to design your program while first ignoring the details of the deck (e.g., not worrying about drawing more than 4 of one value). Then extend your basic idea to include those details in some way. One option is to design an abstract data type to track the cards drawn so far during the game. However, you may employ any logical approach you wish. Your program - should use a for-loop, a while-loop, and an array (at least one of each). - must be a procedural program. (Not an object-oriented program.) - must not use global variables. All variables should be defined locally in a method.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Write a FULL  Java procedural program for one human player to play a “Higher or Lower” card game. In this game, each card has a value from 1..10 inclusive. There are 4 of each value in the deck, i.e., 40 cards in total. Cards are not replaced in the deck once drawn, i.e., no more than 4 of each value will be drawn. The program starts by asking the player for a target score. The game proceeds in a series of rounds with the program repeatedly drawing and showing a card from the deck to the player one at a time. Each time, it asks the player to enter "h" (higher) or "l" (lower) to guess whether the next card drawn will be higher or lower in value. The player gains a point if they guess correctly. The game continues until the player guesses incorrectly or the target score is reached. When the game ends, it prints either a "You win!" or a "Nice try, you scored …” message as illustrated below. The image provided shows  two examples of the required program behaviour: (bold is keyboard input by the player): 

Hint: you could start by considering how to design your program while first ignoring the details of the deck (e.g., not worrying about drawing more than 4 of one value). Then extend your basic idea to include those details in some way. One option is to design an abstract data type to track the cards drawn so far during the game. However, you may employ any logical approach you wish. Your program - should use a for-loop, a while-loop, and an array (at least one of each). - must be a procedural program. (Not an object-oriented program.) - must not use global variables. All variables should be defined locally in a method.

 

You may use the following method if you wish.
/* Return a random int between 0 (inclusive) and bound (exclusive) */
public static int randomInt(int bound) {
Random r
= new Random();
return r.nextInt(bound);
}
Transcribed Image Text:You may use the following method if you wish. /* Return a random int between 0 (inclusive) and bound (exclusive) */ public static int randomInt(int bound) { Random r = new Random(); return r.nextInt(bound); }
Target score? 10
I drew a 5
Round 1: Higher or lower? (h/1) 1
I drew a 4
Round 2: Higher or lower? (h/1) h
I drew a 2
Nice try, you scored 1.
Target score? 40
I drew a 10
Round 1: Higher or lower? (h/1) 1
I drew a 5
Round 2: Higher or lower? (h/1) h
[lines omitted here for space reasons]
I drew a 2
...
Round 40: Higher or lower? (h/1) h
I drew a 10
You win!
Transcribed Image Text:Target score? 10 I drew a 5 Round 1: Higher or lower? (h/1) 1 I drew a 4 Round 2: Higher or lower? (h/1) h I drew a 2 Nice try, you scored 1. Target score? 40 I drew a 10 Round 1: Higher or lower? (h/1) 1 I drew a 5 Round 2: Higher or lower? (h/1) h [lines omitted here for space reasons] I drew a 2 ... Round 40: Higher or lower? (h/1) h I drew a 10 You win!
Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY