Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WRITTEN IN JAVA IN ECLIPSE, DO NOT YOU ANY JAVA LIBRARY classes (e.g., ArrayList) or methods for implementation. That is, there must not be any

WRITTEN IN JAVA IN ECLIPSE, DO NOT YOU ANY JAVA LIBRARY classes (e.g., ArrayList) or methods for implementation. That is, there must not be any import statement in the class(es) you add to the model package.

USE THE JUNIT TESTS PROVIDED BELOW TO INFER CLASS NAMES AND WHAT THEY DO TO CREATE THE PROGRAM.

image text in transcribed

image text in transcribedpackage junit_tests;

import static org.junit.Assert.*;

import org.junit.Test;

/* * Requirement: Any classes you create must reside in the `model` package and be imported properly. * For example, creating a new class `Foo` in the `model` package should result in: * import model.Foo; */ These are the Junit tests the program must pass:

@Test

public void test_01() {

Instructor i = new Instructor("Jackie", 70130, "jackie@eecs.yorku.ca");

String name = i.getName();

int ext = i.getPhoneExtension();

String contact = i.getEmail();

String info = i.getInformation();

assertEquals("Jackie", name);

assertEquals(70130, ext);

assertEquals("jackie@eecs.yorku.ca", contact);

assertEquals("Instructor Jackie has campus phone extension 70130 and contact email jackie@eecs.yorku.ca", info);

i.setName("Jonathan");

i.setPhoneExtension(70139);

i.setEmail("jonathan@yorku.ca");

assertEquals("Jonathan", i.getName());

assertEquals(70139, i.getPhoneExtension());

assertEquals("jonathan@yorku.ca", i.getEmail());

assertEquals("Instructor Jonathan has campus phone extension 70139 and contact email jonathan@yorku.ca", i.getInformation());

}

@Test

public void test_02a() {

Registration r = new Registration("Software Design");

String t = r.getTitle();

int m = r.getMarks();

Instructor i = r.getInstructor();

/* Size of returned array should be 2:

* - 1st element denotes the letter grade.

* - 2nd element denotes its qualitative description (see the mapping table in the instructions PDF).

*/

String[] gr = r.getGradeReport();

String info = r.getInformation();

assertEquals("Software Design", t);

assertEquals(0, m);

assertNull(i);

assertTrue(gr.length == 2 && gr[0].equals("F") && gr[1].equals("Failing"));

assertEquals("Software Design has not yet been assigned an instructor", info);

Instructor jackie = new Instructor("Jackie", 70130, "jackie@eecs.yorku.ca");

r.setInstructor(jackie);

assertEquals("Software Design", r.getTitle());

assertEquals(0, r.getMarks());

assertTrue(r.getInstructor() != null

&& r.getInstructor() == jackie /* reference aliasing */

/* Q. Can you visualize this chain of method calls? */

&& r.getInstructor().getName().equals("Jackie")

&& r.getInstructor().getPhoneExtension() == 70130

&& r.getInstructor().getEmail().equals("jackie@eecs.yorku.ca"));

assertTrue(r.getGradeReport().length == 2);

assertEquals(r.getGradeReport()[0], "F");

assertEquals(r.getGradeReport()[1], "Failing");

/* When the instructor is assigned for the course, its information displays:

* - Title of course

* - Name of instructor

* - Numerical marks, the corresponding letter grade, and its qualitative description.

*

* Note. Here we only test one case of mapping from marks to its grade and description.

* You should test other cases (see the mapping table in the instructions PDF).

*/

assertEquals("Software Design, taught by Jackie, is completed with raw marks 0 (F ; Failing)", r.getInformation());

r.setMarks(61);

assertEquals(61, r.getMarks());

assertTrue(r.getGradeReport().length == 2

&& r.getGradeReport()[0].equals("C")

&& r.getGradeReport()[1].equals("Competent"));

assertEquals("Software Design, taught by Jackie, is completed with raw marks 61 (C ; Competent)", r.getInformation());

Instructor jim = new Instructor("Jim Davies", 70139, "jim@yorku.ca");

r.setInstructor(jim);

assertTrue(r.getInstructor() != null

&& r.getInstructor() != jackie

&& r.getInstructor() == jim);

assertEquals("Software Design, taught by Jim Davies, is completed with raw marks 61 (C ; Competent)", r.getInformation());

}

@Test

public void test_02b() {

//Second argument of the constructor call is an anonymous object:

/ew Instructor("J. Gibbons", 76283, "jeremy@yorku.ca")

Registration r = new Registration("Data Structures", new Instructor("J. Gibbons", 76283, "jeremy@yorku.ca"));

r.setMarks(73);

assertEquals("Data Structures", r.getTitle());

assertEquals(73, r.getMarks());

assertTrue(r.getInstructor().getName().equals("J. Gibbons")

&& r.getInstructor().getPhoneExtension() == 76283

&& r.getInstructor().getEmail().equals("jeremy@yorku.ca")

&& r.getInstructor().getInformation().equals("Instructor J. Gibbons has campus phone extension 76283 and contact email jeremy@yorku.ca"));

assertTrue(r.getGradeReport().length == 2

&& r.getGradeReport()[0].equals("B")

&& r.getGradeReport()[1].equals("Good"));

assertEquals("Data Structures, taught by J. Gibbons, is completed with raw marks 73 (B ; Good)", r.getInformation());

}

@Test

public void test03a() {

Instructor alan = new Instructor("A. Wassyng", 70130, "jackie@eecs.yorku.ca");

Instructor mark = new Instructor("M. Lawford", 70139, "jonathan@yorku.ca");

Participant suyeon = new Participant("S. Y. Lee");

/*

* Length of the returned array from `getRegistrations` corresponds to

* the number of registrations added by the participant so far.

* See the instructions PDF regarding the max number of registrations that can be added.

*/

Registration[] suyeonRegistrations = suyeon.getRegistrations();

String report = suyeon.getGPAReport();

assertTrue(suyeonRegistrations.length == 0);

assertEquals("No GPA available yet for S. Y. Lee", report);

assertTrue(suyeon.marksOf("Intro. to OOP") == -1);

assertTrue(suyeon.marksOf("Heavy Metal Music") == -1);

assertTrue(suyeon.marksOf("Psychology I") == -1);

Registration r1 = new Registration("Intro. to OOP", alan);

/* add two registrations for suyeon

* Hints:

* - Are the two `addRegistration` calls denote the same method?

* - Or an overloaded method (i.e., methods with the same name but distinct input parameter types)?

*/

suyeon.addRegistration(r1);

suyeon.addRegistration("Heavy Metal Music");

assertTrue(suyeon.getRegistrations().length == 2

&& suyeon.getRegistrations()[0] == r1

&& suyeon.getRegistrations()[1].getTitle().equals("Heavy Metal Music")

&& suyeon.getRegistrations()[1].getInstructor() == null);

assertTrue(suyeon.getRegistrations()[0].getMarks() == 0);

assertTrue(suyeon.getRegistrations()[1].getMarks() == 0);

assertTrue(suyeon.marksOf("Intro. to OOP") == 0); /* now a registered course */

assertTrue(suyeon.marksOf("Heavy Metal Music") == 0); /* now a registered course */

assertTrue(suyeon.marksOf("Psychology I") == -1); /* still a non-registered course */

suyeon.getRegistrations()[1].setInstructor(mark);

assertTrue(suyeon.getRegistrations()[1].getInstructor() == mark);

/*

* Notice the format of GPA report:

* - GPA value is displayed with 1 digit after the decimal point.

* - The comma-separated list of `GradePoint (LetterGrade)` is surrounded by curly braces.

* - There is a space after each comma and after the colon.

*/

assertEquals("S. Y. Lee's GPA of {0 (F), 0 (F)}: 0.0", suyeon.getGPAReport());

suyeon.updateMarks("Intro. to OOP", 61);

suyeon.updateMarks("Heavy Metal Music", 79);

suyeon.updateMarks("Psychology I", 89);

assertTrue(suyeon.getRegistrations()[0].getMarks() == 61); /* Grade: C; GP: 6 */

assertTrue(suyeon.getRegistrations()[1].getMarks() == 79); /* Grade: B; GP: 7 */

assertTrue(suyeon.marksOf("Intro. to OOP") == 61);

assertTrue(suyeon.marksOf("Heavy Metal Music") == 79);

assertTrue(suyeon.marksOf("Psychology I") == -1);

assertEquals("S. Y. Lee's GPA of {6 (C), 7 (B)}: 6.5", suyeon.getGPAReport());

Participant yuna = new Participant("Y. Lee");

yuna.addRegistration(new Registration("Heavy Metal Music", mark));

yuna.addRegistration(new Registration("Intro. to OOP", alan));

yuna.addRegistration(new Registration(

"Psychology I",

new Instructor("Tom", 70141, "tom@yorku.ca")));

yuna.updateMarks("Heavy Metal Music", 85);

yuna.updateMarks("Intro. to OOP", 58);

yuna.updateMarks("Psychology I", 66);

assertTrue(yuna.getRegistrations()[0].getMarks() == 85); /* Grade: A; GP: 8 */

assertTrue(yuna.getRegistrations()[1].getMarks() == 58); /* Grade: D; GP: 5 */

assertTrue(yuna.getRegistrations()[2].getMarks() == 66); /* Grade: C; GP: 6 */

assertTrue(yuna.marksOf("Heavy Metal Music") == 85);

assertTrue(yuna.marksOf("Intro. to OOP") == 58);

assertTrue(yuna.marksOf("Psychology I") == 66);

assertEquals("Y. Lee's GPA of {8 (A), 5 (D), 6 (C)}: 6.3", yuna.getGPAReport());

assertEquals(suyeon.getRegistrations()[0].getTitle(), yuna.getRegistrations()[1].getTitle());

assertTrue(suyeon.getRegistrations()[0] != yuna.getRegistrations()[1]);

assertEquals(suyeon.getRegistrations()[1].getTitle(), yuna.getRegistrations()[0].getTitle());

assertTrue(suyeon.getRegistrations()[1] != yuna.getRegistrations()[0]);

suyeon.clearRegistrations();

yuna.clearRegistrations();

assertTrue(suyeon.getRegistrations().length == 0

&& yuna.getRegistrations().length == 0);

assertTrue(suyeon.getGPAReport().equals("No GPA available yet for S. Y. Lee")

&& yuna.getGPAReport().equals("No GPA available yet for Y. Lee"));

String[] courses = {"Intro. to OOP", "Heavy Metal Music", "Psychology I", "Software Design"};

for(int i = 0; i

assertTrue(suyeon.marksOf(courses[i]) == -1);

assertTrue(yuna.marksOf(courses[i]) == -1);

}

suyeon.addRegistration("Heavy Metal Music");

suyeon.updateMarks("Heavy Metal Music", 99);

assertTrue(suyeon.getRegistrations().length == 1);

assertEquals("S. Y. Lee's GPA of {9 (A+)}: 9.0", suyeon.getGPAReport());

assertEquals("Heavy Metal Music has not yet been assigned an instructor", suyeon.getRegistrations()[0].getInformation());

}

@Test

public void test03b() {

Participant heeyeon = new Participant("H. Y. Kang");

Registration r1 = new Registration("EECS2001");

Registration r2 = new Registration("EECS2011");

Registration r3 = new Registration("EECS2021");

Registration r4 = new Registration("EECS2031");

Registration r5 = new Registration("EECS1090");

Registration[] list = {r1, r2, r3, r4, r5};

for(int i = 0; i

heeyeon.addRegistration(list[i]);

assertTrue(heeyeon.getRegistrations().length == i + 1);

assertTrue(heeyeon.getRegistrations()[i] == list[i]);

}

heeyeon.addRegistration(new Registration("ECON1000"));

heeyeon.addRegistration(new Registration("ECON1010"));

assertTrue(heeyeon.getRegistrations().length == 5);

assertTrue(heeyeon.getRegistrations()[0] == r1);

assertTrue(heeyeon.getRegistrations()[1] == r2);

assertTrue(heeyeon.getRegistrations()[2] == r3);

assertTrue(heeyeon.getRegistrations()[3] == r4);

assertTrue(heeyeon.getRegistrations()[4] == r5);

}

@Test

public void test_04() {

OnlineSchool school = new OnlineSchool();

Participant[] list1 = school.getParticipants("Intro. to OOP");

Participant[] list2 = school.getParticipants("Heavy Metal Music");

Participant[] list3 = school.getParticipants("Chamber Music");

assertTrue(list1.length == 0 && list2.length == 0 && list3.length == 0);

Participant alan = new Participant("A. Wassyng");

Participant mark = new Participant("M. Lawford");

Participant tom = new Participant("T. Maibaum");

school.addParticipant(alan);

school.addParticipant(mark);

school.addParticipant(tom);

tom.addRegistration("Heavy Metal Music");

tom.addRegistration("Chamber Music");

tom.addRegistration("Intro. to OOP");

alan.addRegistration("Intro. to OOP");

mark.addRegistration("Heavy Metal Music");

mark.addRegistration("Intro. to OOP");

list1 = school.getParticipants("Intro. to OOP");

list2 = school.getParticipants("Heavy Metal Music");

list3 = school.getParticipants("Chamber Music");

assertTrue(list1.length == 3

&& list1[0] == alan

&& list1[1] == mark

&& list1[2] == tom);

assertTrue(list2.length == 2

&& list2[0] == mark

&& list2[1] == tom);

assertTrue(list3.length == 1

&& list3[0] == tom);

assertTrue(school.getParticipants("How to Make Fish and Chips").length == 0);

}

}

2.3 The Online School Problem You are required to develop an object-oriented program solving a (simplified) online school problem, where there is a list of participants registered in courses taught by qualified instructors: Each instructor is characterized by their name, campus phone extension (e.g., 70310), and contact email. Each registration is characterized by its subject title, numerical marks, and instructor (who may not be assigned when the course is first created). Given a registration object: A grade report may be returned as an array of length 2, e.g., {"B", "Good"), where the first element stores the letter grade and the second element stores its qualitative description. Consider the following table summarizing how each numerical marks (assumed to range between 0 and 100) maps to its grade, description (whose spellings should be exact), and grade point: Range of Raw Marks Letter Grade Qualitative Description Grade Point 90 100 A+ Exceptional 80 - 89 A Excellent 70 - 79 B Good 60-69 Competent 50 - 59 49 Failing 9 8 C D F Passing 7 6 5 0 0 A string information object may be returned. There are two cases to consider, depending on whether or not the course instructor has been assigned. In the case where the instructor is present, the returned string should contain the course title, instructor name, the marks, and its corresponding grade and description (see the above mapping table). Each participant object is characterized by the name of student and the list of added registrations. Given a participant object, we may: Add a new registration, either by an input registration object, or by the name of course (from which a registration object may be created accordingly). The maximum number of registrations allowed for a participant is 5: attempting to add registrations beyond this limit will have no impact i.e., the list of registrations remains the same). Furthermore, there is no need to check if there are duplicated registrations added (e.g., two registrations with the same course name). Retrieve its list of registrations as an array (i.e., Registration[]), whose length is less than or equal to the maximum allowable number i.e., 5). Clear its list of registrations (e.g., allowing further registrations to be added). Retrieve the marks of a course with the given name. If the name of a non-registered course is given, then return -1 as its marks. - Update the marks of a course with the given name. If the name of a non-registered course is given, then nothing should be changed. Obtain a report of the GPA (grade point average) over the list of added registrations. Each online school object is characterized by its list of participants. Given an online school object, we may: Add a new participant by an input participant object. The maximum number of participants allowed for a school is 100: attempting to add participants beyond this limit will have no impact (i.e., the list of participants remains the same). Furthermore, there is no need to check if there are duplicated participants added (e.g., two participants with the same name). Retrieve the list of participants of a course, given its name, as an array. If the input name denotes a non-existing course, then an empty array is returned. Other intended functionalities of above kinds of objects can be inferred from the given JUnit test class TestOnlineSchool. 4 9 * *TestOnline School.java X 1 package junit_tests; 2 36 import static org.junit. Assert.*; import org.junit. Test; 6 7 /* 8 * Requirement: Any classes you create must reside in the model package and be imported properly. 9 * For example, creating a new class "F90' in the 'model package should result in: 10 * import model. Foo; 11 12 public class TestOnlineSchool { 13 140 15 * Requirement: Any classes you add to the "model" package must not contain any use of the Java library (e.g., ArrayList). 16 17 * Tests included in this class serve as documentation on how instances of an online school operates. 18 19 20 * Programming IDEs such as Eclipse are able to fix such compilation errors for you. 21 * However, you are advised to follow the guidance as specified in the written notes above 22 * to fix these compilation errors manually, because: 23 * 1) it helps you better understand how the intended classes and methods work together; and 24 * 2) you may be tested in a written test or exam without the assistance of IDES. 25 26 */ 27 28 @Test 29 public void test_01() { 30 Instructor i = new Instructor("Jackie", 70130, "jackie@eecs.yorku.ca"); 31 String name = i.getName(); 32 int ext = i.getPhoneExtension(); 33 String contact = i.getEmail(); 34 String info = i.getInformation(); 35 36 assertEquals("Jackie", name); 37 assertEquals(70130, ext); assertEquals("jackieceecs.yorku.ca", contact); 39 assertEquals("Instructor Jackie has campus phone extension 70130 and contact email jackie@eecs.yorku.ca", info); 10 41 i.setName("Jonathan"); 42 i.setPhoneExtension ( 70139); 13 i.setEmail("jonathan@yorku.ca"); 14 45 assertEquals("Jonathan", i.getName()); 46 assertEquals(70139, i.getPhoneExtension()); 17 assertEquals("jonathan@yorku.ca", i.getEmail()); 48 assertEquals("Instructor Jonathan has campus phone extension 70139 and contact email jonathan@yorku.ca", i.getInformation()); 19 } 50 516 52 * Recommended exercises: 53 Visualizing and tracing (on both debugger and paper) on how objects are created and manipulated 54 in each test would be extremely valuable for reinforcing your understanding. * 2.3 The Online School Problem You are required to develop an object-oriented program solving a (simplified) online school problem, where there is a list of participants registered in courses taught by qualified instructors: Each instructor is characterized by their name, campus phone extension (e.g., 70310), and contact email. Each registration is characterized by its subject title, numerical marks, and instructor (who may not be assigned when the course is first created). Given a registration object: A grade report may be returned as an array of length 2, e.g., {"B", "Good"), where the first element stores the letter grade and the second element stores its qualitative description. Consider the following table summarizing how each numerical marks (assumed to range between 0 and 100) maps to its grade, description (whose spellings should be exact), and grade point: Range of Raw Marks Letter Grade Qualitative Description Grade Point 90 100 A+ Exceptional 80 - 89 A Excellent 70 - 79 B Good 60-69 Competent 50 - 59 49 Failing 9 8 C D F Passing 7 6 5 0 0 A string information object may be returned. There are two cases to consider, depending on whether or not the course instructor has been assigned. In the case where the instructor is present, the returned string should contain the course title, instructor name, the marks, and its corresponding grade and description (see the above mapping table). Each participant object is characterized by the name of student and the list of added registrations. Given a participant object, we may: Add a new registration, either by an input registration object, or by the name of course (from which a registration object may be created accordingly). The maximum number of registrations allowed for a participant is 5: attempting to add registrations beyond this limit will have no impact i.e., the list of registrations remains the same). Furthermore, there is no need to check if there are duplicated registrations added (e.g., two registrations with the same course name). Retrieve its list of registrations as an array (i.e., Registration[]), whose length is less than or equal to the maximum allowable number i.e., 5). Clear its list of registrations (e.g., allowing further registrations to be added). Retrieve the marks of a course with the given name. If the name of a non-registered course is given, then return -1 as its marks. - Update the marks of a course with the given name. If the name of a non-registered course is given, then nothing should be changed. Obtain a report of the GPA (grade point average) over the list of added registrations. Each online school object is characterized by its list of participants. Given an online school object, we may: Add a new participant by an input participant object. The maximum number of participants allowed for a school is 100: attempting to add participants beyond this limit will have no impact (i.e., the list of participants remains the same). Furthermore, there is no need to check if there are duplicated participants added (e.g., two participants with the same name). Retrieve the list of participants of a course, given its name, as an array. If the input name denotes a non-existing course, then an empty array is returned. Other intended functionalities of above kinds of objects can be inferred from the given JUnit test class TestOnlineSchool. 4 9 * *TestOnline School.java X 1 package junit_tests; 2 36 import static org.junit. Assert.*; import org.junit. Test; 6 7 /* 8 * Requirement: Any classes you create must reside in the model package and be imported properly. 9 * For example, creating a new class "F90' in the 'model package should result in: 10 * import model. Foo; 11 12 public class TestOnlineSchool { 13 140 15 * Requirement: Any classes you add to the "model" package must not contain any use of the Java library (e.g., ArrayList). 16 17 * Tests included in this class serve as documentation on how instances of an online school operates. 18 19 20 * Programming IDEs such as Eclipse are able to fix such compilation errors for you. 21 * However, you are advised to follow the guidance as specified in the written notes above 22 * to fix these compilation errors manually, because: 23 * 1) it helps you better understand how the intended classes and methods work together; and 24 * 2) you may be tested in a written test or exam without the assistance of IDES. 25 26 */ 27 28 @Test 29 public void test_01() { 30 Instructor i = new Instructor("Jackie", 70130, "jackie@eecs.yorku.ca"); 31 String name = i.getName(); 32 int ext = i.getPhoneExtension(); 33 String contact = i.getEmail(); 34 String info = i.getInformation(); 35 36 assertEquals("Jackie", name); 37 assertEquals(70130, ext); assertEquals("jackieceecs.yorku.ca", contact); 39 assertEquals("Instructor Jackie has campus phone extension 70130 and contact email jackie@eecs.yorku.ca", info); 10 41 i.setName("Jonathan"); 42 i.setPhoneExtension ( 70139); 13 i.setEmail("jonathan@yorku.ca"); 14 45 assertEquals("Jonathan", i.getName()); 46 assertEquals(70139, i.getPhoneExtension()); 17 assertEquals("jonathan@yorku.ca", i.getEmail()); 48 assertEquals("Instructor Jonathan has campus phone extension 70139 and contact email jonathan@yorku.ca", i.getInformation()); 19 } 50 516 52 * Recommended exercises: 53 Visualizing and tracing (on both debugger and paper) on how objects are created and manipulated 54 in each test would be extremely valuable for reinforcing your understanding. *

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Multidimensional Array Data Management In Databases

Authors: Florin Rusu

1st Edition

1638281483, 978-1638281481

Students also viewed these Databases questions