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); } }
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);
}
}
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)