Question
Need class diagram for below java program, which has 2 classes ____________________________________________________________________________________________ public class People { //Declares the instance variables private String name; private String
Need class diagram for below java program, which has 2 classes
____________________________________________________________________________________________
public class People { //Declares the instance variables private String name; private String address; private int age; private String phNumber; //Default constructor People() { }
//setter functions that apply user input to private variables 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 that access the information in the private variables 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+" "; } } ________________________________________________________________________________________________________________
import java.util.Scanner;
public class Driver { public static void main(String args[]) { //opens new scanner Scanner input=new Scanner(System.in);
//Create three instances of the people class People person1=new People(); People person2=new People(); People person3=new People();
//Collects Person1s information from user System.out.printf("Enter the name of the first person: "); person1.setName(input.nextLine()); System.out.printf("Enter the address of "+person1.getName()+": "); person1.setAddress(input.nextLine()); System.out.printf("Enter the age of "+person1.getName()+": "); person1.setAge(Integer.parseInt(input.nextLine())); System.out.printf("Enter the phone number of "+person1.getName()+": "); person1.setPhNumber(input.nextLine());
//Collects Person2s information from user System.out.printf("Enter the name of the second person: "); person2.setName(input.nextLine()); System.out.printf("Enter the address of "+person2.getName()+": "); person2.setAddress(input.nextLine()); System.out.printf("Enter the age of "+person2.getName()+": "); person2.setAge(input.nextInt()); System.out.printf("Enter the phone number of "+person2.getName()+": "); input.nextLine();//to consume new line person2.setPhNumber(input.nextLine());
//Collects Person3s information from user System.out.printf("Enter the name of the third person: "); person3.setName(input.nextLine()); System.out.printf("Enter the address of "+person3.getName()+": "); person3.setAddress(input.nextLine()); System.out.printf("Enter the age of "+person3.getName()+": "); person3.setAge(input.nextInt()); System.out.printf("Enter the phone number of "+person3.getName()+": "); input.nextLine();//to consume new line person3.setPhNumber(input.next()); System.out.printf(" "); //Prints Person 1 information to the console System.out.printf(person1.toString()); System.out.printf(" "); //Prints Person 2 information to the console System.out.printf(person2.toString()); System.out.printf(" "); //Prints Person 3 information to the console System.out.printf(person3.toString()); //Closes the Scanner input.close(); } }
___________________________________________________________________________________________________
Have this so far
PEOPLE
-Name : string
-Address : string
-Age : int
-phNumber : string
+ setName ( ) : void
+ setAddress ( ) : void
+ setAge ( ) : void
+ setPhNumber ( ) : void
+ getName ( ) : string
+ getAddress ( ) : string
+ getAge ( ) : string
+ getPhNumber ( ) : string
+ toString ( ) : string
______________________________
DRIVER
-People ( ) : People person1
-People ( ) : People person2
-People ( ) : People person3
+ system.out.printf ( ) : string
+ system.out.printf ( ) : string
+ system.out.printf ( ) : string
+ system.out.printf ( ) : string
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