Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Game Theory Expert

The program asks the user four questions. It converts the person's favourite color, person's gender and person's level of education into a corresponding number. Finally a lucky number is generated based on a mathematical expression using these numbers.

Can you please modify my program so that it employs two classes: a "Driver" class (that contains the main method) and another class called "Lucky" that implements the operations seen in the original program.Note: I want the program to perform the exact same tasks as it does now (when the user runs the program). I just want my code modified so that it has two classes now.

One approach I have figured out is:

class Driver
{
public static void main (String [] args)
{
Lucky generator = new Lucky ();
generator.start();
}
}

With this approach the main loop for the program is contained in the "start" method of class Lucky.Furthermore, the calls to the different methods of class Lucky won't be made in the main method of the Driver class but instead will be made in the start method of class Lucky:
class Lucky
{
public void start ()
{
int ageModifier;
int colorModifier;
ageModifier = generator.determineAgeModifier ();
colorModifier = generator.determineColorModifier();
etc.
// The loop that asks the user if they want to re-run the program will be in method start and it will encompass all
// the calls to the methods of class Lucky.
}

public int determineAgeModifier ()
{
: :

return ageModifier;
}

: : : :

}

Here is an outline of the methods that you could implement in class Lucky:

1. public int determineAgeModifier (): This method prompts the user to enter his or her age. This value is stored in an integer and returned back to the caller of this method.

2. public int determineColorModifier (): This method prompts the user to enter his or her favourite primary color. Based on the value entered, the program will then determine the numeric value for the color modifier and return this value back to the caller of the method.

3. public int determineGenderModifier (): This method prompts the user to enter his or her gender. Based on the value entered, the program will then determine the numeric value for the gender modifier and return this value back to the caller of the method.

4. public int determineEducationModifier (): This method prompts the user to enter his or her current level of education (if the person is currently a student) or the highest level of education that he or she completed (if the person is no longer a student). Based on the value entered, the program will then determine the numeric value for the education modifier and return this value back to the caller of the method.

5. public int generateLuckyNumber (int ageModifier, int colorModifier, int genderModifier, int educationModifier): The parameters to this method are the four numeric modifiers that were generated by the previous four methods. Method generateLuckyNumber applies the formula outlined in the first assignment in order to calculate the largest lucky number. A call is in made to class Random (or some other class that generates random numbers) in order to generate a lucky number from zero to this maximum value. The lucky number is returned to the caller of generateLuckyNumber.

6. public void display (int luckyNumber): This takes the lucky number generated by the previous method (#5) and displays it to the onscreen along with whatever formatting statements that you wish to add.

I want this program to be able to compile and run on my computer. I use UNIX and compile my programs with javac filename.java (javac compiler). The UNIX file is then changed from something.java to something.class. To run the interpreter, in UNIX I type java filename.

Attachment:- ass1cpsc5.zip

Game Theory, Economics

  • Category:- Game Theory
  • Reference No.:- M91615775
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Game Theory

In this assessment task you will take the role of an expert

In this assessment task you will take the role of an expert economist, employed by a government department or regulatory authority. Decision-makers in government rely on the advice of experts, like you, when formulating ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As