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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started