EE333 P2 Task Model Course(s) for LMS Over P2-P5, we will build a object oriente
ID: 3783877 • Letter: E
Question
EE333 P2 Task Model Course(s) for LMS Over P2-P5, we will build a object oriented model of parts of a Learning Management System to learn object oriented modeling and implementation as wel as build parts of a system to model a course. We will start with two objects: course and notes. We also start testing to validate the quality of our implementation developingevidence of correct operation. Background on course Courses consist of meta-data (things about a course) and then lecture content, notes, pages, media, assignments, etc. The UML diagram describing these first two classes is given as Figure 1. getTite setTite(new Tite) appendine) Figure 1. P2 UML Class DiagramExplanation / Answer
PROGRAM CODE:
Note.java
package simple;
public class Note {
private String title;
private String lines[];
private int UID;
private int lineSize;
private static int counter = 10000;
public Note(String title)
{
this.title = title;
this.UID = counter++;
lines = new String[10];
lineSize = 0;
}
public void delete(int i)
{
if(i<10)
{
lines[i] = "";
lineSize--;
}
}
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;
}
}
Course.java
package simple;
public class Course {
private String code;
private String name;
public Note notes[];
private int noteSize;
public Course(String code, String name) {
this.code = code;
this.name = name;
notes = new Note[5];
noteSize = 0;
}
public void add(Note note)
{
if(noteSize<5)
notes[noteSize++] = note;
}
public String getCode()
{
return code;
}
public String getName()
{
return name;
}
public int getCount()
{
return noteSize;
}
public Note get(int i)
{
if(i<notes.length)
return notes[i];
else return null;
}
@Override
public String toString() {
return code + " " + name;
}
}
P2Tester.java
package simple;
public class P2Tester {
public static void main(String[] args) {
Course c1 = new Course("EE333", "Engineering Software using Objects");
Note n1 = new Note("Chapter 1");
n1.append("This is the first line for chapter 1");
n1.append("This is the second line for chapter 1");
Note n2 = new Note("Chapter 2");
n2.append("This is the first line for chapter 2");
n2.append("This is the second line for chapter 2");
c1.add(n1);
c1.add(n2);
if(n1.getTitle().equals("Chapter 1") && n1.getUID() != n2.getUID() && n1.getCount() == 2
&& n1.getLine(1).equals("This is the second line for chapter 1"))
{
System.out.println("Note class works");
}
else
System.out.println("note class doesnt work");
if(c1.getCode().equals("EE333") && c1.getName().equals("Engineering Software using Objects")
&& c1.toString().equals("EE333 Engineering Software using Objects") && c1.getCount()==2)
{
System.out.println("Course Class works");
}
else
System.out.println("Course class doesnt work");
}
}
OUTPUT:
Note class works
Course Class works
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.