Question: Java Program: The sample solution to Exercise #5, CalculateFacultyPay3.java, is an object-oriented program and calculates the pay for each faculty member based on 2 input

Java Program:

The sample solution to Exercise #5, CalculateFacultyPay3.java, is an object-oriented program and calculates the pay for each faculty member based on 2 input data files: facultyInfo.cvs and courseInfo.csv

Faculty will also receive a $200 bonus for each course that has more than 15 students enrolled. The enrollment information is saved in the file enrollment.csv which contains 2 fields in each record:

courseID, enrollment

Sample records in enrollment.csv :

CIS106-1 18
CIS107-3 12
CIS203-HYB1 19
CIS228-HYB2 15
CIS107-1 8
CIS201-HYB1 11
CIS208-HYB1 21
CIS176-HYB1 12
CIS227-3 16
CIS179-ONL1 17
CIS180-ONL1 9

Sample Records in courseinfo.csv:

1234567 3 CIS106-1 Object Design & Programming
1176277 2 CIS107-3 Introduction to Programming
1133107 3 CIS203-HYB1 Systems Analysis & Design
1176277 3 CIS228-HYB2 Simulation & Game Development
1133107 2 CIS107-1 Introduction to Programming
1133107 4

CIS201-HYB1

Computer Science I

Sample Records in facultyinfo.csv:

1234567 Ava Smith 750
1176277 John Jones 812
1133107 Jimmy Loveone 787
1098210 Kimberly Richone 802

Please develop a program to calculate the faculty pay, including the bonus.

You are NOT allowed to modify FacultyRec class or CourseRec class. You are required to create a subclassfrom CourseRec in order to capture the enrollment information.

3 Input data files:

facultyInfo.csv

courseInfo.csv

enrollment.csv

The number of records in each input data file is unknown.

I use JGRASP so it must be in one java file.

CalculateFacultyPay3.java:

/** Begin Open faculty data file for reading Read faculty records into list Open course data file for reading Read course records into list Loop Get 1 faculty object from faculty list Loop Get 1 course object from course list A mtach on faculty ID? ask the faculty object to add the current course End Loop End Loop Loop Ask each faculty object to show the pay End Loop End Input data files: facultyInfo.csv and courseInfo.csv **/ import java.io.*; import java.util.*; public class CalculateFacultyPay3 { public static void main(String args[]) { String line; StringTokenizer st; ArrayList instructors = new ArrayList (); ArrayList courses = new ArrayList (); try { BufferedReader inFile = new BufferedReader(new FileReader("facultyInfo.csv")); while ((line = inFile.readLine()) != null) instructors.add(new FacultyRec(line.trim())); inFile.close(); } catch (Exception e) { e.printStackTrace(); } try { BufferedReader inFile = new BufferedReader(new FileReader("courseInfo.csv")); while ((line = inFile.readLine()) != null) courses.add(new CourseRec(line.trim())); inFile.close(); } catch (Exception e) { e.printStackTrace(); } for (FacultyRec f : instructors) for (CourseRec c : courses) if (f.getID().equals(c.getFacultyID())) f.add(c); for (FacultyRec f : instructors) f.showPay(); } // main } // CalculateFacultyPay3 class FacultyRec { String ID, firstName, lastName; double payRate; StringTokenizer st; java.util.ArrayList courses; public FacultyRec() { courses = new ArrayList (); } public FacultyRec(String r) { st = new StringTokenizer(r.trim(), ","); ID = st.nextToken(",").trim(); firstName = st.nextToken(","); lastName = st.nextToken(",").trim(); payRate = new Double(st.nextToken(",").trim()).doubleValue(); courses = new ArrayList (); } public void showPay() { int creditCount = 0; for (CourseRec c : courses) creditCount = creditCount + c.getCredit(); System.out.print(firstName + " " + lastName + " $"); System.out.println(payRate * creditCount); } public void add(CourseRec c) { courses.add(c); } public double getPayRate() { return payRate; } public String getID() { return ID; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public void setPayRate(double p) { payRate = p; } public String toString() { return firstName + " " + lastName; } } // Faculty class CourseRec { int credit; String facultyID, courseID, title; StringTokenizer st; public CourseRec() { courseID = null; title = null; credit =0; } public CourseRec(String r) { st = new StringTokenizer(r.trim(), ","); facultyID = st.nextToken(",").trim(); credit = new Integer(st.nextToken(",").trim()).intValue(); courseID = st.nextToken(",").trim(); title = st.nextToken(",").trim(); } public String getFacultyID () { return facultyID; } public int getCredit() { return credit; } public String getCourseID() { return courseID; } public String getTitle() { return title; } public void setFacultyID (String f) { facultyID = f; } public void setCredit(int c) { credit = c; } public String toString() { return courseID + " " + title; } } // Course 

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!