Question
I have a decently sized project to complete, but I'm having a really hard time completing it. I would greatly appreciate any help on this.
I have a decently sized project to complete, but I'm having a really hard time completing it. I would greatly appreciate any help on this. I have some code that I've gotten started with, posted below.
CODE I HAVE SO FAR:
MAIN
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Scanner;
public class Main {
/** * Instantiate a Main object and call run() on the object. */ public static void main(String[] args) { ??? }
/** * Calculates the tuition for each student. Write an enhanced for loop that iterates over each Student in * pStudentList. For each Student, call calcTuition() on that Student. Note: this is a polymorphic method * call. * * PSEUDOCODE * EnhancedFor each student in pStudentList Do * student.calcTuition() * End EnhancedFor */ private void calcTuition(ArrayList
/** * Reads the student information from "p02-students.txt" and returns the list of students as an ArrayList *
/** * Reads the information for an on-campus student. * * PSEUDOCODE * Declare String object id and assign pIn.next() to id * Declare String object named lname and assign pIn.next() to lname * Declare String object named fname and assign pIn.next() to fname * Declare and create an OnCampusStudent object. Pass id, fname, and lname as params to ctor. * Declare String object named res and assign pIn.next() to res * Declare double variable named fee and assign pIn.nextDouble() to fee * Declare int variable named credits and assign pIn.nextInt() to credits * If res.equals("R") Then * Call setResidency(true) on student * Else * Call setResidency(false) on student * End If * Call setProgramFee(fee) on student * Call setCredits(credits) on student * Return student */ private OnCampusStudent readOnCampusStudent(Scanner pIn) { String id = pIn.next(); String lname = pIn.next(); String fname = pIn.next(); OnCampusStudent student = new OnCampusStudent(id, fname, lname); String res = pIn.next(); double fee = pIn.nextDouble(); int credits = pIn.nextInt(); student.setResidency(res.equals("R")); student.setProgramFee(fee); student.setCredits(credits); return student; }
/** * Reads the information for an online student. * * PSEUDOCODE * Declare String object id and assign pIn.next() to id * Declare String object named lname and assign pIn.next() to lname * Declare String object named fname and assign pIn.next() to fname * Declare and create an OnlineStudent object. Pass id, fname, lname as params to the ctor., * Declare String object named fee and assign pIn.next() to fee * Declare int variable named credits and assign pIn.nextInt() to credits * If fee.equals("T")) Then * Call setTechFee(true) on student * Else * Call setTechFee(false) on student * End If * Call setCredits(credits) on student * Return student */ private OnlineStudent readOnlineStudent(Scanner pIn) { ??? }
/** * Calls other methods to implement the sw requirements. * * PSEUDOCODE * Declare ArrayList
/** * Writes the output file to "p02-tuition.txt" per the software requirements. * * PSEUDOCODE * Declare and create a PrintWriter object named out. Open "p02-tuition.txt" for writing. * EnhancedFor each student in pStudentList Do * out.print(student id + " " + student last name + " " + student first name) * out.printf("%.2f%n" student tuition) * End EnhancedFor * Close the output file */ private void writeFile(ArrayList
SORTER
import java.util.ArrayList;
public class Sorter {
public static final int SORT_ASCENDING = 0; public static final int SORT_DESCENDING = 1;
/** * Sorts pList into ascending (pOrder = SORT_ASCENDING) or descending (pOrder = SORT_DESCENDING) order * using the insertion sort algorithm. */ public static void insertionSort(ArrayList /** * Returns true if we need to continue moving the element at pIndex until it reaches its proper location. */ private static boolean keepMoving(ArrayList /** * Swaps the elements in pList at pIndex1 and pIndex2. */ private static void swap(ArrayList } STUDENT public abstract class Student implements Comparable private int mCredits; private String mFname; private String mId; private String mLname; private double mTuition; /** * Creates a Student object and initializes the mId, mFname, and mLname instance variables. */ public Student(String pId, String pFname, String pLname) { setId(pId); setFirstName(pFname); setLastName(pLname); } /** * calcTuition() is to be implemented by subclasses of Student. */ public abstract void calcTuition(); /** * The Comparable interface declares one method compareTo() that must be implemented. This * method is called from Sorter.keepMoving() to compare the mId fields of two Students. * * Compares the mId fields of this Student and pStudent. Returns -1 if this Student's mId * field is less than pStudent's mId field. Returns 0 if this Student's mId field is equal to * pStudent's mId field. Returns 1 if this Student's mId field is greater than pStudent's mId * field. The compareTo */ @Override public int compareTo(Student pStudent) { return getId().compareTo(pStudent.getId()); } /** * Accessor method for mCredits. */ public int getCredits() { return mCredits; } /** * Accessor method for mFname. */ public String getFirstName() { return mFname; } /** * Accessor method for mId. */ public String getId() { return mId; } /** * Accessor method for mLname. */ public String getLastName() { return mLname; } /** * Accessor method for mTuition. */ public double getTuition() { return mTuition; } /** * Mutator method for mCredits. */ public void setCredits(int pCredits) { mCredits = pCredits; } /** * Mutator method for mFname. */ public void setFirstName(String pFname) { mFname = pFname; } /** * Mutator method for mId. */ public void setId(String pId) { mId = pId; } /** * Mutator method for mLname. */ public void setLastName(String pLname) { mLname = pLname; } /** * Mutator method for mTuition. */ protected void setTuition(double pTuition) { mTuition = pTuition; } } TUITION CONSTANTS public class TuitionConstants { public static final int ONCAMP_ADD_CREDITS = 350; public static final int MAX_CREDITS = 18; public static final int ONCAMP_NONRES_BASE = 12200; public static final int ONCAMP_RES_BASE = 5500; public static final int ONLINE_CREDIT_RATE = 875; public static final int ONLINE_TECH_FEE = 125; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started