Using the code given as a reference. In the main file personalInfo.java create an ArrayList of person type named infolist. Add 3 person objects, 3 teacher objects and 3 student objects to the ArrayList, then navigate the ArrayList using a loop to print out the info on all 9 people. You can modify the program so it does not require you to get user input using a scanner, you can just create all of the people by passing in the information as parameters:  add.infolist(new person(tom , jones , 732-555-5555 , 20 Church Lane ); Make sure you pass the correct parameters for the object you are creating in the correct order. Given code: personalInfo.java // driver class import java.util.*; public class personalInfo {     static Scanner sc = new Scanner(System.in);     // main method     public static void main(String[] args) {         //printing the menu         System.out.println("Press 1. if you are person");         System.out.println("Press 2. if you are teacher");         System.out.println("Press 3. if you are student");         int choice = sc.nextInt();         sc.nextLine();         //switch case         switch (choice){             case 1:                 inputPersonInfo();                 break;             case 2:                 inputTeacherInfo();                 break;             case 3:                 inputStudentInfo();                 break;         }     }     //function to take student input and print the information     public static void inputStudentInfo() {         System.out.print("Enter the first name: ");         String fname = sc.nextLine();         System.out.print("Enter the last name: ");         String lname = sc.nextLine();         System.out.print("Enter the address: ");         String address = sc.nextLine();         System.out.print("Enter the phone number: ");         String phone = sc.nextLine();         System.out.print("Enter the year of graduation: ");         int year = sc.nextInt();         System.out.print("Enter the GPA: ");         double gpa = sc.nextDouble();         //creating the student object         student Student = new student(fname,lname,address,phone,year,gpa);         //calling the function to print the info         Student.printInfo();     }     public static void inputTeacherInfo() {         System.out.print("Enter the first name: ");         String fname = sc.nextLine();         System.out.print("Enter the last name: ");         String lname = sc.nextLine();         System.out.print("Enter the address: ");         String address = sc.nextLine();         System.out.print("Enter the phone number: ");         String phone = sc.nextLine();         System.out.print("Enter the number of teaching years: ");         int year = sc.nextInt();         teacher Teacher = new teacher(fname,lname,address,phone,year);         Teacher.printInfo();     }     public static void inputPersonInfo() {         System.out.print("Enter the first name: ");         String fname = sc.nextLine();         System.out.print("Enter the last name: ");         String lname = sc.nextLine();         System.out.print("Enter the address: ");         String address = sc.nextLine();         System.out.print("Enter the phone number: ");         String phone = sc.nextLine();         person Person = new person(fname,lname,address,phone);         Person.printInfo();     } } person.java import java.util.Scanner; class person{     private String firstName;     private String lastName;     private String streetAddress;     private String phoneNumber;     public person(String firstName, String lastName, String streetAddress, String phoneNumber) {         this.firstName = firstName;         this.lastName = lastName;         this.streetAddress = streetAddress;         this.phoneNumber = phoneNumber;     }     public void printInfo(){         System.out.println("First name: " + firstName);         System.out.println("Last name: " + lastName);         System.out.println("Street Address: " + streetAddress);         System.out.println("Phone Number: " + phoneNumber);     } } teacher.java class teacher extends person{     private int numberOfTeachingYear;     public teacher(String firstName, String lastName, String streetAddress, String phoneNumber, int numberOfTeachingYear) {         super(firstName, lastName, streetAddress, phoneNumber);         this.numberOfTeachingYear = numberOfTeachingYear;     }     @Override     public void printInfo() {         super.printInfo();         System.out.println("Number of teaching years: " + numberOfTeachingYear);     } } student.java class student extends person{     private int yearOfGraduation;     private double GPA;     public student(String firstName, String lastName, String streetAddress, String phoneNumber, int yearOfGraduation, double GPA) {         super(firstName, lastName, streetAddress, phoneNumber);         this.yearOfGraduation = yearOfGraduation;         this.GPA = GPA;     }     @Override     public void printInfo() {         super.printInfo();         System.out.println("Year of graduation: " + yearOfGraduation);         System.out.println("GPA: " + GPA);     } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Using the code given as a reference.

In the main file personalInfo.java create an ArrayList of person type named infolist.

Add 3 person objects, 3 teacher objects and 3 student objects to the ArrayList, then navigate the ArrayList using a loop to print out the info on all 9 people.

You can modify the program so it does not require you to get user input using a scanner, you can just create all of the people by passing in the information as parameters: 

add.infolist(new person(tom , jones , 732-555-5555 , 20 Church Lane );
Make sure you pass the correct parameters for the object you are creating in the correct order.




Given code:

personalInfo.java

// driver class
import java.util.*;
public class personalInfo {
    static Scanner sc = new Scanner(System.in);
    // main method
    public static void main(String[] args) {
        //printing the menu
        System.out.println("Press 1. if you are person");
        System.out.println("Press 2. if you are teacher");
        System.out.println("Press 3. if you are student");
        int choice = sc.nextInt();
        sc.nextLine();
        //switch case
        switch (choice){
            case 1:
                inputPersonInfo();
                break;
            case 2:
                inputTeacherInfo();
                break;
            case 3:
                inputStudentInfo();
                break;
        }

    }

    //function to take student input and print the information
    public static void inputStudentInfo() {
        System.out.print("Enter the first name: ");
        String fname = sc.nextLine();
        System.out.print("Enter the last name: ");
        String lname = sc.nextLine();
        System.out.print("Enter the address: ");
        String address = sc.nextLine();
        System.out.print("Enter the phone number: ");
        String phone = sc.nextLine();
        System.out.print("Enter the year of graduation: ");
        int year = sc.nextInt();
        System.out.print("Enter the GPA: ");
        double gpa = sc.nextDouble();
        //creating the student object
        student Student = new student(fname,lname,address,phone,year,gpa);
        //calling the function to print the info
        Student.printInfo();
    }

    public static void inputTeacherInfo() {
        System.out.print("Enter the first name: ");
        String fname = sc.nextLine();
        System.out.print("Enter the last name: ");
        String lname = sc.nextLine();
        System.out.print("Enter the address: ");
        String address = sc.nextLine();
        System.out.print("Enter the phone number: ");
        String phone = sc.nextLine();
        System.out.print("Enter the number of teaching years: ");
        int year = sc.nextInt();
        teacher Teacher = new teacher(fname,lname,address,phone,year);
        Teacher.printInfo();
    }

    public static void inputPersonInfo() {
        System.out.print("Enter the first name: ");
        String fname = sc.nextLine();
        System.out.print("Enter the last name: ");
        String lname = sc.nextLine();
        System.out.print("Enter the address: ");
        String address = sc.nextLine();
        System.out.print("Enter the phone number: ");
        String phone = sc.nextLine();
        person Person = new person(fname,lname,address,phone);
        Person.printInfo();
    }
}

person.java

import java.util.Scanner;

class person{
    private String firstName;
    private String lastName;
    private String streetAddress;
    private String phoneNumber;
    public person(String firstName, String lastName, String streetAddress, String phoneNumber) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.streetAddress = streetAddress;
        this.phoneNumber = phoneNumber;
    }
    public void printInfo(){
        System.out.println("First name: " + firstName);
        System.out.println("Last name: " + lastName);
        System.out.println("Street Address: " + streetAddress);
        System.out.println("Phone Number: " + phoneNumber);
    }
}

teacher.java

class teacher extends person{
    private int numberOfTeachingYear;

    public teacher(String firstName, String lastName, String streetAddress, String phoneNumber, int numberOfTeachingYear) {
        super(firstName, lastName, streetAddress, phoneNumber);
        this.numberOfTeachingYear = numberOfTeachingYear;
    }

    @Override
    public void printInfo() {
        super.printInfo();
        System.out.println("Number of teaching years: " + numberOfTeachingYear);
    }
}

student.java

class student extends person{
    private int yearOfGraduation;
    private double GPA;

    public student(String firstName, String lastName, String streetAddress, String phoneNumber, int yearOfGraduation, double GPA) {
        super(firstName, lastName, streetAddress, phoneNumber);
        this.yearOfGraduation = yearOfGraduation;
        this.GPA = GPA;
    }

    @Override
    public void printInfo() {
        super.printInfo();
        System.out.println("Year of graduation: " + yearOfGraduation);
        System.out.println("GPA: " + GPA);
    }
}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY