1. Please draw me a class diagram corresponding to the code. 2. And this code wo
ID: 3662502 • Letter: 1
Question
1. Please draw me a class diagram corresponding to the code.
2. And this code won't let me input data about second person. check that for me please
thanks
// Data.java
public class Data {
String name;
String address;
int age;
String phoneNumber;
Data(String n, String ad, int a, String p){
name = n;
address = ad;
age = a;
phoneNumber = p;
}
void setName(String n){
name = n;
}
void setAddress(String ad){
address = ad;
}
void setAge(int a){
age = a;
}
void setPhoneNumber(String p){
phoneNumber = p;
}
String getName(){
return name;
}
String getAddress(){
return address;
}
int getAge(){
return age;
}
String getPhoneNumber(){
return phoneNumber;
}
}
// test.java
import java.util.Scanner;
public class test{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
String n, ad, p;
int a;
System.out.println("Enter the name of first person: ");
n = in.next();
System.out.println("Enter the address of first person: ");
ad = in.next();
System.out.println("Enter the age of first person: ");
a = in.nextInt();
System.out.println("Enter the phone number of first person: ");
p = in.next();
Data d1 = new Data(n, ad, a, p);
System.out.println("Enter the name of second person: ");
n = in.next();
System.out.println("Enter the address of second person: ");
ad = in.next();
System.out.println("Enter the age of second person: ");
a = in.nextInt();
System.out.println("Enter the phone number of second person: ");
p = in.next();
Data d2 = new Data(n, ad, a, p);
System.out.println("Enter the name of third person: ");
n = in.next();
System.out.println("Enter the address of third person: ");
ad = in.next();
System.out.println("Enter the age of third person: ");
a = in.nextInt();
System.out.println("Enter the phone number of third person: ");
p = in.next();
Data d3 = new Data(n, ad, a, p);
}
}
Explanation / Answer
import java.util.Scanner;
class Data
{
String name;
String address;
int age;
String phoneNumber;
Data(String n, String ad, int a, String p)
{
name = n;
address = ad;
age = a;
phoneNumber = p;
}
void setName(String n){
name = n;
}
void setAddress(String ad){
address = ad;
}
void setAge(int a){
age = a;
}
void setPhoneNumber(String p){
phoneNumber = p;
}
String getName(){
return name;
}
String getAddress(){
return address;
}
int getAge(){
return age;
}
String getPhoneNumber(){
return phoneNumber;
}
}
// test.java
class test{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
String n, ad, p;
int a;
System.out.println("Enter the name of first person: ");
n = in.next();
System.out.println("Enter the address of first person: ");
ad = in.next();
System.out.println("Enter the age of first person: ");
a = in.nextInt();
System.out.println("Enter the phone number of first person:
");
p = in.next();
Data d1 = new Data(n, ad, a, p);
System.out.println("Enter the name of second person: ");
n = in.next();
System.out.println("Enter the address of second person: ");
ad = in.next();
System.out.println("Enter the age of second person: ");
a = in.nextInt();
System.out.println("Enter the phone number of second
person: ");
p = in.next();
Data d2 = new Data(n, ad, a, p);
System.out.println("Enter the name of third person: ");
n = in.next();
System.out.println("Enter the address of third person: ");
ad = in.next();
System.out.println("Enter the age of third person: ");
a = in.nextInt();
System.out.println("Enter the phone number of third person:
");
p = in.next();
Data d3 = new Data(n, ad, a, p);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.