Fix these codes in order to get the following output:Code:public class 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 methodspublic 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.javaimport java.util.*;public class Main{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 inputString name;String dept;int number;courses[0]=new Course();courses[1]=new Course();courses[2]=new Course();for(int i = 0; i < 3;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 functionsfor(int i = 0; i < 3;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 DeptCSEnter room number204Enter Course nameCPS 2231Enter DeptCSEnter room number220Enter Course nameCPS 2232Enter DeptCSEnter room number204Enter Course nameCPS 2232Printing the coursesCourse Name: CPS 1231 Dept: CS CourseNumber: 1000 Room 204Course Name: CPS 2231 Dept: CS CourseNumber: 1001 Room 220Course Name: CPS 2232 Dept: CS CourseNumber: 1002 Room 204

Question
Asked Oct 12, 2019
285 views

Fix these codes in order to get the following output:

Code:

public class 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 Main

{

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 < 3;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 < 3;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

check_circle

Expert Answer

Step 1

Revised code is as follows:

import java.util.Scanner; //importing packages.

// declaring class

class Course {

 //declaring class members.

 private static int count = 1000;

 private String dept_code;

 private String course_name;

 private int course_number;

 private int room_number;

 //parameterized constructor

 public Course(String dept_code, String course_name, int room_number) {

  this.dept_code = dept_code;

  this.course_name = course_name;

  this.course_number = count;

  this.room_number = room_number;

  count++;

 }

 //implementing setters method for dept_code

 public void setDept_code(String dept_code) {

  this.dept_code = dept_code;

 }

 //implementing setters method for course_name

 public void setcourse_name(String course_name) {

  this.course_name = course_name;

 }

 //implementing setters method for course_number

 public void setCourse_number(int course_number) {

  this.course_number = course_number;

 }

 //implementing setters method for room_number

 public void setroom_number(int room_number) {

  this.room_number = room_number;

 }

 //implementing getters method for dept_code

 public String getDept_code() {

  return dept_code;

 }

 //implementing getters method for course_name

 public String getcourse_name() {

  return course_name;

 }

 //implementing getters method for course_number

 public int getCourse_number() {

  return course_number;

 }

 //implementing getters method for room_number

 public int getroom_number() {

  return room_number;

 }

 //display method to display the result

 void display() {

  System.out.println("CourseName: " + course_name + " Department: " + dept_code + " CourseNumber: " + course_number + " Room " + room_number + ".");

 }

 

Step 2

//main class

public class Main {

 public static void main(String[] args) {

  Course[] courses = new Course[3];

  Scanner sc = new Scanner(System.in);

  int counter = 0;

  while (counter < 3) {

   System.out.print("Enter Depertment for course " + (counter + 1) + ": ");

   String dept_code = sc.next();

   System.out.print("Enter Room Number for course " + (counter + 1) + ": ");

   int room_number = Integer.parseInt(sc.next());

   System.out.print("Enter Course Name fo...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Engineering

Programing

Related Computer Engineering Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Do you think technologies like Big Data and Predictive Analytics in Marketing would have worked 10-1...

A: The technologies like Big Data would not have worked 10-15 years back as due to lack of large datase...

question_answer

Q: Write a program called KiloToPoundTable that prints the below table. Useprintf()and while statement....

A: A constant is defined for holding the conversion factor. printf function is used to format the print...

question_answer

Q: Assume that a firm has already implemented a KMS system, as a manager, how do you ensure that learni...

A: The given case study describes the internal knowledge assets of the organization and details about t...

question_answer

Q: How do you code?

A: For coding one needs to focus on the following points:Selecting a programming language: First, selec...

question_answer

Q: Match the following 1) BRANCHING 2) AIRTHMATIC 3) DATA TRANSFER 4) CONTROL TRANSFER Note: Instructio...

A: TRAP:TRAP instruction changes the program counter to an operating system “service routine”.When TRAP...

question_answer

Q: this question is from fundamentals of logic. related to boolean algebra. I am unable to decipher the...

A: Click to see the answer

question_answer

Q: The following print code is to find out the ASCII code, character for the decimal codes,and comparis...

A: Reasons for displaying given output for each line of code: For “System.out.println((int)'1');”: From...

question_answer

Q: Hello, I am trying to write a program: Write a .py file like MainFiles.py In that .py, create a func...

A: A python file is created named as MainFiles.py:Def main( ):Print(“ Welcome to python”)The above pyth...

question_answer

Q: 2) Identify the errors in the following programs a) 3 errorspublic class Test {public static void ma...

A: Hey, since there are multiple questions posted, we will answer first question. If you want any speci...