Fix these codes in order to get the following output:
Code:
public class rinoel_Course
{
private String course_name;
public static int count=1000;
public int course_number;
private String dept_code;
private int room_number;
public Course()
{
course_name="";
dept_code="";
room_number=0;
//System.out.println(""+course_number);
course_number=count++;
}
public void set_course_name(String name)
{
course_name=name;
}
public void set_dept_code(String code)
{
dept_code=code;
}
public void set_room_number(int no)
{
room_number=no;
}
//getter methods
public String get_course_name()
{
return course_name;
}
public String get_dept_code()
{
return dept_code;
}
public int get_room_number()
{
return room_number;
}
public int get_course_number()
{
return course_number;
}
void display()
{
System.out.println(""+course_number+" "+dept_code+" "+course_name+" "+room_number);
}
}
---------------------------------------
//main.java
import java.util.*;
public class rinoel_TestCourse
{
public static void main(String[] args) {
//System.out.println("Hello World");
Course []courses=new Course[3];
Course cor=new Course();
Scanner sc=new Scanner(System.in);
//ask user input
String name;
String dept;
int number;
courses[0]=new Course();
courses[1]=new Course();
courses[2]=new Course();
for(int i = 0; i <>
{
System.out.println("Enter the course Name: ");
name=sc.next();
//System.out.println(""+name);
courses[i].set_course_name(name);
System.out.println("Enter department: ");
dept=sc.next();
courses[i].set_dept_code(name);
System.out.println("Enter the room Number: ");
number=sc.nextInt();
courses[i].set_room_number(number);
//System.out.println(""+courses[i].course_number+" "+courses[i].get_dept_code()+" "+courses[i].get_course_name()+" "+courses[i].get_room_number());
}
//getter functions
for(int i = 0; i <>
{
courses[i].display();
//System.out.println(""+courses[i].course_number+" "+courses[i].get_dept_code()+" "+courses[i].get_course_name()+" "+courses[i].get_room_number());
}
}
}
Output:
Enter Dept
CS
Enter room number
204
Enter Course name
CPS 2231
Enter Dept
CS
Enter room number
220
Enter Course name
CPS 2232
Enter Dept
CS
Enter room number
204
Enter Course name
CPS 2232
Printing the courses
Course Name: CPS 1231 Dept: CS CourseNumber: 1000 Room 204
Course Name: CPS 2231 Dept: CS CourseNumber: 1001 Room 220
Course Name: CPS 2232 Dept: CS CourseNumber: 1002 Room 204