Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Java program that will create an array for a dog years to human years c

ID: 3716643 • Letter: C

Question

Create a Java program that will create an array for a dog years to human years conversion.

The class name will be "Lab_DogYears". All methods will be "public static".

The formula for dog years to human years is:

Human Years = [ ( Dog Years - 1 ) * 4 ] + 15

The program will ask the user to enter the year the dog is born. The format is the date is MM/DD/YYYY.

Validate the birth date so that the date can not be before 01/01/2000. Also validate the month, day, and year so that the integers are in range.

The program should calculate the number of full years have passed since the dog was born up to 04/28/2018. Disregard any leap years.

It will create a dog chart(constant array) to hold the different number of years a dog ages in human years.

Then the program will state how old the dog currently is (as of 04/28/2018) in human years.

The methods and main() will be on the same java file.

The program should look like

Intput:

Enter the date of birth of the dog: 01/01/2010

Output:

The dog have lived for 8 years.

[ 15 19 23 27 31 35 39 43]

The dog is 43 years old in human age.

Explanation / Answer

import java.util.Scanner;

public class Chegg4 {

public static void main(String args[]){

Scanner sc=new Scanner(System.in);

System.out.print("Enter the date of birth of the dog: ");

String dob=sc.nextLine();

String temp[]=dob.split("/");

if(Integer.parseInt(temp[2])<2000){

System.out.println("Enter correct dob of dob (it must be less than 01/01/2000)");

}

else{

int Dog_Years=2018-Integer.parseInt(temp[2]);

System.out.println("The dog have lived for "+Dog_Years+" years.");

System.out.print("[ ");

int Human_Years=0;

for(int i=1;i<=Dog_Years;i++){

Human_Years = ( ( i - 1 ) * 4 ) + 15;

System.out.print(Human_Years+" ");

}

System.out.println("]");

System.out.println("The dog is "+Human_Years+" years old in human age.");

}

}

}