Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Why won't this code compile? For example, when I try to compile Faculty I get this error. error: cannot find symbol public class Faculty extends

Why won't this code compile?

For example, when I try to compile Faculty I get this error.

error: cannot find symbol public class Faculty extends Employee

with the error pointing to employee. When I compile Employee, the error is that it cannot find people, however people compiles perfectly. What is going on and how can I fix it?

Here are the HW insturctions.

During this homework, you will be implementing the following class hierarchy that implements university systems. In this university system, the university is associated with multiple people types. People can be Employee type or Student type. Employee can be either Faculty or Staff. The following class diagram show the relationship among objects.

package university;

import java.util.*;

public class University

{

public static void main(String args[]) {

String univ_Name, location; ArrayList people = new ArrayList(); char choice = 'A'; String line; Scanner scan = new Scanner(System.in);

String first_name; String last_name; String phoneNumber; String major; double payRate; int payScale ; do { //calling printMenu method printMenu(); System.out.println("Enter your choice ?"); //prompt to enter user choice choice=scan.nextLine().charAt(0); // read the name and the location of the university here switch (choice) { case 'A': // add a Student here /* * read the first name, last name, phone number, major as * parameters and then call the constructor of the Student * class to create the instance then read the gpa, call * setGpa method of the student to set the gpa finally add * the student instance to the people list */ System.out.println("Enter first name, " + "last name, phone number, major: "); first_name = scan.nextLine(); last_name = scan.nextLine(); phoneNumber = scan.nextLine(); major = scan.nextLine(); Student st = new Student(first_name, last_name, phoneNumber, major); people.add(st); break; case 'B': // add a Staff here /* * read the first name, last name, phone number, payRate, * payScale, and title and then call the constructor of the * Staff class to create the instance finally add the Staff * instance to the people list */

System.out.println("Enter first name, last name, phone number, payRate, payScale, and title: "); first_name = scan.nextLine(); last_name = scan.nextLine(); phoneNumber = scan.nextLine(); payRate = scan.nextDouble(); payScale = scan.nextInt(); scan.nextLine(); String title = scan.nextLine(); Staff stf = new Staff(first_name, last_name, phoneNumber,payRate,payScale, title); people.add(stf); break;

case 'C':

// add a Faculty here /*

* read the first name, last name, phone number, payRate,

* payScale, and department and then call the constructor of

* the Faculty class to create the instance read list of

* courses the instructor read and call the addClass method

* of the faculty to add classes finally add the Faculty

* instance to the people list

*/System.out.println("Enter first name, last name, phone number, payRate, payScale, and department "); first_name = scan.nextLine(); last_name = scan.nextLine(); phoneNumber = scan.nextLine(); payRate = scan.nextDouble(); payScale = scan.nextInt(); scan.nextLine(); String department = scan.nextLine(); Faculty fcl = new Faculty(first_name, last_name, phoneNumber,payRate,payScale, department); people.add(fcl); break;

case 'D':

// display university info

/*

* university name, location, number of students, number of

* faculty and number of staff

*/ //System.out.println(univ_Name+" "+location);

int studentCount=0;

int facultyCount=0;

int staffCount=0; for(People p:people) {

if(p instanceof Student) studentCount++; else if (p instanceof Faculty) facultyCount++; else if (p instanceof Staff) staffCount++; }

System.out.println("Number of Students: "+studentCount); System.out.println("Number of Staff: "+staffCount); System.out.println("Number of Faculty: "+facultyCount);

break; case 'E': // display people info /* * display the fist name and the last name of each person at * school * */ for(People p:people) { System.out.println(p); } break; case 'F': // display Student info /* * display fist name, last name, and the major of each * student java has a construct called instanceof. That * construct can determine the object instance type example: * String str = new String("hello"); if(str instanceof * String) will be evaluated to true */ for(People p:people) { if( p instanceof Student) { System.out.println(p); } } break; case 'G': // display Employee info

/* * display fist name, last name, pay payRate, and monthly pay * of each employee * */ for(People p:people) if( p instanceof Employee) { System.out.println(p); } break; case 'Q': System.exit(0); // quit the program

break; case '?': printMenu(); // display the menu again break; default: System.out.print("Unknown action "); } }while(choice!='Q'); } public static void printMenu() { System.out.print("Choice\t\tAction " +"------\t\t------ " + "A\t\tAdd a Student " + "B\t\tAdd a Staff " + "C\t\tAdd a Faculty "+ "D\t\tDisplay University Info " + "E\t\tDisplay University People Info " + "F\t\tDisplay University Student Info " + "G\t\tDisplay University Employee Info " + "Q\t\tQuit " + "?\t\tDisplay Menu Again "); } }

------------------------------------------------------------------------------------------------------------------------

//Student.java

package university;

public class Student extends People { protected String major; protected int gpa; public Student(String first_name, String last_name, String phoneNumberber, String major) { super(first_name, last_name, phoneNumberber); //Note //Set major this.major=major; this.gpa = 0; } public void setGpa(int gpa) { this.gpa = gpa; } public void changeMajor(String major) { this.major = major; } public String toString() { return "Student{" +"gpa=" + gpa +", major='" + major + '\'' +", first_name='" + first_name + '\'' +", last_name='" + last_name + '\'' +", phoneNumberber=" + phoneNumberber +'}'; } }

------------------------------------------------------------------------------------------------------------------------

//People.java package university; public class People { protected String first_name, last_name; //Note: //convert phonenumber from integer type to string protected String phoneNumberber; protected double payRate; protected double monthlyPay;

//Note:Phonenumber integer type to string public People(String first_name, String last_name, String phoneNumberber) { this.first_name = first_name; this.last_name = last_name; this.phoneNumberber = phoneNumberber; this.payRate = 0; this.monthlyPay = 0; } public void calculatePay() { this.monthlyPay = 0; } public String getName() { return first_name + " " + last_name; } public String toString() { return "People{" +"first_name='" + first_name + '\'' +", last_name='" + last_name + '\'' +", phoneNumberber=" + phoneNumberber +'}'; } }

------------------------------------------------------------------------------------------------------------------------

//Faculty.java package university; import java.util.ArrayList; public class Faculty extends Employee { protected String department; protected ArrayList classesTeach;

public Faculty(String first_name, String last_name, String phoneNumberber, double payRate, int payScale, String department) { super(first_name, last_name, phoneNumberber, payRate, payScale); this.department = department; classesTeach = new ArrayList<>(); } public void addClass(String className) { classesTeach.add(className); } public void calculatePay(){ monthlyPay = payRate/payScale + 500*classesTeach.size(); } public String toString() { return "Faculty{" +"first_name='" + first_name + '\'' +", last_name='" + last_name + '\'' +", classesTeach=" + classesTeach +", monthlyPay=" + monthlyPay +'}'; } }

------------------------------------------------------------------------------------------------------------------------

//Employee.java package university; public class Employee extends People { protected int payScale; public Employee(String first_name, String last_name, String phoneNumberber, double payRate, int payScale) { super(first_name, last_name, phoneNumberber); this.payScale = payScale; } }

---------------------------------------------------------------------------------------------------------------------------

//Staff.java package university; public class Staff extends Employee { protected String title; //Note: //Convert payrate to double from int public Staff(String first_name, String last_name, String phoneNumberber, double payRate, int payScale, String title) { super(first_name, last_name, phoneNumberber, payRate, payScale); this.title = title; } public void calculatePay() { monthlyPay = payRate / payScale; } public String toString() { return "Staff{" +"first_name=" + first_name +", last_name=" + last_name +", title=" + title +", monthlyPay=" + monthlyPay +'}'; } }

----------------------------------------------------

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

Microsoft Outlook 2023

Authors: James Holler

1st Edition

B0BP9P1VWJ, 979-8367217322

More Books

Students also viewed these Databases questions