Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

5. List the forces that shape a groups decisions

Answered: 1 week ago

Question

4. Identify how culture affects appropriate leadership behavior

Answered: 1 week ago