Question: Create a class that converts human years to dog years. The American Kennel Club calculates the first year as 15 years, the second as 9

Create a class that converts human years to dog years. The American Kennel Club calculates the first year as 15 years, the second as 9 years and every following year as 5 years.

Create a project for the assignment.

Create a project for the assignment.

Create a ConvertDogYears class. Dogs age approximately 15 years in the first year of its life, 9 years in the second year of its life and 5 human years every year after. For example, a five year old dog has aged the human equivalent of: 15 human years * 1 dog years + 9 human years * 1 dog year + 5 human years * 3 dog years = 39 human years.

Set a constant as a field (at the class level) DOG_AGE_FIRST_YEAR equal to 15. Make it constant with the keywords static final.

Do the same for DOG_AGE_SECOND_YEAR equal to 9 and

DOG_AGE_REMAINING_YEARS equal to 5. private static final double DOG_AGE_FIRST_YEAR = 15;

Create the main method for the DogYears class.

Create a local boolean variable in main called again. This will be used to ask the user if they want to try again.

Create a Scanner or JOptionPane to ask the user for input.

Create a local double variable called humanYears.

Create a local double variable called dogYears.

Ask the user if they want to convert from human years or dog years. Use the chosen input method to get an answer. Loop until the answer is valid.

Ask the user for a years value. This can be a fractional value, so scan the input for a double. Years is always a value greater than zero because negative years do not make sense for humans or dogs. Make sure that any negative value is set to zero.

Based on the choice of the conversion, use the appropriate conversion from the next two steps.

To calculate the dog years from human years, use the following calculations.

If the humanYears value is greater than two, use the following formula: dogYears = DOG_AGE_FIRST_YEAR + DOG_AGE_SECOND_YEAR + (humanYears - 2) * DOG_AGE_REMAINING_YEARS;

Otherwise, if the humanYears value is greater than one or equal to two it is calculated with following formula: dogYears = DOG_AGE_FIRST_YEAR + (humanYears - 1) * DOG_AGE_SECOND_YEAR;

Otherwise, if the humanYears value is less than or equal to one, it is calculated with the following formula dogYears = DOG_AGE_FIRST_YEAR * humanYears;

This logic works, but is more complex than needed. As extra credit, but still using if statements and the constants as specified, simplify the logic for these equations.

Human years can be converted to dog years with the following equations:

If the dogYears value is greater than (DOG_AGE_FIRST_YEAR + DOG_AGE_SECOND_YEAR), then use the following formula: humanYears = ((dogYears - DOG_AGE_FIRST_YEAR - DOG_AGE_SECOND_YEAR) / DOG_AGE_REMAINING_YEARS) + 2;

Otherwise, if the dogYears value is less than or equal to (DOG_AGE_FIRST_YEAR + DOG_AGE_SECOND_YEAR) but greater than DOG_AGE_FIRST_YEAR, then use the following formula: humanYears = (dogYears - DOG_AGE_FIRST_YEAR) / DOG_AGE_SECOND_YEAR + 1;

Otherwise, if the dogYears value is less than or equal to DOG_AGE_FIRST_YEAR, then use the following formula: humanYears = dogYears / DOG_AGE_FIRST_YEAR;

This logic works, but is more complex than needed, just like the logic above. As extra credit, but still using if statements and the constants as specified, simplify the logic for these equations.

Display the human years and the dog years.

Ask the user if they want to quit or try again. Set the again boolean value based on their answer.

Loop back to the first question if they want to continue.

If they want to quit, print a message that indicates the program is exiting.

As required for all assignments from now on

validate the proper functionality using the example answers below and review the Concepts and Ideas checklist

format the code

add a comment at the top of the file that reads @ author and your name

build the javadocs

Verify that the jar file contains source and class files and the MANIFEST.MF file contains a Main-Class. See the Resources section for Configuring Eclipse to view Jar files.

Run the application from the jar file, either from the command line using java -jar jarfilename or from Eclipse. See the Resources section for Configuring Eclipse to run Jar files.

submit the jar file in the Assignment section of BlackBoard under View/Complete Assignment for this assignment.

Example:

Would you like to convert from human years or dog years? (H / D) d Please enter a year value: 45 6.2 in human years is 45.0 in dog years.

Enter 'Q' to quit, any other key to continue.

Would you like to convert from human years or dog years? (H / D) h Please enter a year value: 16 16.0 in human years is 94.0 in dog years.

Enter 'Q' to quit, any other key to continue. d

Would you like to convert from human years or dog years? (H / D) 15 Would you like to convert from human years or dog years? (H / D) d Please enter a year value: 15 1.0 in human years is 15.0 in dog years.

Enter 'Q' to quit, any other key to continue.

Would you like to convert from human years or dog years? (H / D) h Please enter a year value: -2 Please enter a year value: 2 2.0 in human years is 24.0 in dog years.

Enter 'Q' to quit, any other key to continue.

Would you like to convert from human years or dog years? (H / D) d Please enter a year value: 35 4.2 in human years is 35.0 in dog years.

Enter 'Q' to quit, any other key to continue.

Would you like to convert from human years or dog years? (H / D) h Please enter a year value: 6.2 6.2 in human years is 45.0 in dog years.

Enter 'Q' to quit, any other key to continue. q

Thanks for using the Dog Years converter.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!