Question

In: Computer Science

Write any java programming to meet the following requirements. Your project must meet the following requirements:...

Write any java programming to meet the following requirements.

Your project must meet the following requirements:

1. Specify input specification

     Design input

2. Specify Output Specification

    Design Output

3. The class must include set methods and get methods ( with or without parameters both)

4. Must include Array structure

5. Must include Input or Output Files or both

6. Demonstrate your knowledge of an Applet

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.



This is a very big question.
I have solved all of them. 
Please give me an upvote dear, Much Appreciated.!!

TwoDice.java

import java.util.Random;

public class TwoDice
{
    private int dLeft;
    private int dRight;
    Random random=new Random();

    // default constructor which sets dLeft and dRight to random "real" dice value.
    public TwoDice()
    {
        dLeft=1+random.nextInt(6);
        dRight = 1 + random.nextInt(6);
    }

    // constructor with parameters which sets the dice to specific values.
    public TwoDice(int dLeft, int dRight) {
        //  If the parameters are not between 1-6, force it to be 1.
        if(dLeft>=1 && dLeft<=6)
            this.dLeft = dLeft;
        else
            this.dLeft = 1;
        //  If the parameters are not between 1-6, force it to be 1.
        if(dRight>=1 && dRight<=6)
            this.dRight = dRight;
        else
            this.dRight = 1;
    }

    // accessors getDLeft(), getDRight(), and getTotal( )
    public int getDLeft() {
        return dLeft;
    }

    public int getDRight() {
        return dRight;
    }

    public int getTotal() {
        return dLeft+dRight;
    }

    // mutator setDLeft( ), setDRight( )
    public void setDLeft(int dLeft) {
        this.dLeft = dLeft;
    }

    public void setDRight(int dRight) {
        this.dRight = dRight;
    }
    // and roll( ) which rolls them to a value in the parameter.
    public void roll()
    {
        dLeft=1+random.nextInt(6);
        dRight = 1 + random.nextInt(6);
    }

    // toString( ) e.g. returns "4, 2" which are the values of the two dice
    public String toString() {
        return dLeft+", "+dRight;
    }

    // printMe( ) for debugging. It calls on toString( ).
    public void printMe()
    {
        System.out.println(this.toString());
    }

    // equals( ) to compare one pair of dice with another pair of dice.
    // Have it return true if one pair of dice has the same values as the other pair,
    // regardless of which is the left and which is the right dice.
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof TwoDice)) return false;
        TwoDice twoDice = (TwoDice) o;
        return (dLeft == twoDice.dLeft && dRight == twoDice.dRight) || (dLeft == twoDice.dRight && dRight == twoDice.dLeft);
    }

}

======

TwoDiceClient.java

import java.util.Scanner;

public class TwoDiceClient
{
    public static void main(String[] args) {
        System.out.println("Welcome To Yourname Dice Game...!!");
        Scanner scanner=new Scanner(System.in);
        System.out.print("What is your name? ");
        String name=scanner.nextLine();
        System.out.print("How many rounds to play? ");
        int rounds=scanner.nextInt();

        TwoDice twoDice=new TwoDice();
        int computerWins=0, userWins=0, tied=0;
        // start here
        // repeat for rounds times
        for(int i=1;i<=rounds;i++)
        {
            // print the output
            System.out.print("Play "+i+": "+name+" "+twoDice.getDLeft()+", Computer "+twoDice.getDRight()+".");
            // check who won
            if(twoDice.getDLeft() > twoDice.getDRight()) {
                System.out.println(" " + name + " wins.");
                // increment count
                userWins++;
            }
            else if(twoDice.getDLeft() < twoDice.getDRight()) {
                System.out.println(" Computer wins.");
                // increment count
                computerWins++;
            }
            else {
                System.out.println(" Tied.");
                // increment count
                tied++;
            }
            // ask to press enter
            System.out.println("Please enter to play another round.");
            scanner.nextLine();
            // Roll the dice
            twoDice.roll();
        }
        System.out.println("Score: "+name+" won "+userWins+" times. Computer won "+computerWins+" times. Tied "+tied+" times.");
    }
}

OUTPUTS:

CODE SCREENSHOTS:


Related Solutions

Java programming. *******I Need complete the following requirements in this project: 1/ Remove the applyRandomBonus method...
Java programming. *******I Need complete the following requirements in this project: 1/ Remove the applyRandomBonus method from the test class 2/ Create a File, Printwriter for an output file yourlastnameErrorLog.txt 3/ Set your maximum array size for accounts to 10 4/ Catch InputMismatch and ArrayIndexOutOfBounds exceptions when reading data from the file: a. Skip any lines that cause an exception b. Write information about the exception to the log file, yourlastnameError.txt c. Include exception type and line number in exception...
Java. Part 1 of 4 - Amusement Park Programming Project Requirements: Use the Java selection constructs...
Java. Part 1 of 4 - Amusement Park Programming Project Requirements: Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Proper error handling. Class: Ticket – models admission tickets. Instance Fields: number : long – identify the unique ticket. category : String – store the category of the ticket. holder : String – store the name of the person who purchased the ticket. date...
Java Project Requirements: 1.Write a Java program that plays a word game with a user. The...
Java Project Requirements: 1.Write a Java program that plays a word game with a user. The program asks the user questions and then creates a paragraph using the user’s answers. 2.The program must perform the following: a.Uses a Scanner object to ask the user: (The program asks for no other information) i.Full Name (First and Last name only) - stores this Full Name in one String object variable. ii.Age – must be read in as an int. iii.Profession or expected...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
What requirements must an instrument meet to be negotiable? Why do you think these are requirements?...
What requirements must an instrument meet to be negotiable? Why do you think these are requirements? Do some quick Internet research concerning a case that involves a holder in due course. Briefly explain the facts of the case, and the court's decision. Do you agree with the outcome? Explain.
The following are all due diligence requirements a Tax Professional must meet for a taxpayer claiming...
The following are all due diligence requirements a Tax Professional must meet for a taxpayer claiming EITC, AOTC, and CTC/ACTC EXCEPT: Maintain a copy of documents provided by the taxpayer that the Tax Professional relied on when determining eligibility for the credit. Record the date the information was obtained and the name of the person who provided the information. Complete all worksheets used to compute the credit. Worksheets completed by hand must be kept in the taxpayer's client file. When...
Programming. Write only code for the following. Do not write any comments. You can submit your...
Programming. Write only code for the following. Do not write any comments. You can submit your answer as .java file(s). #1. Design a Java JProduct class for a product which implements both cloneable and comparable interfaces The class should have the following private member variables: m_id: an integer that holds the product ID m_name: a string that holds the product name m_wholesaleprice: a double that holds the wholesale price m_retailers: a String array that holds all retailers who sell the...
Java Part 2 of 4 - Amusement Park Programming Project MUST BE COMPATIBLE WITH PART 1...
Java Part 2 of 4 - Amusement Park Programming Project MUST BE COMPATIBLE WITH PART 1 https://www.chegg.com/homework-help/questions-and-answers/java-part-1-4-amusement-park-programming-project-requirements-use-java-selection-construct-q40170145?trackid=ERIFssNL Requirements: Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Proper error handling. Class: Merchandise – models merchandise available in the gift shop such as t-shirts, sweatshirts, and stuffed animals. Instance Fields: id : long – to identify the specific merchandise item. category : String – to...
Java please! Write the code in Exercise.java to meet the following problem statement: Write a program...
Java please! Write the code in Exercise.java to meet the following problem statement: Write a program that will print the number of words, characters, and letters read as input. It is guaranteed that each input will consist of at least one line, and the program should stop reading input when either the end of the file is reached or a blank line of input is provided. Words are assumed to be any non-empty blocks of text separated by spaces, and...
13. To join a Medicare Advantage Plan you must meet the following eligibility requirements. Belong to...
13. To join a Medicare Advantage Plan you must meet the following eligibility requirements. Belong to several plans at your discretion Be enrolled in Medicare Part A Be enrolled in Medicare Part D Live in or just outside of the plans service area 14. Tier 1 drugs are generic drugs and are the same as their brand-name counterparts in safety, strength, quality, the way they work how they’re taken, and the way they should be used. True False 15. By...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT