import javautilScanner public class Driver public static vo

import java.util.Scanner;

public class Driver {

   public static void main(String[] args) {

       Scanner stdIn = new Scanner(System.in);

       System.out.println(\"How many Person objects you want to construct? \");

       Person[] persons = new Person[stdIn.nextInt()];

       stdIn.nextLine();

       for (int index = 0; index < persons.length; index++) {

           persons[index] = promtAndRead(stdIn);
           System.out.println(persons[index].toString());

       }

       for (Person p : persons) {

           System.out.printf(\"\ To change the age of %s, please enter the new age\ \", p.getName());

           p.setAge(stdIn.nextInt());
           stdIn.nextLine();

           System.out.println(\"Updated data: \" + p.toString());

           System.out.printf(\"To change the name of %s, please enter the new name\ \", p.getName());
           p.setName(stdIn.nextLine());
           System.out.println(\"Updated data: \" + p.toString());

       }

   }

   public static Person promtAndRead(Scanner stdIn) {

       System.out.print(\"\ Please enter a name for a person: \");
       String name = stdIn.nextLine();

       System.out.printf(\"Please enter the SSN for %s : \", name);
       String ssn = stdIn.nextLine();

       System.out.printf(\"Please enter the age for %s : \", name);
       int age = stdIn.nextInt();

       stdIn.nextLine();

       Person pers = new Person(ssn, name);
       pers.setAge(age);

       return pers;

   }

****Create a Person class conforming to the diagram above. A person is assigned an immutable social security number at birth, and a name which can be changed later. People are born with an age of zero. The setAge method should set the person’s age. A senior citizen is someone over 65 years old.

****Create a driver that asks the user, in a loop, for a person’s name, ssn, and age. You should create an instance of your Person class and print the new person to the console. You should stop when the user enters the word ”quit”.

Person ssn: String name: String age: int Person (ssn: String, name: String) getName(): String setName(name: String) set Age (age: int get Age(): int isSenior Citizen(): boolean toString String

Solution

Hi, please find my implementation.

Please let me know in case of any issue.

public class Person {

  

   // instance variables

   private String ssn;

   private String name;

   private int age;

  

   public Person(String ssn, String name) {

       this.ssn = ssn;

       this.name = name;

   }

   public String getName() {

       return name;

   }

   public int getAge() {

       return age;

   }

   public void setName(String name) {

       this.name = name;

   }

   public void setAge(int age) {

       this.age = age;

   }

  

   public boolean isSeniorCitizen(){

       return age > 65;

   }

  

   @Override

   public String toString() {

       return \"SSN: \"+ssn+\", Name: \"+name+\", and Age: \"+age;

   }

}

import java.util.Scanner;

public class Driver {

   public static void main(String[] args) {

       Scanner stdIn = new Scanner(System.in);

       System.out.println(\"How many Person objects you want to construct? \");

       Person[] persons = new Person[stdIn.nextInt()];

       stdIn.nextLine();

       for (int index = 0; index < persons.length; index++) {

           persons[index] = promtAndRead(stdIn);

           System.out.println(persons[index].toString());

       }

       for (Person p : persons) {

           System.out.printf(\"\ To change the age of %s, please enter the new age\ \", p.getName());

           p.setAge(stdIn.nextInt());

           stdIn.nextLine();

           System.out.println(\"Updated data: \" + p.toString());

           System.out.printf(\"To change the name of %s, please enter the new name\ \", p.getName());

           p.setName(stdIn.nextLine());

           System.out.println(\"Updated data: \" + p.toString());

       }

   }

   public static Person promtAndRead(Scanner stdIn) {

       System.out.print(\"\ Please enter a name for a person: \");

       String name = stdIn.nextLine();

       System.out.printf(\"Please enter the SSN for %s : \", name);

       String ssn = stdIn.nextLine();

       System.out.printf(\"Please enter the age for %s : \", name);

       int age = stdIn.nextInt();

       stdIn.nextLine();

       Person pers = new Person(ssn, name);

       pers.setAge(age);

       return pers;

   }

}

/*

Sample run:

How many Person objects you want to construct?

2

Please enter a name for a person: Pravesh

Please enter the SSN for Pravesh : SB123

Please enter the age for Pravesh : 60

SSN: SB123, Name: Pravesh, and Age: 60

Please enter a name for a person: Mukesh Kuamr

Please enter the SSN for Mukesh Kuamr : Sb543

Please enter the age for Mukesh Kuamr : 43

SSN: Sb543, Name: Mukesh Kuamr, and Age: 43

To change the age of Pravesh, please enter the new age

45

Updated data: SSN: SB123, Name: Pravesh, and Age: 45

To change the name of Pravesh, please enter the new name

Pravesh M

Updated data: SSN: SB123, Name: Pravesh M, and Age: 45

To change the age of Mukesh Kuamr, please enter the new age

40

Updated data: SSN: Sb543, Name: Mukesh Kuamr, and Age: 40

To change the name of Mukesh Kuamr, please enter the new name

Mukesh M

Updated data: SSN: Sb543, Name: Mukesh M, and Age: 40

*/

import java.util.Scanner; public class Driver { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); System.out.println(\
import java.util.Scanner; public class Driver { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); System.out.println(\
import java.util.Scanner; public class Driver { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); System.out.println(\
import java.util.Scanner; public class Driver { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); System.out.println(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site