I have written code for a program (attachment) in java. In it, my main method contained all of my program code.
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:
public static void main (String  args)
Lucky generator = new Lucky ();
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:
public void start ()
ageModifier = generator.determineAgeModifier ();
colorModifier = generator.determineColorModifier();
// 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 ()
: : : :
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.© BrainMass Inc. brainmass.com July 22, 2018, 6:40 pm ad1c9bdddf
The main methods of Java programming are analyzed. The value stored in an integer and returned for a bank caller method is provided.