Question

Can someone please tell me what each line of this Java code does exactly? LINE BY...

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 + " ";
}
  
}

Homework Answers

Answer #1

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
}
  
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
What's wrong with this code? #Java Why I am getting error in : int BusCompare =...
What's wrong with this code? #Java Why I am getting error in : int BusCompare = o1.numberOfBusinesses.compareTo(o2.numberOfBusinesses); public class TypeComparator implements Comparator<Type> { @Override public int compare(Type o1, Type o2) { // return o1.name.compareTo(o2.name); int NameCompare = o1.name.compareTo(o2.name); int BusCompare = o1.numberOfBusinesses.compareTo(o2.numberOfBusinesses); // 2-level comparison using if-else block if (NameCompare == 0) { return ((BusCompare == 0) ? NameCompare : BusCompare); } else { return NameCompare; } } } public class Type implements Comparable<Type> { int id; String name; int...
Assignment 1 - ITSC 2214 I have to complete the array list for a shopping list...
Assignment 1 - ITSC 2214 I have to complete the array list for a shopping list code and can't figure out how to complete it: Below is the code Complete the three empty methods (remove(), find(), and contains()) in the ShoppingListArrayList.java file. These methods are already implemented in the ShoppingListArray class. /////////////////////////////////////////////////////////////////////////////////////////////////////////// Grocery Class (If this helps) package Shopping; public class Grocery implements Comparable<Grocery> { private String name; private String category; private int aisle; private float price; private int quantity;...
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
This is my course class. Can someone please explain what the equals method is for and...
This is my course class. Can someone please explain what the equals method is for and also the compareTo method is for in general and then explain what the methods are doing in this class. public class Course {    private boolean isGraduateCourse;    private int courseNum;    private String courseDept;    private int numCredits;       public Course(boolean isGraduateCourse, int courseNum, String courseDept, int numCredits) {        this.isGraduateCourse=isGraduateCourse;        this.courseNum=courseNum;        this.courseDept=courseDept;        this.numCredits=numCredits;   ...
Please show fully functioning java code and outputs. Design a Java Animal class (assuming in Animal.java...
Please show fully functioning java code and outputs. Design a Java Animal class (assuming in Animal.java file) and a sub class of Animal named Cat (assuming in Cat.java file).   The Animal class has the following protected instance variables: boolean vegetarian, String eatings, int numOfLegs and the following public instance methods: constructor without parameters: initialize all of the instance variables to some default values constructor with parameters: initialize all of the instance variables to the arguments SetAnimal: assign arguments to all...
How do I get this portion of my List Iterator code to work? This is a...
How do I get this portion of my List Iterator code to work? This is a portion of the code in the AddressBookApp that I need to work. Currently it stops at Person not found and if it makes it to the else it gives me this Exception in thread "main" java.lang.NullPointerException    at AddressBookApp.main(AddressBookApp.java:36) iter.reset(); Person findPerson = iter.findLastname("Duck"); if (findPerson == null) System.out.println("Person not found."); else findPerson.displayEntry(); findPerson = iter.findLastname("Duck"); if (findPerson == null) { System.out.println("Person not found.");...
Please explain code 1 and code 2 for each lines code 1 public class MyQueue {...
Please explain code 1 and code 2 for each lines code 1 public class MyQueue {    public static final int DEFAULT_SIZE = 10;    private Object data[];    private int index; code 2 package test; import java.util.*; /* Class Node */ class Node { protected Object data; protected Node link; /* Constructor */ public Node() { link = null; data = 0; } /* Constructor */ public Node(Object d,Node n) { data = d; link = n; } /*...
Sort by the following (name, address, dependent and gender) of these and ask the user which...
Sort by the following (name, address, dependent and gender) of these and ask the user which field to sort by !. this mean the following java must sort by address if we need, by name , by dependent , and by gender it depend on the following java it must have an option which we need to sort. please i need your help now, you just add the sorting on the following java. // Use a custom comparator. import java.io.BufferedReader;...
Java: ModifyStudentList.javato use anArrayListinstead of an array In StudentList.java, create two new public methods: The addStudent...
Java: ModifyStudentList.javato use anArrayListinstead of an array In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and should add the given Student to the StudentList. The removeStudent method should have one parameter of type String. The String is the email of the student to be removed from the StudentList. In Assign5Test.java do the following: Create a new StudentList containing 3 students. Print the info of all the Students in the StudentList using...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT