Question
create a Java class diagram for the below Java program class PersonalInfo { //Declare instance variables private String name; private String address; private int age;
create a Java class diagram for the below Java program
class PersonalInfo
{
//Declare instance variables
private String name;
private String address;
private int age;
private String phNumber;
//Default constructor
PersonalInfo()
{
}
//setter functions
public void setName(String personName)
{
name=personName;
}
public void setAddress(String personAdd)
{
address=personAdd;
}
public void setAge(int personAge)
{
age=personAge;
}
public void setPhNumber(String personNumber)
{
phNumber=personNumber;
}
//getter functions
public String getName()
{
return name;
}
public String getAddress()
{
return address;
}
public int getAge()
{
return age;
}
public String getPhNumber()
{
return phNumber;
}
public String toString()
{
return "Name: "+name+" Age: "+age+" Address: "+address+" Phone Number: "+phNumber+" ";
}
}
/** PersonalInfoTester.java*/
import java.util.Scanner;
public class PersonalInfoTester
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
//Create three instances of the PersonalInfo class
PersonalInfo person1=new PersonalInfo();
PersonalInfo person2=new PersonalInfo();
PersonalInfo person3=new PersonalInfo();
System.out.print("Enter the name of person1: ");
person1.setName(input.nextLine());
System.out.print("Enter the address of "+person1.getName()+": ");
person1.setAddress(input.nextLine());
System.out.print("Enter the age of "+person1.getName()+": ");
person1.setAge(Integer.parseInt(input.nextLine()));
System.out.print("Enter the phone number of "+person1.getName()+": ");
person1.setPhNumber(input.nextLine());
System.out.println(person1.toString());
System.out.print("Enter the name of person2: ");
person2.setName(input.nextLine());
System.out.print("Enter the address of "+person2.getName()+": ");
person2.setAddress(input.nextLine());
System.out.print("Enter the age of "+person2.getName()+": ");
person2.setAge(input.nextInt());
System.out.print("Enter the phone number of "+person2.getName()+": ");
input.nextLine();//to consume new line
person2.setPhNumber(input.nextLine());
System.out.println(person2.toString());
System.out.print("Enter the name of person3: ");
person3.setName(input.nextLine());
System.out.print("Enter the address of "+person3.getName()+": ");
person3.setAddress(input.nextLine());
System.out.print("Enter the age of "+person3.getName()+": ");
person3.setAge(input.nextInt());
System.out.print("Enter the phone number of "+person3.getName()+": ");
input.nextLine();//to consume new line
person3.setPhNumber(input.next());
System.out.println(person3.toString());
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started