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...

Trending nowThis is a popular solution!

Chapter 8 Solutions
MindTapV2.0 for Farrell's Java Programming with 2021 Updates, 9th Edition [Instant Access], 1 term
- usiing python remove all negative values from a list of values values = [34, -8, -5, 4, 6, 7]arrow_forwardUsing python, remove highes and lowest score and then sum the remaining 6 scores: scores = [1.4, 5.5, 4.7, 2.0, 6.3, 7.5, 2.6, 5.3, 8.1] totalScore= print("Score = %5.2f" % totalScorearrow_forwardWhat are quantitative and qualitative data? Describe an example of a use case and visual representation for qualitative data and one for quantitative data from your organization.arrow_forward
- 1. Checksum. Assuming the following IP header lacking checksum: 01000101.00000000.11000011.00101010. 00000000.00000000.00000000.00000000. 10000000.00000000.00000000.00000000. <- checksum 01100011.11011001.00000000.00000001. 10000000.00000000.00000000.00000010 Compute its checksumarrow_forwardI would like to know the features of BranchCache, Metadata, and LPR Port Monitorarrow_forwardPlease answer the JAVA OOP questions below: How do arrays of objects differ from arrays of primitive types? Why and when would you use an array of objects? What are the different ways to initialize an array of objects? What is a static variable in Java? How does its scope differ from instance variables? When should you use static variables? Provide examples where static variables are beneficial over instance variables. What is the difference between static and non-static methods in the Data Definition Class? What are the benefits of using static methods?arrow_forward
- Assume you are a loyal member of Costco. You have been expecting your membership reward from the company, and you just received a text message on your mobile phone. The message appears to be from Costco: Costco - Your 3% return is ready: costco.wholesaledividend.com Before clicking the link in the message, you consider whether this is genuinely from Costco or a phishing attack on you. How can you tell? If it is a phishing attack, what mechanism was most likely used to send the message to you? What actions can you take if you are not sure whether it is a genuine message from Costco? What actions can you take if you are sure this is a phishing attack?arrow_forwardRSA and Diffie-Hellman are important algorithms in public-key cryptography. What are the differences between the two? Assume you intercept the ciphertext C = 105 sent to a user whose public key is e = 7, n = 403. Explain in detail how you will find the private key of the user and crack the ciphertext. What is the plaintext M?arrow_forwardCBC-Pad is a block cipher mode of operation commonly used in block ciphers. CBC-Pad handles plain text of any length. Padding is used to ensure that the plaintext input is a multiple of the block length. Hence, the ciphertext is longer than the plaintext by at most the size of a single block.Assume that the original plaintext is 556 bytes and the size of a cipher block is 28 bytes. What will be the padding? If the original plaintext is an integer multiple of the block size, will padding still be needed? Why or why not?arrow_forward
- Abstract classes & Interfaces (Ch13) 5. See the code below and solve the following. class Circle { protected double radius; // Default constructor public Circle() ( } this(1.0); // Construct circle with specified radius public Circle(double radius) { } this.radius radius; // Getter method for radius public double getRadius() { } return radius; // Setter method for radius public void setRadius(double radius) { } this.radius = radius; // Implement the findArea method defined in GeometricObject public double findArea() { } return radius* radius * Math. PI; // Implement the find Perimeter method defined in GeometricObject public double findPerimeter() { } return 2*radius*Math.PI; // Override the equals() method defined in the Object class public boolean equals(Circlel circle) { } return this.radius == circle.getRadius(); // Override the toString() method defined in the Object class public String toString() { } } return "[Circle] radius = " + radius; 5-1. Define a class name…arrow_forward6. What is Race condition? How to prevent it? [2 marks] 7. How many synchronization methods do you know and compare the differences. [2 marks] 8. Explain what are the “mutual exclusion”, “deadlock”, “livelock”, and “eventual entry”, with the traffic intersection as an example like dinning philosophy. [2 marks] 9. For memory allocation, what are the difference between internal fragmentation and external fragmentation. Explain with an example. [2 marks] 10. How can the virtual memory map to the physical memory. Explain with an example. [2 marks]arrow_forwardYour answers normally have 50 words. Less than 50 words will not get marks. 1. What is context switch between multiple processes? [2 marks] 2. Draw the memory layout for a C program. [2 marks] 3. How many states does a process has? [2 marks] 4. Compare the non-preemptitve scheduling and preemptive scheduling. [2 marks] 5. Given 4 process and their arrival times and next CPU burst times, what are the average times and average Turnaround time, for different scheduling algorithms including: a. First Come, First-Served (FCFS) Scheduling [2 marks] b. Shortest-Job-First (SJF) Scheduling [2 marks] c. Shortest-remaining-time-first [2 marks] d. Priority Scheduling [2 marks] e. Round Robin (RR) [2 marks] Process Arrival Time Burst Time P1 0 8 P2 1 9 P3 3 2 P4 5 4arrow_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




