Can someone please tell me what each line of this Java code does exactly? LINE BY LINE PLEASE!!!
package p2;
public class Course {
// class fields
private String code; // course code, such as "EE333"
private String name; // course name, such as "Engineering
Programming w/ Objects"
public Note notes[]; // attached note of a course
private int noteSize; // size of the note by lines
// construct a Course with a code and a name, i.e. a course
constructor
public Course(String code, String name) {
this.code = code;
this.name = name;
notes = new Note[5];
noteSize = 0;
}
// get and return the course code
public String getCode() {
return code;
}
// add note method
public void add(Note note) {
if (noteSize < 5)
notes[noteSize++] = note;
}
// get and return the course name
public String getName() {
return name;
}
// get and return the size of the note
public int getCount() {
return noteSize;
}
// get and return the i'th line of the note
public Note get(int i) {
if (i < notes.length)
return notes[i];
else
return null;
}
// create a string of the course name and course code
@Override
public String toString() {
return code + ": " + name + " ";
}
}
public class Course {
// class fields
private String code; //Declares a variable for storing the code of
the course
private String name; //Declares a variable for storing the name of
the course
public Note notes[]; //Declares a array for storing the one or more
notes for a particular course
private int noteSize; //Declares a variable for storing the size of
notes made
// construct a Course with a code and a name, i.e. a course
constructor
public Course(String code, String name) {
this.code = code;
//Initialises a variable for storing the code of
the course
this.name = name;
//Initialises a variable for storing the name of
the course
notes = new Note[5];
//Initialises a array for storing the one or
more notes for a particular course
noteSize = 0;
//Initialises a variable for
storing the size of notes made
}
public String getCode() {
return code;
// get and return the course code
}
public void add(Note note) {
if (noteSize < 5)
// add note in the array if
number of enteries is less than 5
notes[noteSize++] = note;
}
public String getName() {
return name;
// get and
return the course name
}
public int getCount() {
return noteSize;
// get and return the size of the note
}
public Note get(int i) {
if (i < notes.length)
// get and
return the i'th line of the note
return notes[i];
else
return null;
}
@Override
public String toString() {
return code + ": " + name + " ";
// create a string of the
course name and course code
}
}
Get Answers For Free
Most questions answered within 1 hours.