Class for course information Here's what the question asks:


  Build a class called Course.java. This class should have 4 properties: CourseId, CourseName, Description, and credit hours. Also add the appropriate set and get methods. Add a display() method to display these 4 properties out to the DOS window. Lastly add a main() method for testing. In the main() method instantiate a Course object, fill it with data using the set methods, then call the display method to display the data.


I just want to make sure is my code right and if there are mistake in my code.

public class Course {

//   ========================== Properties ===========================
private int courseid;
private String courseName;
private String description;
private String creditHours;

//   ==========================  Behaviors  ==========================
public void setCourseId(int c) { courseid = c; }
public int getCourseId() { return courseid;}

public void setCourseName(String cn) { courseName = cn; }
public String getCourseName() { return courseName;}

public void setDescription(String d) { description = d; }
public String getDescription() { return description;}

public void setCreditHours(int ch) { ch = 4; }
public int getCreditHours() { return ch;}

//Returning String
public String toString() {
    return courseName + ":" + description + ":" + creditHours;
}

public void display() {
    System.out.println("Course ID             = " + getCourseId());
    System.out.println("Course Name      = " + getCourseName());
    System.out.println("Description      = " + getDescription());
    System.out.println("Credit Hours           = " + getCreditHours());

} //end display()





public static void main(String args []) {

    Course c1;
    c1 = new Course();

    c1.setCourseId(109);
    c1.setCourseName("Intro to Python");
    c1.setDescription("This course intros the Python Prog Lang.");
    c1.setCreditHours(4);

    c1.display();


    //Test out toString() method
    System.out.println(c1);
} //end main
} //end class
Here's the list of things I would change:


Indentation (make it 2 or 4 tabs) 
Field naming is inconsistent. For example, courseid should be changed to courseId. Secondly, you should append the prefix course to all fields, or omit it at all. (Don't forget to change your methods as well).
Assuming that this is a POJO (Plain Old Java Object) class, then I would recommend removing the display() method from this class. It's simply not its responsibility to display itself(S from SOLID principles). Instead, you can modify your toString() method to look something like this:


`

public String toString() {
   return "Course ID:" + id + '\n' +
            "Course name:" + name + '\n' +
            "Course description:" + description + '\n' +
            "Credit hours:" + creditHours + '\n';
}


`
And then use it in a different object/function whose responsibility is to present information to the user. 


From my personal experience, I can say that the id field should be a String. If you are getting data from a server, and then convert that data to a POJO, the id field may cause an overflow in some situations if it's an integer. Even longdata type may cause an overflow if the id value is very long. 
I don't think it's a professional way to declare and initialize an instance of a class the way it was written. You can do both in a single line.


This is how I would have written it:

public class Course {

  private String id;
  private String name;
  private String description;
  private float creditHours;

  public void setId(String id) {
     this.id = id;
  }

  public String getId() {
     return id;
  }

  public String getName() {
     return name;
  }

  public void setCreditHours(float creditHours) {
     this.creditHours = creditHours;
  }

  public void setName(String name) {
     this.name = name;
  }

  public void setDescription(String description) {
     this.description = description;
  }

  public String getDescription() {
     return description;
  }


  public String toString() {
     return "Course ID:" + id + '\n' +
            "Course name:" + name + '\n' +
            "Course description:" + description + '\n' +
            "Credit hours:" + creditHours + '\n';
  }

  public static void main(String args[]) {
    final Course course = new Course();
    course.setCreditHours(15.6f);
    course.setDescription("BlaBla");
    course.setId("12345567878665345453123");
    course.setName("Just a boring class");

    System.out.print(course.getDescription());
  }
}


It contains some other corrections as well.

Hope this helps!

As a side note, though it seems absolutely superfluous, I would like you to know that's it's not my intention to criticize your code, I'm simply expressing my opinion based on the experience I have.