Java Program 3 making a printlogger and adding another class
Java Program 3 (making a printlogger and adding another class to existing project)
Here are the classes \"Course\" and \"Note\"
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 + \" \";
 }
   
 }
*****************************************************************
package p2;
public class Note {
   
 // class fields
 private String title; // title of note
 private String lines[]; // contents of a note, line by line
 private int UID; // UID of note (starts at 10000)
 private int lineSize; // size of a line within a note
 private static int count; // i\'th line of the note
   
 // construct a note with a title
 public Note(String title) {
 this.title = title;
 this.UID = count++;
 lines = new String[10];
 lineSize = 0;
 }
   
 // delete line method
 public void delete(int i) {
 if (i < 10) {
 lines[i] = \"\";
 lineSize--;
 }
 }
   
 // append string method
 public void append(String line) {
 if (lineSize < 10) {
 lines[lineSize++] = line;
 }
 }
   
 public void setTitle(String newTitle) {
 this.title = newTitle;
 }
public int getUID() {
 return UID;
 }
   
 public String getTitle() {
 return title;
 }
 
 public int getCount() {
 return lineSize;
 }
 
 public String getLine(int i) {
 if(i<lineSize)
 return lines[i];
 else
 return \"\";
 }
 
 @Override
 public String toString() {
 return \"Note \" + UID + \": \" + title;
 }
 }
Solution
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 + \" \";
 }
   
 }
*****************************************************************
package p2;
public class Note {
   
 // class fields
 private String title; // title of note
 private String lines[]; // contents of a note, line by line
 private int UID; // UID of note (starts at 10000)
 private int lineSize; // size of a line within a note
 private static int count; // i\'th line of the note
   
 // construct a note with a title
 public Note(String title) {
 this.title = title;
 this.UID = count++;
 lines = new String[10];
 lineSize = 0;
 }
   
 // delete line method
 public void delete(int i) {
 if (i < 10) {
 lines[i] = \"\";
 lineSize--;
 }
 }
   
 // append string method
 public void append(String line) {
 if (lineSize < 10) {
 lines[lineSize++] = line;
 }
 }
   
 public void setTitle(String newTitle) {
 this.title = newTitle;
 }
public int getUID() {
 return UID;
 }
   
 public String getTitle() {
 return title;
 }
 
 public int getCount() {
 return lineSize;
 }
 
 public String getLine(int i) {
 if(i<lineSize)
 return lines[i];
 else
 return \"\";
 }
 
 @Override
 public String toString() {
 return \"Note \" + UID + \": \" + title;
 }
 }





