![Java Programming, Loose-leaf Version](https://www.bartleby.com/isbn_cover_images/9781337685917/9781337685917_largeCoverImage.gif)
a.
Explanation of Solution
Program:
File name: “Die.java”
//Define a class named Die
public class Die
{
//Declare the private variables and initialize the value
private int value;
private static final int HIGHEST_DIE_VALUE = 6;
private static final int LOWEST_DIE_VALUE = 1;
//Define a Die method
public Die()
{
//Calculate the value
value = ((int)(Math.random() * 100) % HIGHEST_DIE_VALUE +
LOWEST_DIE_VALUE);
}
//Define a getValue method
public int getValue()
{
//Return the value
return value;
}
}
File name: “FiveDice2.java”
//Define a class named FiveDice2
public class FiveDice2
{
//Define a main method
public static void main(String[] args)
{
//Declare a variable and initialize the value
final int NUM = 5;
//Store the five dice rolled value for computer
Die[] comp = new Die[NUM];
//Store the five dice rolled value for player
Die[] player = new Die[NUM];
//Declare a variable
int x;
//For loop to be executed until x exceeds NUM
for(x = 0; x < NUM; ++x)
{
//Allocating memory for the array objects
comp[x] = new Die();
player[x] = new Die();
}
//Declare the variables
int compMatch, playerMatch;
//Get computer name
String computerName = "Computer";
//Get player name
String playerName = "You";
//Display the message
display(computerName, comp, NUM);
display(playerName, player, NUM);
//Calls the method to find same numbers for computer
compMatch = howManySame(comp, NUM);
//Calls the method to find same numbers for player
playerMatch = howManySame(player, NUM);
//If computer has one of a kind
if(compMatch == 1)
//Print the result
System.out.println("Computer has nothing");
//Else computer has a pair, three, four, or five of a //kind
else
//Print the result
System.out.println("Computer has " + compMatch + " of a kind");
//If player has one of a kind
if(playerMatch == 1)
//Print the result
System.out.println("You have nothing");
//Else player has a pair, three, four, or five of a kind
else
//Print the result
System.out.println("You have " + playerMatch + " of a kind");
//If any higher combination of computer beats a lower //one of player
if(compMatch > playerMatch)
//Print the result
System...
b.
Explanation of Solution
Program:
File name: “Die.java”
//Define a class named Die
public class Die
{
//Declare the private variables and initialize the value
private int value;
private static final int HIGHEST_DIE_VALUE = 6;
private static final int LOWEST_DIE_VALUE = 1;
//Define a Die method
public Die()
{
//Calculate the value
value = ((int)(Math.random() * 100) % HIGHEST_DIE_VALUE +
LOWEST_DIE_VALUE);
}
//Define a getValue method
public int getValue()
{
//Return the value
return value;
}
}
File name: “FiveDice3.java”
//Define a class named FiveDice3
public class FiveDice3
{
//Define a main method
public static void main(String[] args)
{
//Declare a variable and initialize the value
final int NUM = 5;
//Store the five dice rolled value for computer
Die[] comp = new Die[NUM];
//Store the five dice rolled value for player
Die[] player = new Die[NUM];
//Declare a variable
int x;
//For loop to be executed until x exceeds NUM
for(x = 0; x < NUM; ++x)
{
//Allocating memory for the array objects
comp[x] = new Die();
player[x] = new Die();
}
//Declare the variables
int compMatch, playerMatch;
int compHigh, playerHigh;
//Get computer name
String computerName = "Computer";
//Get player name
String playerName = "You";
//Display the message
display(computerName, comp, NUM);
display(playerName, player, NUM);
//Calls the method to find same numbers for computer
compMatch = howManySame(comp, NUM);
//Calls the method to find same numbers for player
playerMatch = howManySame(player, NUM);
//Compute the value
compHigh = compMatch / 10;
playerHigh = playerMatch / 10;
compMatch = compMatch % 10;
playerMatch = playerMatch % 10;
//If computer has one of a kind
if(compMatch == 1)
//Print the result
System.out.println("Computer has nothing");
//Else computer has a pair, three, four, or five of a //kind
else
//Print the result
System.out.println("Computer has " + compMatch + " of a kind");
//If player has one of a kind
if(playerMatch == 1)
//Print the result
System.out.println("You have nothing");
//Else player has a pair, three, four, or five of a kind
else
//Print the result
System.out.println("You have " + playerMatch + " of a kind");
//If any higher combination of computer beats a lower one of player
if(compMatch > playerMatch)
//Print the result
System.out.println("Computer wins");
//Else
else
//If any higher combination of player beats
//a lower one of computer
if(compMatch < playerMatch)
//Print the result
System.out.println("You win");
//Else
else
{
//If values of computer are greater than player's value
if(compHigh > playerHigh)
//Print the result
System...
![Check Mark](/static/check-mark.png)
Trending nowThis is a popular solution!
![Blurred answer](/static/blurred-answer.jpg)
Chapter 8 Solutions
Java Programming, Loose-leaf Version
- I would like to know the main features about the following 3 key concepts:1. Backup Domain Controller (BDC)2. Access Control List (ACL)3. Dynamic Memoryarrow_forwardIn cell C21, enter a formula to calculate the number of miles you expect to drive each month. Divide the value of number of miles (cell A5 from the Data sheet) by the average MPG for the vehicle multiplied by the price of a gallon of gas (cell A6 from the Data sheet).arrow_forwardMicrosoft Excelarrow_forward
- In cell C16, enter a formula to calculate the price of the vehicle minus your available cash (from cell A3 in the Data worksheet). Use absolute references where appropriate—you will be copying this formula across the row what fomula would i use and how do i solve itarrow_forwardWhat types of data visualizations or tools based on data visualizations have you used professionally, whether in a current or past position? What types of data did they involve? What, in your experience, is the value these data views or tools added to your performance or productivity?arrow_forwardQuestion: Finding the smallest element and its row index and column index in 2D Array: 1. Write a public Java class min2D. 2. In min2D, write a main method. 3. In the main method, create a 2-D array myArray with 2 rows and 5 columns: {{10, 21, 20, 13, 1}, {2, 6, 7, 8, 14}}. 4. Then, use a nested for loop to find the smallest element and its row index and column index. 5. Print the smallest element and its row index and column index on Java Consolearrow_forward
- (using R)The iris data set in R gives the measurements in centimeters of the variables sepal length and width andpetal length and width, respectively, for 50 flowers from each of 3 species of iris, setosa, versicolor, andvirginica. Use the iris data set and the t.test function, test if the mean of pepal length of iris flowers isgreater than the mean of sepal length.The iris data set in R gives the measurements in centimeters of the variables sepal length and width andpetal length and width, respectively, for 50 flowers from each of 3 species of iris, setosa, versicolor, andvirginica. Use the iris data set and the t.test function, test if the mean of pepal length of iris flowers isgreater than the mean of sepal length.arrow_forwardRecognizing the Use of Steganography in Forensic Evidence (4e)Digital Forensics, Investigation, and Response, Fourth Edition - Lab 02arrow_forwardWrite a Java Program to manage student information of a university. The Javaprogram does the following steps:a) The program must use single-dimensional arrays to store the studentinformation such as Student ID, Name and Major.b) The program asks the user to provide the number of students.c) The program asks the user to enter the Student IDs for the number of studentsand stores them.d) The program asks the user to enter the corresponding names for the numberof students and stores them.e) The program then asks the user to provide the corresponding major for thestudents and stores them.f) The program then should display the following options:1. ID Search2. Major Enrollment3. Exitg) On selecting option 1, the user can search for a student using Student ID. Theprogram asks the user to enter a Student ID. It then should print thecorresponding student’s details such as Name and Major if the user providedStudent ID number is present in the stored data. If the user’s Student IDnumber does not…arrow_forward
- (a) Algebraically determine the output state |q3q2q1q0> (which is a 4-qubitvector in 16-dimensional Hilbert space). Show all steps of your calculations. (b) Run a Qiskit code which implements the circuit and append threemeasurement gates to measure the (partial) output state |q2q1q0> (which is a 3-qubit vector in 8-dimensional Hilbert space). this is for quantum soft dev class, you can use stuff like Deutsch Jozsa if u wantarrow_forwardWrite a C++ program that will count from 1 to 10 by 1. The default output should be 1, 2, 3, 4, 5, 6 , 7, 8, 9, 10 There should be only a newline after the last number. Each number except the last should be followed by a comma and a space. To make your program more functional, you should parse command line arguments and change behavior based on their values. Argument Parameter Action -f, --first yes, an integer Change place you start counting -l, --last yes, an integer Change place you end counting -s, --skip optional, an integer, 1 if not specified Change the amount you add to the counter each iteration -h, --help none Print a help message including these instructions. -j, --joke none Tell a number based joke. So, if your program is called counter counter -f 10 --last 4 --skip 2 should produce 10, 8, 6, 4 Please use the last supplied argument. If your code is called counter, counter -f 4 -f 5 -f 6 should count from 6. You should count from first to last inclusively.…arrow_forwardWrite a program that will count from 1 to 10 by 1. The default output should be 1, 2, 3, 4, 5, 6 , 7, 8, 9, 10 There should be only a newline after the last number. Each number except the last should be followed by a comma and a space. To make your program more functional, you should parse command line arguments and change behavior based on their values. Argument Parameter Action -f, --first yes, an integer Change place you start counting -l, --last yes, an integer Change place you end counting -s, --skip optional, an integer, 1 if not specified Change the amount you add to the counter each iteration -h, --help none Print a help message including these instructions. -j, --joke none Tell a number based joke. So, if your program is called counter counter -f 10 --last 4 --skip 2 should produce 10, 8, 6, 4 Please use the last supplied argument. If your code is called counter, counter -f 4 -f 5 -f 6 should count from 6. You should count from first to last inclusively. You…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
![Text book image](https://www.bartleby.com/isbn_cover_images/9781305480537/9781305480537_smallCoverImage.jpg)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102124/9781337102124_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)