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

[Java] Design a class that hold the personal data: name, address, age and phone

ID: 3662422 • Letter: #

Question

[Java]

Design a class that hold the personal data: name, address, age and phone number. Write appropriate methods (constructor, getters ad setters. Demonstrate the class by writing a program that creates three instances of the class. You can populate information in each object using Scanner class. Please do not use any personal information as data in the project.

I'm a super beginner in java. Please explain the code in detail. And also please provide a class diagram too. Thank you for your help.

Explanation / Answer

public class PersonalInformationDemo

{

public static void main(String[] args)

{

// Create three Peronsal Information objects.

PersonalInformationClass me = new PersonalInformationClass();

me.setName("Firstname lastname");

me.setAge(16); // your age goes in the parenthesis

me.setAddress("your address goes here");

me.setPhone("your phone number goes here");

PersonalInformationClass Friend1 = new PersonalInformationClass();

Friend1.setName("friend 1 name goes here");

Friend1.setAge(19);//friend 1 age

Friend1.setAddress("Friend 1 Address here");

Friend1.setPhone("Friend 1 Phone number here");

PersonalInformationClass Friend2 = new PersonalInformationClass();

Friend2.setName("Friend 2 name goes here");

Friend2.setAge(21); //friend 2 age

Friend2.setAddress("Friend 2 Address here");

Friend2.setPhone("Friend 2 Phone number here");

// Display my info.

System.out.println("My information:");

System.out.println("Name: " + me.getName());

System.out.println("Age: " + me.getAge());

System.out.println("Address: " + me.getAddress());

System.out.println("Phone: " + me.getPhone());

// Display friend #1's info.

System.out.println(" Friend #1's information:");

System.out.println("Age: " + Friend1.getAge());

System.out.println("Address: " + Friend1.getAddress());

System.out.println("Phone: " + Friend1.getPhone());

// Display friensd #2's info.

System.out.println(" Friend #2's information:");

System.out.println("Age: " + Friend2.getAge());

System.out.println("Address: " + Friend2.getAddress());

System.out.println("Phone: " + Friend2.getPhone());

}

}

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