Concept explainers
Will the
for (int i = 0 ; i < 4 ; i ++) {
int cardNumber = (int)(Math.random() • deck. length) ;
String suit = suits[cardNumber / 13];
String rank = ranks[cardNumber % 13];
System.out.println( "Card number " + cardNumber + "· " + rank + " of " + suit);
}
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Modern Database Management
Concepts Of Programming Languages
Mechanics of Materials (10th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
- Java Program Chapter 5. PC #17. Rock, Paper, Scissors Game (page 317) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. Add the following two lines to the beginning of your main method. This will allow your computer choices match with the test cases here in HyperGrade. long seed = Long.parseLong(args[0]); Random random = new Random(seed); 2. When the program begins, a random number in the range of 0 through 2 is generated. If the number is 0, then the computer has chosen rock. If the number is 1, then the computer has chosen paper. If the number is 2, then the computer has chosen scissors. (Do not display the computer choice yet.) 3. The user enters his or her choice of "rock", "paper", or "scissors" at the keyboard. You should use 1 for rock, 2 for paper, and 3 for scissors. Internally, you can store 0, 1, and 2 as the user choice, to match with the above schema. 4. Both user and…arrow_forwardJAVA PROGRAM Chapter 5. PC #17. Rock, Paper, Scissors Game (page 317) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. Add the following two lines to the beginning of your main method. This will allow your computer choices match with the test cases here in HyperGrade. long seed = Long.parseLong(args[0]); Random random = new Random(seed); 2. When the program begins, a random number in the range of 0 through 2 is generated. If the number is 0, then the computer has chosen rock. If the number is 1, then the computer has chosen paper. If the number is 2, then the computer has chosen scissors. (Do not display the computer choice yet.) 3. The user enters his or her choice of "rock", "paper", or "scissors" at the keyboard. You should use 1 for rock, 2 for paper, and 3 for scissors. Internally, you can store 0, 1, and 2 as the user choice, to match with the above schema. 4. Both user and…arrow_forwardvoid getInput(){for(int i =0; i < studentName.length; i++){System.out.print("Student name: ");studentName[i] = keyboard.nextLine();System.out.print("Studnet ID: ");midTerm1[i] = keyboard.nextInt();}keyboard.close();} Can't put full student name becuase nextLine();arrow_forward
- Write this program in Java using a custom method. Implementation details You will implement this program in a specific way in order to gain some experience with loops, arrays and array lists. Use an array of strings to store the 4 strings listed in the description. Use a do-while loop for your 'game engine'. This means the game starts once the user enters money. The decision to stop occurs at the bottom of the loop. The do-while loop keeps going until the user quits, or there is no money left. The pseudocode for this 'game engine' is shown below: determine the fruits to display (step 3 below) and print them determine if there are 3 or 4 of the same image display the results update the customer balance as necessary prompt to play or quit continue loop if customer wants to play and there's money for another game. Use the Random class to generate a random number between 0 and 3. This random number will be an index into the array of strings. Add the string at that index to an…arrow_forwardFor the code in java below it shows a deck of 52 cards and asks the name of the two human players and makes both players draw five cards from the deck. What I want to added into the code is for Player A to manually pick a card from his/her 5 cards and have Player B pick two cards that equal the value of Player A's card if possible. Main class code and Player class code shown below: Main class code: import java.util.ArrayList; import java.util.Scanner; import java.util.List; import java.util.Random; class Main { publicstaticvoid main(String[] args) { // card game, two players, take turns. String[] suits = {"Hearts", "Clubs", "Spades", "Diamonds"}; String[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}; for(String oneSuit : suits){ for(String num : numbers){ System.out.println(oneSuit + " " + num); } } List<Player> listOfPlayers = new ArrayList<>(); Scanner sc = new Scanner(System.in); System.out.println("Name of Player 1");…arrow_forwardFor the code in java below it shows a deck of 52 cards and asks the name of the two human players and makes both players draw five cards from the deck. For the code make PlayerA chose one of the 5 cards but the player who is playing as PlayerA can select which card it is and the card is not selected randomly. Main class code: import java.util.ArrayList; import java.util.Scanner; import java.util.List; import java.util.Random; class Main { publicstaticvoid main(String[] args) { // card game, two players, take turns. String[] suits = {"Hearts", "Clubs", "Spades", "Diamonds"}; String[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}; for(String oneSuit : suits){ for(String num : numbers){ System.out.println(oneSuit + " " + num); } } List<Player> listOfPlayers = new ArrayList<>(); Scanner sc = new Scanner(System.in); System.out.println("Name of Player 1"); String PlayerName = sc.nextLine(); Player newPlayer = new Player(PlayerName);…arrow_forward
- In Javaarrow_forwardint nums[] = {7,2,5,6,7,2,3,4,6}; int location = -1; int iterations = 0; for (int i=0; iarrow_forwardWhat is returned from fun (5, 12) and fun (12, 5) as coded below? int fun (int n, int m) { } if (n == m) { return 0; } else if (n> m) { return 1; } else { } return fun (m, n);arrow_forwardConsider the following code to answer below questions: public double calculatePerimeter(Shapes [] shapes) { double p = 0; for (Shape shape : shapes) { if (shape is Rectangle) { Rectangle rectangle = (Rectangle) shape; %3D p += (rectangle.Width+rectangle.Height) * 2; } else { Circle circle = (Circle)shape; p += 2 * circle.Radius * Math.PI; } return p; } 1. which design principle is violated in the above code? 2. what is the issue/ limitation of this code? 3. rewrite the code to not violate the design principle you answered in part 1?arrow_forwardHow do you do this? JAVAarrow_forwardfloat someDataValues [] = new float[30]; for (int i = 1; i < someDataValues.length - 5; i+=4) { someDataValues[i] = (float) Math.pow((i+2), 2); System.out.println((int) someDataValues[i] + " "); i++; }arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT