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

Homework 1: Write a program using OOP in Java to contain the following methods.

ID: 3742977 • Letter: H

Question

Homework 1:

Write a program using OOP in Java to contain the following methods.

Use proper constructor and instantiate different object to use the specified, methods. The program must be interactive. A method called “displayCourse” which displays the name of CS courses offered in Loudoun. (CS200..)

Set Coursename()

Display Course time()

Display Course name()

Hint: Course info a=new courseInfo()

a.displayCourseTime(name, …)

Extra info:

CSC110 Introduction Computing - M 07:00P - 09:55P || F 09:30A - 12:10P

CSC200 Introduction to Computer Science - MW 09:30A - 11:20A || MW 02:00P - 03:50P || TR 09:30A - 11:20A || TR 12:30P - 02:20P || TR 07:00P - 08:50P || S 09:30A - 01:10P

CSC201 Computer Science 1 - MW 09:30A - 11:20A || S 09:30A - 01:10P

CSC202 Computer Science 2 - MW 09:30A - 11:20A || S 09:30A - 01:10P

CSC205 Computer Organization - R 07:00P - 09:40P

Explanation / Answer

/**

* The java test program that instantiates the object of the Coursename

* class and set the course name and time using the setter methods

* and then call the displayCourseTime to print to console.

* */

//TestCourseName.java

public class TestCourseName {

public static void main(String[] args) {

Coursename c1=new Coursename("CSC110 Introduction Computing",

"M 07:00P - 09:55P || F 09:30A - 12:10P");

c1.displayCourseTime();

//Modify the name and time

c1.setName("CSC200 Introduction to Computer Science");

c1.setTime("MW 09:30A - 11:20A || MW 02:00P - 03:50P || TR 09:30A - 11:20A || TR 12:30P - 02:20P || TR 07:00P - 08:50P || S 09:30A - 01:10P");

//display course info

c1.displayCourseTime();

c1.setName("CSC201 Computer Science 1");

c1.setTime("MW 09:30A - 11:20A || S 09:30A - 01:10P");

c1.displayCourseTime();

c1.setName("CSC202 Computer Science 2");

c1.setTime("MW 09:30A - 11:20A || S 09:30A - 01:10P");

c1.displayCourseTime();

c1.setName("CSC205 Computer Organization");

c1.setTime("R 07:00P - 09:40P");

c1.displayCourseTime();

}

}

----------------------------------------------------------------------------------------

//Coursename.java

public class Coursename {

//private data members

private String name;

private String time;

public Coursename() {

name="NA";

time="NA";

}

//Constructor that takes name and time

public Coursename(String name,String time) {

setName(name);

setTime(time);

}

//Set name

public void setName(String name) {

this.name=name;

}

//Set time

public void setTime(String time) {

this.time=time;

}

//Print name and time

public void displayCourseTime() {

System.out.printf("%-30s%-30s ",name,time);

}

}

----------------------------------------------------------------------------------------

Sample Output:

CSC110 Introduction Computing M 07:00P - 09:55P || F 09:30A - 12:10P
CSC200 Introduction to Computer ScienceMW 09:30A - 11:20A || MW 02:00P - 03:50P || TR 09:30A - 11:20A || TR 12:30P - 02:20P || TR 07:00P - 08:50P || S 09:30A - 01:10P
CSC201 Computer Science 1 MW 09:30A - 11:20A || S 09:30A - 01:10P
CSC202 Computer Science 2 MW 09:30A - 11:20A || S 09:30A - 01:10P
CSC205 Computer Organization R 07:00P - 09:40P