Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi guys I need help with this assignment... I have to make changes to this code. Would really appreciate it if someone can help me

Hi guys I need help with this assignment... I have to make changes to this code. Would really appreciate it if someone can help me out... The instructions are as follows ->

1: In the constructor, as well as in the setLetterGrade method, when the grade parameter is A, B, C, D, or F, use it to set the letterGrade instance variable. Otherwise, throw an IllegalArgumentException. The message for the exception would be: "Invalid value for the letter grade.

2: Make the class implement the Comparable interface.

3: Provide an implementation for the compareTo method such that it compares the value of the courseTaken variable. If both objects have the same value, it returns 0; if the courseTaken variable of the calling object is greater, it returns a positive number; else it returns a negative number.

package acadadminsystem_phase1;

public class CourseGrade { // instance variables private Course courseTaken; private String letterGrade; /** * This constructor initializes the fields to the passed values. * @param course Course number. * @param grade Grade received. */ public CourseGrade(Course course, String grade) { courseTaken = course; letterGrade = grade; } /** * This is a copy constructor. It initializes the fields of the object being created to the same * values as the fields in the object passed as an argument. * @param courseGradeObj The object being copied. */ public CourseGrade(CourseGrade courseGradeObj) { if( courseGradeObj != null ) { courseTaken = courseGradeObj.courseTaken; letterGrade = courseGradeObj.letterGrade; } } /** * The getCourseTaken method returns the course that the student has taken. * @return A copy of the course object. */ public Course getCourseTaken() { return courseTaken; } /** * The getLetterGrade method returns the grade received for a course. * @return The value in the letterGrade field. */ public String getLetterGrade() { return letterGrade; } /** * The setCourseTaken method stores a value in the courseTaken field. * @param course the new Course object to store in courseTaken. */ public void setCourseTaken(Course course) { courseTaken = course; } /** * The setLetterGrade method stores a value in the letterGrade field. * @param grade the value to store in letterGrade. */ public void setLetterGrade(String grade) { letterGrade = grade; } /** * The toString method returns a string representing the state of a CourseGrade object. * @return A string containing the information for the course that has been taken: course info, * and grade received. */ @Override public String toString() { return String.format("%s %-30s %s", courseTaken, "Grade Received:", letterGrade); } /** * The equals method compares two CourseGrade objects. The result is true if the argument * is not null and is a CourseGrade object with the same course and grade as the calling * object. * @param obj The object to compare this CourseGrade with. * @return true if the given object has the same value for the courseTaken and letterGrade * fields. */ @Override public boolean equals(Object obj) { // check that the type of the parameter is CourseGrade if( !(obj instanceof CourseGrade) ) return false; // we already know that obj is of type CourseGrade, so it's safe to cast CourseGrade courseGradeObj = (CourseGrade) obj; // return true or false depending on whether courseTaken and letterGrade have the same value return courseGradeObj.courseTaken.equals(this.courseTaken) && courseGradeObj.letterGrade.equals(this.letterGrade); } public int compareTo(CourseGrade courseGrade) { } }

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

DB2 9 For Linux UNIX And Windows Advanced Database Administration Certification Certification Study Guide

Authors: Roger E. Sanders, Dwaine R Snow

1st Edition

1583470808, 978-1583470800

More Books

Students also viewed these Databases questions

Question

Prepare an employment application.

Answered: 1 week ago

Question

=+ 9. What is inflation and what causes it?

Answered: 1 week ago

Question

=+6. What does the invisible hand of the marketplace do?

Answered: 1 week ago