So Far I have these two classes but I need help with my pers

So Far I have these two classes but I need help with my persontest class:

The next step is to add method calls for the accessor methods after each input:

//Reading and updating values
System.out.print(\"\ Enter Person Name: \");
person1.setPersonName(sc.nextLine());
System.out.println(\"You entered: \" + person1.getPersonName());

Call the accessor function each time you ask for input, after capturing that input. Then repeat for a second Person, only this time call the constructor that takes the student id as a parameter.

7 import java.util.Scanner;
8
9 class PersonTest
10 {
11 //Main method
12 public static void main(String args[])
13 {
14 Scanner sc = new Scanner(System.in);
15
16 //Creating object
17 Persons_Information person1 = new Persons_Information();
18
19 //Reading and updating values
20 System.out.print(\"\ Enter Person Name: \");
21 person1.setPersonName(sc.nextLine());
22
23 System.out.print(\"\ Enter Current Address: \");
24 person1.setCurrentAdress(sc.nextLine());
25
26 System.out.print(\"\ Enter Permanent Address: \");
27 person1.setpermanentAdress(sc.nextLine());
28
29 System.out.print(\"\ Enter ID number: \");
30 person1.setIdNumber(sc.nextInt());
31
32 sc.nextLine();
33
34 System.out.print(\"\ Enter Birth Date: \");
35 person1.setBirthDate(sc.nextLine());
36
37
38 System.out.print(\"\ Enter Person Age: \");
39 person1.setPersonAge(sc.nextInt());
40
41
42 System.out.print(\"\ Enter Entry Year: \");
43 person1.setEntryYear(sc.nextInt());
44
45
46 System.out.print(\"\ Enter Total Years: \");
47 person1.setTotalYears(sc.nextInt());
48
49 //Printing person 1 details
50 System.out.println(\"\ Person 1: \ \" + person1.toString());
51 }
52 }

Solution

Persons_Information.java

public class Persons_Information {
  
//Declaring instance variables
private String personName;
private String currentAdress;
private String permanentAdress;
private int idNumber;
private String birthDate;
private int    personAge;
private int entryYear;
private int totalYears;

//Zero argumented constructor
public Persons_Information()
{
}

//Parameterized constructor
public Persons_Information(int idNumber) {
   this.idNumber = idNumber;
}

//Getters and setters
public String getPersonName() {
   return personName;
}
public void setPersonName(String personName) {
   this.personName = personName;
}
public String getCurrentAdress() {
   return currentAdress;
}
public void setCurrentAdress(String currentAdress) {
   this.currentAdress = currentAdress;
}
public String getPermanentAdress() {
   return permanentAdress;
}
public void setPermanentAdress(String permanentAdress) {
   this.permanentAdress = permanentAdress;
}
public int getIdNumber() {
   return idNumber;
}
public void setIdNumber(int idNumber) {
   this.idNumber = idNumber;
}
public String getBirthDate() {
   return birthDate;
}
public void setBirthDate(String birthDate) {
   this.birthDate = birthDate;
}
public int getPersonAge() {
   return personAge;
}
public void setPersonAge(int personAge) {
   this.personAge = personAge;
}
public int getEntryYear() {
   return entryYear;
}
public void setEntryYear(int entryYear) {
   this.entryYear = entryYear;
}
public int getTotalYears() {
   return totalYears;
}
public void setTotalYears(int totalYears) {
   this.totalYears = totalYears;
}

//toString() method is used to display the contents of an object indide it
@Override
public String toString() {
   return \"Persons_Information#\ Person Name=\" + personName + \"\ Current Adress=\"
           + currentAdress + \"\ Permanent Adress=\" + permanentAdress
           + \"\ Id Number=\" + idNumber + \"\ Birth Date=\" + birthDate
           + \"\ Person Age=\" + personAge + \"\ EntryYear=\" + entryYear
           + \"\ TotalYears=\" + totalYears;
}

}

___________________________________

PersonTest.java

import java.util.Scanner;

class PersonTest
{
//Main method
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
  
//Creating object
Persons_Information person1 = new Persons_Information();
  
//Reading and updating values
System.out.print(\"\ Enter Person Name: \");
person1.setPersonName(sc.nextLine());
System.out.println(\"You entered: \" + person1.getPersonName());
  
System.out.print(\"\ Enter Current Address: \");
person1.setCurrentAdress(sc.nextLine());
System.out.println(\"You entered: \" + person1.getCurrentAdress());
  
System.out.print(\"\ Enter Permanent Address: \");
person1.setPermanentAdress(sc.nextLine());
System.out.println(\"You entered: \" + person1.getPermanentAdress());
  
System.out.print(\"\ Enter ID number: \");
person1.setIdNumber(sc.nextInt());
System.out.println(\"You entered: \" + person1.getIdNumber());
  
sc.nextLine();
  
System.out.print(\"\ Enter Birth Date: \");
person1.setBirthDate(sc.nextLine());
System.out.println(\"You entered: \" + person1.getBirthDate());
  
System.out.print(\"\ Enter Person Age: \");
person1.setPersonAge(sc.nextInt());
System.out.println(\"You entered: \" + person1.getPersonAge());
  
System.out.print(\"\ Enter Entry Year: \");
person1.setEntryYear(sc.nextInt());
System.out.println(\"You entered: \" + person1.getEntryYear());
  
System.out.print(\"\ Enter Total Years: \");
person1.setTotalYears(sc.nextInt());
System.out.println(\"You entered: \" + person1.getTotalYears());
//Printing person 1 details
System.out.println(\"\ Person 1: \ \" + person1.toString());
  
System.out.println(\"______Creating the Person#2 Object______\");
  
System.out.print(\"\ Enter ID number: \");
int id=sc.nextInt();
Persons_Information pi2=new Persons_Information(id);
System.out.println(\"You Entered Person Id :\"+pi2.getIdNumber());
  
sc.nextLine();
  
//Reading and updating values
System.out.print(\"\ Enter Person Name: \");
pi2.setPersonName(sc.nextLine());
System.out.println(\"You entered: \" + pi2.getPersonName());
  
System.out.print(\"\ Enter Current Address: \");
pi2.setCurrentAdress(sc.nextLine());
System.out.println(\"You entered: \" + pi2.getCurrentAdress());
  
System.out.print(\"\ Enter Permanent Address: \");
pi2.setPermanentAdress(sc.nextLine());
System.out.println(\"You entered: \" + pi2.getPermanentAdress());
  
  
System.out.print(\"\ Enter Birth Date: \");
pi2.setBirthDate(sc.nextLine());
System.out.println(\"You entered: \" + pi2.getBirthDate());
  
System.out.print(\"\ Enter Person Age: \");
pi2.setPersonAge(sc.nextInt());
System.out.println(\"You entered: \" + pi2.getPersonAge());
  
System.out.print(\"\ Enter Entry Year: \");
pi2.setEntryYear(sc.nextInt());
System.out.println(\"You entered: \" + pi2.getEntryYear());
  
System.out.print(\"\ Enter Total Years: \");
pi2.setTotalYears(sc.nextInt());
System.out.println(\"You entered: \" + pi2.getTotalYears());
  
//Printing person 2 details
System.out.println(\"\ Person 1: \ \" + pi2.toString());
}
}

____________________________

output:


Enter Person Name: Williams
You entered: Williams

Enter Current Address: 101,Park Street, Newyork
You entered: 101,Park Street, Newyork

Enter Permanent Address: 101,Park Street, Newyork
You entered: 101,Park Street, Newyork

Enter ID number: 1234
You entered: 1234

Enter Birth Date: oct-12-2000
You entered: oct-12-2000

Enter Person Age: 16
You entered: 16

Enter Entry Year: 2016
You entered: 2016

Enter Total Years: 5
You entered: 5

Person 1:
Persons_Information#
Person Name=Williams
Current Adress=101,Park Street, Newyork
Permanent Adress=101,Park Street, Newyork
Id Number=1234
Birth Date=oct-12-2000
Person Age=16
EntryYear=2016
TotalYears=5
______Creating the Person#2 Object______

Enter ID number: 7891
You Entered Person Id :7891

Enter Person Name: Kane
You entered: Kane

Enter Current Address: 22,Church Road,Newyork
You entered: 22,Church Road,Newyork

Enter Permanent Address: 22,Church Road,Newyork
You entered: 22,Church Road,Newyork

Enter Birth Date: nov-12-2001
You entered: nov-12-2001

Enter Person Age: 15
You entered: 15

Enter Entry Year: 2010
You entered: 2010

Enter Total Years: 5
You entered: 5

Person 1:
Persons_Information#
Person Name=Kane
Current Adress=22,Church Road,Newyork
Permanent Adress=22,Church Road,Newyork
Id Number=7891
Birth Date=nov-12-2001
Person Age=15
EntryYear=2010
TotalYears=5

___________________Thank You

So Far I have these two classes but I need help with my persontest class: The next step is to add method calls for the accessor methods after each input: //Read
So Far I have these two classes but I need help with my persontest class: The next step is to add method calls for the accessor methods after each input: //Read
So Far I have these two classes but I need help with my persontest class: The next step is to add method calls for the accessor methods after each input: //Read
So Far I have these two classes but I need help with my persontest class: The next step is to add method calls for the accessor methods after each input: //Read
So Far I have these two classes but I need help with my persontest class: The next step is to add method calls for the accessor methods after each input: //Read
So Far I have these two classes but I need help with my persontest class: The next step is to add method calls for the accessor methods after each input: //Read

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site