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...
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.
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...
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...
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...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner object to read input. int Age;     Write a java statement to read the Age input value 4 . Redo 1 to 3 using JOptionPane
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...
Model the following in JAVA PROGRAMMING : In a software engineering project we are developing software...
Model the following in JAVA PROGRAMMING : In a software engineering project we are developing software for a Real estate agency. The Real Estate Agency has these types of properties: Shops, Apartments and Villas. All properties have: Property Owner, Address, Property Purpose (Sale/Rent), Area (in m^2) and price. Model these in an inheritance hierarchy considering that: 1. Shops have these fields in addition to properties: Floor (int), Street view (boolean). 2. Apartments have these feilds in addition to properties: Floor,...
Write a program that validates passwords based on the following requirements: • must be at least...
Write a program that validates passwords based on the following requirements: • must be at least 8 characters in length • must include at least 1 alphabet character • must include at least 1 number The program should implement the password checker using a function name validate_password, which takes two strings as input and returns one of the following: • 0 if the passwords match and fulfill all requirements • 1 if the passwords are not the same length •...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT