Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

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 pStudentList) { ??? }

/** * Reads the student information from "p02-students.txt" and returns the list of students as an ArrayList * object. * * PSEUDOCODE * Declare and create an ArrayList object named studentList. * Open "p02-students.txt" for reading using a Scanner object named in. * While in.hasNext() returns true Do * String studentType readFile() throws FileNotFoundException { ??? }

/** * 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 object named studentList * try * studentList = readFile() * calcTuition(studentList) * Call Sorter.insertionSort(studentList, Sorter.SORT_ASCENDING) to sort the list * writeFile(studentList) * catch FileNotFoundException * Print "Sorry, could not open 'p02-students.txt' for reading. Stopping." * Call System.exit(-1) */ private void run() { ArrayList studentList; try { studentList = readFile(); calcTuition(studentList); Sorter.insertionSort(studentList, Sorter.SORT_ASCENDING); writeFile(studentList); } catch (FileNotFoundException pExcept) { System.out.println("Sorry, could not open 'p02-students.txt' for reading. Stopping."); System.exit(-1); } }

/** * 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 pStudentList) throws FileNotFoundException { ??? } }

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 pList, int pOrder) { for (int i = 1; i

/** * Returns true if we need to continue moving the element at pIndex until it reaches its proper location. */ private static boolean keepMoving(ArrayList pList, int pIndex, int pOrder) { if (pIndex 0; }

/** * Swaps the elements in pList at pIndex1 and pIndex2. */ private static void swap(ArrayList pList, int pIndex1, int pIndex2) { Student temp = pList.get(pIndex1); pList.set(pIndex1, pList.get(pIndex2)); pList.set(pIndex2, temp); }

}

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;

}

image text in transcribed

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

IBM Db2 11 1 Certification Guide Explore Techniques To Master Database Programming And Administration Tasks In IBM Db2

Authors: Mohankumar Saraswatipura ,Robert Collins

1st Edition

1788626915, 978-1788626910

More Books

Students also viewed these Databases questions

Question

=+ Are these impediments deliberate?

Answered: 1 week ago