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

Java; please dont use @Override, and comment as much as you can, thanks. write a

ID: 3594093 • Letter: J

Question

Java; please dont use @Override, and comment as much as you can, thanks.

write a service class called Course that implements a concept of a course and has the following defined:

three fields: a code (which must be one of "CS1", "CS2", "CS3" or "CS4"), a description (String), and a number of credits as int (for example 3).

default constructor

secondary constructor

accessor methods for each field

mutator methods for each field

toString method

equals method

a "business" method called level, that returns either 1,2,3, or 4 based on the value of code

write a client class called CourseClient. The client class has a main method that should call all the methods defined in the Course class to make sure that they work properly. Please remember to use thiskeyword where appropriate. Submit both classes for grading.

Explanation / Answer

Course.java

public class Course {

private String code;

private String description;

private int credits;

public Course(String c, String d, int cr){

code = c;

description = d;

credits = cr;

}

public int business() {

if(code.equalsIgnoreCase("CS1")) {

return 1;

} else if(code.equalsIgnoreCase("CS2")) {

return 2;

} else if(code.equalsIgnoreCase("CS3")) {

return 3;

} else {

return 4;

}

}

public String getCode() {

return code;

}

public void setCode(String code) {

this.code = code;

}

public String getDescription() {

return description;

}

public void setDescription(String description) {

this.description = description;

}

public int getCredits() {

return credits;

}

public void setCredits(int credits) {

this.credits = credits;

}

public String toString(){

return "code is "+code+" description is "+description+" credits is "+credits;

}

public boolean equals(Course c){

if(this.code == c.code && this.description==c.description && this.credits==c.credits){

return true;

}

else{

return false;

}

}

}

CourseClient.java


public class CourseClient
{
public static void main( String [] args )
{
Course c1 = new Course( "CS1", "Intro to Computer Science", 4 );
Course c2 = new Course( "CS2", "Intro to Data Structures", 3 );
System.out.println( "The code of course # 1 is " + c1.getCode( ) );
System.out.println( "The description of course # 1 is " + c1.getDescription( ) );
System.out.println( "The number of credits of course # 1 is " + c1.getCredits( ) );
System.out.println( "Course # 2 is " + c2.toString( ) );
if ( c1.equals( c2 ) )
System.out.println( "Original courses #1 and #2 are identical" );
else
System.out.println( "Original courses #1 and #2 are different" );
c2.setCode( "CS1" );
c2.setDescription( "Intro to Computer Science" );
c2.setCredits( 4 );
if ( c1.equals( c2 ) )
System.out.println( "Original course #1 and modified course #2 are identical" );
else
System.out.println( "Original course #1 and modified course #2 are different" );
System.out.println(c1.business());
System.out.println(c2.business());
}
}

Output:

The code of course # 1 is CS1
The description of course # 1 is Intro to Computer Science
The number of credits of course # 1 is 4
Course # 2 is code is CS2 description is Intro to Data Structures credits is 3
Original courses #1 and #2 are different
Original course #1 and modified course #2 are identical
1
1

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