Question: import java.util.Scanner; class Person { String firstName, lastName, address, zip, phone; void setData ( ) { Scanner scanner = new Scanner ( System . in

import java.util.Scanner;
class Person {
String firstName, lastName, address, zip, phone;
void setData(){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter first name: ");
firstName = scanner.nextLine();
System.out.print("Enter last name: ");
lastName = scanner.nextLine();
System.out.print("Enter address: ");
address = scanner.nextLine();
System.out.print("Enter zip code: ");
zip = scanner.nextLine();
System.out.print("Enter phone number: ");
phone = scanner.nextLine();
}
void display(){
System.out.println(firstName +""+ lastName +""+ address +""+ zip +""+ phone);
}
}
class CollegeEmployee extends Person {
String ssn;
double annualSalary;
String dept;
@Override
void setData(){
super.setData();
Scanner scanner = new Scanner(System.in);
System.out.print("Enter SSN: ");
ssn = scanner.nextLine();
System.out.print("Enter annual salary: ");
annualSalary = scanner.nextDouble();
scanner.nextLine(); // Consume the newline character
System.out.print("Enter department: ");
dept = scanner.nextLine();
}
@Override
void display(){
super.display();
System.out.println("SSN: "+ ssn);
System.out.println("Salary $"+ annualSalary);
System.out.println("Department: "+ dept);
}
}
class Faculty extends CollegeEmployee {
boolean isTenured;
@Override
void setData(){
super.setData();
Scanner scanner = new Scanner(System.in);
System.out.print("Is the faculty member tenured? (true/false): ");
isTenured = scanner.nextBoolean();
}
@Override
void display(){
super.display();
System.out.println("Faculty member is "+(isTenured ?"" : "not ")+ "tenured");
}
}
class Student extends Person {
String major;
double gpa;
@Override
void setData(){
super.setData();
Scanner scanner = new Scanner(System.in);
System.out.print("Enter major: ");
major = scanner.nextLine();
System.out.print("Enter GPA: ");
gpa = scanner.nextDouble();
}
@Override
void display(){
super.display();
System.out.println(" Major: "+ major +" GPA: "+ gpa);
}
}
public class CollegeList {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
Person[] people = new Person[14]; //4 CollegeEmployees +3 Faculty +7 Students
int collegeEmployeeCount =0;
int facultyCount =0;
int studentCount =0;
while (true){
System.out.print("Enter type of person's data (C, F, S) or quit (Q): ");
String choice = scanner.nextLine().toUpperCase();
if (choice.equals("Q")){
break;
}
switch (choice){
case "C":
if (collegeEmployeeCount <4){
people[collegeEmployeeCount++]= new CollegeEmployee();
people[collegeEmployeeCount -1].setData();
} else {
System.out.println("Error: Cannot enter more than 4 CollegeEmployees.");
}
break;
case "F":
if (facultyCount <3){
people[4+ facultyCount++]= new Faculty();
people[3+ facultyCount -1].setData();
} else {
System.out.println("Error: Cannot enter more than 3 Faculty members.");
}
break;
case "S":
if (studentCount <7){
people[7+ studentCount++]= new Student();
people[6+ studentCount -1].setData();
} else {
System.out.println("Error: Cannot enter more than 7 Students.");
}
break;
default:
System.out.println("Invalid choice. Please enter C, F, S, or Q.");
break;
}
}
System.out.println("
College Employees:");
for (int i =0; i < collegeEmployeeCount; i++){
people[i].display();
System.out.println();
}
System.out.println("
Faculty:");
for (int i =4; i <4+ facultyCount; i++){
people[i].display();
System.out.println();
}
System.out.println("
Students:");
for (int i =7; i <7+ studentCount; i++){
people[i].display();
System.out.println();
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!