Explore BrainMass
Share

Programming in Java II

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

Question #1: Develop a program that prompts the user to guess the outcome of a die throw. Then throw a die (using a random number generator) and inform the user if they guessed the correct outcome. Count the number of correct guesses. Develop the program using a separate class for the die. Your program should contain two separate java files, one for the main method and one for your die class. The interaction should be as follows:

Guess the outcome of the die throw (1-6, 0 to quit): 3
The throw of the die was 5, sorry...

Guess the outcome of the die throw (1-6, 0 to quit): 2
The throw of the die was 2, you win!

Guess the outcome of the die throw (1-6, 0 to quit): 8
A die only has six sides...try again...

Guess the outcome of the die throw (1-6, 0 to quit): 0
You guessed correctly 1 time.
Thanks for playing.

The die class must contain (at least) the following methods:

A constructor that initializes the die to some random side.
roll() - sets the die to a random side
getFace() - returns the current value of the die

equals() - returns true when the passed die is equal to the current die
compareTo() - compares two dice returning -1, 0 or 1
toString() - returns the string representation of the current die

© BrainMass Inc. brainmass.com October 24, 2018, 10:06 pm ad1c9bdddf
https://brainmass.com/computer-science/random-number-generation/programming-java-148584

Attachments

Solution Summary

A program is developed that prompts the user to guess the outcome of a die throw. A program using a separate class for the die is determined.

$2.19
See Also This Related BrainMass Solution

Create an efficient Object-Oriented Java application that maintains information about college roommates who are renting a house together, for their realtor.

Create an efficient Object-Oriented Java application that maintains information about college roommates who are renting a house together, for their realtor.

When a house is chosen by the roommates, the user will provide information for it. To allow extensibility, a house object can be created with no information available, the address of the house only or the address of the house, monthly rent and security deposit.

The House class definition should include following instance variables:
- Address
- Number of roommates
- Monthly rent
- Security Deposit

The above class definition should also include following instance methods:
- Validating mutators for the numeric instance variables that are to receive values from the user (including monthly rent - must be between the minimum of $400 and the maximum $2500, and the security deposit - must be between $250 and the monthly rent of the house)
- addARoommate(), that will allow the user to include an additional roommate on the lease (not to exceed the 4 roommate limit - this is a maximum imposed by the realtor for any house)
- Accessors for the instance variables, as well as a toString() method to gather all pertinent information.
- Amount owed by each roommate for individual monthly rent
- Amount owed by each roommate for the entire 12 month lease (which includes their portion of the Security Deposit)

The Realtor application that implements the class described above should prompt the user for the house's address, monthly rent and security deposit. Then the application should process as many roommates (up to 4) the user chooses. The output should include the information on the house (Address, Monthly Rent, and Security Deposit and Total Yearly Income) as well as the number of roommates and their monthly and total financial obligation.

Only one house object is to be manipulated by the application.

View Full Posting Details