Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Any help with the two methods below would be appreciated. 1) /** * Instantiate a

ID: 639726 • Letter: A

Question

Any help with the two methods below would be appreciated.

1)

/**
     * Instantiate a Main object and call run() on the object.
     */
    public static void main(String[] args) {
        Main mainObject = new Main();
        mainObject.run();
    }

    /**
     * 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) {

2)

/**
     * 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
     */
    private void writeFile(ArrayList pStudentList) throws FileNotFoundException {

Student Class

public abstract class Student implements Comparable<Student> {

    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;
    }

}

Explanation / Answer

Here you go :)

comment if you have any doubts.

//calcTuition method

private void calcTuition(ArrayList<Student> pStudentList)
   {
       for(Student eachStudent:pStudentList)
       {
           eachStudent.calcTuition();
       }
   }

//writeFile method


   private void writeFile(ArrayList<Student> pStudentList) throws FileNotFoundException
   {
       PrintWriter out=new PrintWriter(new File("p02-tuition.txt"));
       for(Student eachStudent:pStudentList)
       {
           out.print(eachStudent.getId()+" "+eachStudent.getLastName()+" "+eachStudent.getFirstName());
           out.printf("%.2f ",eachStudent.getTuition());
       }
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote