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

Problem Description: For this Lab you have to implement a class Person. A person

ID: 3671943 • Letter: P

Question

Problem Description: For this Lab you have to implement a class Person. A person has a fistname, lastname, address, and birthday year. Supply a constructor and the following methods: getName(), getAge(), getAddress, and changeAddress(),.

Step 1: Getting Started Create a class called Lab6. Be sure to name your file Lab6.java.

Step 2: Declaring Class

Examining the problem, we need to create a Person class, declare Person class as follows

Inside the class, declare some data members: a string variable called firstname, a string variable called lastname, and an integer called birthYear.

Step 3: Defining the constructor

}

Step4: Supply the methods

A method called getName() to get the name of an object Person:

}

A method called getAge() to get the age of an object Person:

}

A method called getAddress() to get the age of an object Person:

}
A method called changeAddress(String addr) to change the address of an object Person:

Step4: Calling the constructor of Person class from the “main” method

In order to use Person class variables and methods we need to have a runner function. For any class in java, “main” method will be the running method.

You class Lab6 will have the main method.

} }

In order to use the Person class variables and methods, you need to use the constructor to create an object Person.

/ /declare a Scanner object -->

// store the input in the declared variables -->

//use the constructor to create a brand-new object Person -->

Step6: Calling Person class methods and display the output

The methods in the Person class will display the required outputs.

Step7: Calling Person class methods

Now, call the changeAddress(addr) method in order to update the address to the following address:

Step8: Display the output

Sample Output

Sample Run 1:
Enter the first name of the person John
Enter the last name of the person Mann
Enter the address where the person lives E Rural Rd Tempe, AZ. Enter the birth year of the person 1991

Mann is 24 years old in 2016 and will be 34 years old in ten years. Mann lives in E Rural Rd Tempe, AZ.
Mann has moved to a new location: 72 E University Dr Tempe, AZ

Explanation / Answer

}

            { int currentYear;

String addr1;

System.out.println(“Enter the address to be changed and the current year:=> “);

BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
currentYear=Integer.parseInt(br.readLine());

addr1=br.readline();

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote