Question: JAVA QUESTION. 58. Write a class encapsulating the concept of a course, assuming a course has the following attributes: a code (for instance, CSI), a

JAVA QUESTION.

58. Write a class encapsulating the concept of a course, assuming a course has the following attributes: a code (for instance, CSI), a description, and a number of credits ( for instance, 3). Include a constructor, the accessor and mutator, and methods toString and equals. Write a client class to test all the methods in your class. BELOW IS THE CLIENT AND I NEED A TEST CLASS!

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" );

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!