
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Write a Java
I used replit. Do I need correction on my code??
"The sample runs of such a program and my code are on the attached image."
![import java.util.Scanner;
class Lab4 {
public static void main(String[] args) {
Scanner keyb = new Scanner(System.in);
Deck myDeck = new Deck();
myDeck.shuffle();
Hand myHand = new Hand();
System.out.println("Starting with an empty hand\n");
boolean gamePlaying = true;
while (gamePlaying) {
System.out.println("Do you wish to hit or stand (h/s)? ");
String response = keyb.nextLine().trim();
if (response.equals IgnoreCase("s")) {
gamePlaying = false;
}
else {
Card card =
System.out.println("Your
card: " + card);
myHand.add(card);
System.out.println("Hand after drawing card: ");
System.out.println(myHand);
int value myHand.getHandValue();
myDeck.nextCard();
}
=
System.out.println("Hand value: " + value);
if (value> 22) {
System.out.println("Sorry you busted");
} // end of main()
}
} // end while (gamePlaying)](https://content.bartleby.com/qna-images/question/8f295989-0e6d-45c2-9ab7-cdca523774a7/7461f8dd-fade-4bba-9e4b-feda59a9aa8f/nf3ol4_thumbnail.png)
Transcribed Image Text:import java.util.Scanner;
class Lab4 {
public static void main(String[] args) {
Scanner keyb = new Scanner(System.in);
Deck myDeck = new Deck();
myDeck.shuffle();
Hand myHand = new Hand();
System.out.println("Starting with an empty hand\n");
boolean gamePlaying = true;
while (gamePlaying) {
System.out.println("Do you wish to hit or stand (h/s)? ");
String response = keyb.nextLine().trim();
if (response.equals IgnoreCase("s")) {
gamePlaying = false;
}
else {
Card card =
System.out.println("Your
card: " + card);
myHand.add(card);
System.out.println("Hand after drawing card: ");
System.out.println(myHand);
int value myHand.getHandValue();
myDeck.nextCard();
}
=
System.out.println("Hand value: " + value);
if (value> 22) {
System.out.println("Sorry you busted");
} // end of main()
}
} // end while (gamePlaying)
![import java.util.Scanner;
class Lab4 {
public static void main(String[] args) {
Scanner keyb = new Scanner(System.in);
Deck myDeck = new Deck();
myDeck.shuffle();
Hand myHand = new Hand();
System.out.println("Starting with an empty hand\n");
boolean gamePlaying = true;
while (gamePlaying) {
System.out.println("Do you wish to hit or stand (h/s)? ");
String response = keyb.nextLine().trim();
if (response.equals IgnoreCase("s")) {
gamePlaying
}
else {
=
false;
Card card = myDeck.nextCard();
System.out.println("Your card: " + card);
myHand.add(card);
System.out.println("Hand after drawing card: ");
System.out.println(myHand);
}
int value = myHand.getHandValue();
System.out.println("Hand value: " + value);
if (value> 22) {
System.out.println("Sorry you busted");
}
} // end while (gamePlaying)
// end of main()](https://content.bartleby.com/qna-images/question/8f295989-0e6d-45c2-9ab7-cdca523774a7/7461f8dd-fade-4bba-9e4b-feda59a9aa8f/6hhhsxd_thumbnail.png)
Transcribed Image Text:import java.util.Scanner;
class Lab4 {
public static void main(String[] args) {
Scanner keyb = new Scanner(System.in);
Deck myDeck = new Deck();
myDeck.shuffle();
Hand myHand = new Hand();
System.out.println("Starting with an empty hand\n");
boolean gamePlaying = true;
while (gamePlaying) {
System.out.println("Do you wish to hit or stand (h/s)? ");
String response = keyb.nextLine().trim();
if (response.equals IgnoreCase("s")) {
gamePlaying
}
else {
=
false;
Card card = myDeck.nextCard();
System.out.println("Your card: " + card);
myHand.add(card);
System.out.println("Hand after drawing card: ");
System.out.println(myHand);
}
int value = myHand.getHandValue();
System.out.println("Hand value: " + value);
if (value> 22) {
System.out.println("Sorry you busted");
}
} // end while (gamePlaying)
// end of main()
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

Knowledge Booster
Similar questions
- in java Integer valueIn is read from input. Write a while loop that iterates until valueIn is negative. In each iteration: Update integer result as follows: If valueIn is divisible by 5, output "win" and increment result. Otherwise, output "lose" and do not update result. Then, read an integer from input into variable valueIn. End each output with a newline. Click here for exampleEx: If the input is 5 15 11 -5, then the output is: win win lose Result is 2 Note: x % 5 == 0 returns true if x is divisible by 5. import java.util.Scanner; public class ResultCalculator { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int valueIn; int result; result = 0; valueIn = scnr.nextInt(); /your code here/ System.out.println("Result is " + result); }}arrow_forwardin java Strings itemToFind and inputItem are read from input. Integer wordCount is initialized with 1. Write a while loop that iterates until inputItem is equal to "Done". In each iteration of the loop: Increment wordCount if inputItem is equal to itemToFind. Read string inputItem from input. Click here for example Note: Assume that input has at least two strings. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import java.util.Scanner; public class SimpleWhileLoop { publicstaticvoidmain(String[] args) { Scannerscnr=newScanner(System.in); StringitemToFind; StringinputItem; intwordCount; itemToFind=scnr.next(); inputItem=scnr.next(); wordCount=1; /* Your code goes here */ System.out.println(itemToFind+" occurs "+wordCount+" time(s)."); } }arrow_forwardI need help with creating a Java program that puts the given out put with the code: int diceFaceNumber = (int)((Math.random() * 6) + 1).arrow_forward
- Use JAVA to create a card game with in which the dealer shuffles the deck and deals 13 cards out of the 52 to the player. If the player sorts her hand and it includes a king of heart, then in response, the dealer should write on the console, "You won!" if not then then "You loose again." Make sure the cards are randomized to get different outputs. Also, create a unit test for the win and loose cases.arrow_forwardin java Jump to level 1 The first and second integers in the input are read into variables previousNum and currentNum, respectively. Write a loop that iterates until currentNum is not equal to 6 plus previousNum. In each iteration: Output currentNum, followed by " is 6 plus ", previousNum, and ". Sequence is increasing arithmetically." End with a newline. Assign previousNum with currentNum. Read the next integer from input and assign currentNum with the integer read. After the loop, output the last integer read followed by " breaks the sequence." and a newline. Click here for example Note: Assume that input has at least two integers. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import java.util.Scanner; public class Sequencing { publicstaticvoidmain(String[] args) { Scannerscnr=newScanner(System.in); intcurrentNum; intpreviousNum; previousNum=scnr.nextInt(); currentNum=scnr.nextInt(); System.out.println("Sequence starts at "+previousNum+"."); /* Your code…arrow_forwardYou've decided to test the wifi speed in the classroom at the beginning of every lecture. Create a program that will tell you if the wifi speed over the past 3 classes has increased, decreased, or neither. If the wifi speeds are sorted and increasing, then print out "The wifi is getting faster!". If the wifi speeds are sorted and decreasing, then print out "The wifi is getting slower!". If the wifi speeds are unsorted or if two or more speeds are the same, then print "The wifi speed is changing unpredictably." The user should input 3 non-negative numbers (double) separated by spaces. Sample runs: Enter wifi speeds over the last 3 classes: 162 180 225 The wifi is getting faster! Enter wifi speeds over the last 3 classes: 37.5 21.2 19.9 The wifi is getting slower! Enter wifi speeds over the last 3 classes: 162 135.3 225 The wifi speed is changing unpredictably. Ensure you are doing basic input validation, output Please enter a valid input. if the user inputs a negative wifi speed. Make…arrow_forward
- in java String inputWord is read from input. Write a while loop that iterates until inputWord is equal to "Finale". In each iteration of the loop: Read integer clothingNumber from input. If clothingNumber is less than 30, output the value of inputWord, followed by ": low on stock" and a newline. Otherwise, output the value of inputWord, followed by ": well stocked" and a newline. Read string inputWord from input. Click here for example 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import java.util.Scanner; public class PairedDataProcessing { publicstaticvoidmain(String[] args) { Scannerscnr=newScanner(System.in); StringinputWord; intclothingNumber; inputWord=scnr.next(); /* Your code goes here */ } }arrow_forwardIn Java Integer in is read from input. Write a while loop that iterates until in is less than or equal to 0. In each iteration: Update in with the quotient of in and 7. Output the updated in, followed by a newline. Click here for exampleEx: If the input is 2401, then the output is: 343 49 7 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import java.util.Scanner; public class QuotientCalculator { publicstaticvoidmain(String[] args) { Scannerscnr=newScanner(System.in); intin; in=scnr.nextInt(); /your code here/ } }arrow_forwardThe language is Java. The chapter it is in is on Looping.arrow_forward
- Write a java program that will create a Deck object and shuffle the deck. Then, you will draw ten cards from the deck and perform selection statements that carry out the following: If the card is red, then print “Card is red” to the screen. Otherwise, print “Card is black” to the screen. If the card is a picture card, print “That's a picture card”. If the card is an ace, print “That's an Ace”. If the card has a value less than 6, print “Card has a small value”. If the card has a value between 6 and 10 (inclusive), print “Card has a large value”. In the source code, write an algorithm for the program in a comment block. Also, in a comment block, paste the results of running your program. Print out and turn in the completed source code with those comments.arrow_forwardIn Java, design a class that models a 6-sided die. The die will be used in a game. Simulate a roll of the die, return a random value from {1,2,3,4,5,6}.arrow_forwardHow to write a program in java that ask the user for an input word(use the String method toUpperCase to convert the word to all upper-case characters), then have the program keep looping, generating random strings until the random string matches the user word and keep track of how many loops were required to match. Each time through the loop, your program should output the user’s word, the random string, and the difference score. The difference score is the sum of the absolute value of the difference between each character in the random string and the user’s input string. For example, if the random string was “ABC” and the target string was “AAA”, then the difference score is 3 (abs(A-A) + abs(A-B) + abs(A-C) = 0 + 1 + 2 = 3). You can get at the characters of a string, using the String charAt and absolute value is the abs method of the java.lang.Math class. To generate random strings, in a loop, generate random characters to build up a random string the same length as the user word. To…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

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 Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

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
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY