Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please do it in java, no use of any sort of java library @Test public void test03b() { Participant heeyeon = new Participant(H. Y. Kang);

please do it in java, no use of any sort of java library

image text in transcribed

image text in transcribed

@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}; /* Q. Without the loop below, * how many lines of assertions need to be written explicitly? */ for(int i = 0; i

pass these junit tests, thank you

image text in transcribedimage text in transcribedimage text in transcribed

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. public class TestOnlineSchool { * Requirement: Any classes you add to the model package must not contain any use of the Java library (e.g., ArrayList). * Tests included in this class serve as documentation on how instances of an online school operates. * Before attempting this lab, it is expected that you already completed the pre-study materials: 1. Week 7 Java Tutorials: https://www.youtube.com/playlist?list=PL5dxAmCmjv_7x3Qn5px_z5@qqgaBK95c1 2.1 Written Notes on Reference-Typed, Multi-Valued Attributes: https://www.eecs.yorku.ca/-jackie/teaching/lectures/2021/W/EECS1022otes/EECS1022_W21_Tracing_PointCollectorTester.pdf 2.2 The written notes in 2.1 will make it easier for you to follow Week 8's Java Tutorials: https://www.youtube.com/playlist?list=PL5dxAmCmjv_6JyoGf4zvQmg3pinzipWdb 4. Written Notes on Inferring Classes from JUnit Tests: https://www.eecs.yorku.cajackie/teaching/lectures/2021/W/EECS1022otes/EECS1022_W21_Inferring_Classes_from_JUnit.pdf * Item 2.2. will only be available on March 5. You may start attempting the lab after completing: Items 1, 2.1, and 4. * Be sure to also read the following sections from your Labs instructions PDF: - Section 2.3 The Online School Problem - Section 2.4 Hints and Requirements * Programming IDEs such as Eclipse are able to fix such compilation errors for you. * However, you are advised to follow the guidance as specified in the written notes above to fix these compilation errors manually, because: 1) it helps you better understand how the intended classes and methods work together; and 2) you may be tested in a written test or exam without the assistance of IDES. * * */ /* Recommended exercises: Visualizing and tracing (on both debugger and paper) on how objects are created and manipulated in each test would be extremely valuable for reinforcing your understanding. */ * Recommended exercises: Visualizing and tracing on both debugger and paper) on how objects are created and manipulated in each test would be extremely valuable for reinforcing your understanding. @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(); /* Returned information only displays the marks, grade, and description when there is an instructor. */ String info = r.getInformation(); 720 73 74 75 76 770 78 79 80 81 x 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 x 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 assertEquals("Software Design", t); assertEquals(O, m); assertNull(i); assertTrue (gr.length == 2 && gr[@].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(@, r.getMarks(); assert True (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@ecs.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 (F ; Failing)", r.getInformation(); r.setMarks (61); 43129 130 131 132 133 134 135 136 137 138 assertEquals(61, r.getMarks()); assertTrue (r.getGradeReport().length == 2 && r.getGradeReport[@].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(jin); /* Q. Can you visualize why this assertion is true? */ 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(); } Recommended exercises: Visualizing and tracing (on both debugger and paper) on how objects are created and manipulated * in each test would be extremely valuable for reinforcing your understanding. * @Test public void test_02b() { /* Second argument of the constructor call is an anonymous object: new Instructor("3. Gibbons", 76283, "jeremy@yorku.ca") */ Registration - new Registration("Data Structures", new Instructor("). Gibbons", 76283, "jeremy@yorku.ca")); r.setMarks (73); assertEquals("Data Structures", r.getTitle()); assertEquals(73, r.getMarks()); assert True (r.getInstructor().getName().equals("). 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")); assert True (r.getGradeReport().length == 2 && r.getGradeReport[@].equals("8") && r.getGradeReport()[1].equals("Good")); assertEquals("Data Structures, taught by J. Gibbons, is completed with raw marks 73 (B ; Good)", r.getInformation()); } 139 140 141 142 143 1440 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169e 170 3171 172 173 174 175 176 177 178 179 $180 181 182 183 184 185 186 187 188 189 190 191 9192 193 194 195 196 197 198 199 209 201 202 203 204 205 206 207 208 209 219 211 212 213 214 * Recommended exercises: * Visualizing and tracing (on both debugger and paper) on how objects are created and manipulated in each test would be extremely valuable for reinforcing your understanding. @Test public void test3a() { Instructor alan = new Instcucter("A. Wassyng", 70130, "jackie@eecs.yorku.ca"); Instcucter mark = new Instcucter("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(); /* empty list of registrations to begin with */ assert True (suyeonRegistrations. length == 0); /* GPA undefined over an empty list of registrations */ assertEquals("No GPA available yet for S. Y. Lee", report); /* non-registered courses have default marks -1 1 assert True (suyeon.marksof("Intro. to OOP") == -1); assert True (suyeon.marksOf("Heavy Metal Music") -- -1); assert True (suyeon.marksOf("Psychology I") -- -1); Registration ri = 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 (ri); suyeon.addRegistration ("Heavy Metal Music"); assert True (suyeon.getRegistrations().length == 2 && suyeon.getRegistrations() [@] =- r1 && suyeon.getRegistrations() [1].getTitle().equals("Heavy Metal Music") && suyeon.getRegistrations()[1].getInstructor() == null); assert True (suyeon.getRegistrations() [@].getMarks() == 0); assert True (suyeon.getRegistrations() [1].getMarks() == 0); assert True (suyeon.marksOf("Intro. to OOP") == 0); /* now a registered course / assert True (suyeon.marksof("Heavy Metal Music") == @); /* now a registered course */ assert True (suyeon.marksOf("Psychology 1") -- -1); /* still a non-registered course */ suyeon.getRegistrations()[1].setInstructor (mark); assert True (suyeon.getRegistrations()[1].getInstructor() == mark); 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 2235 3236 2237 238 23239 240 -9241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 * 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), O (F)}: 0.0", suyeon.getGPAReport(); suyeon.updateMarks ("Intro. to OOP", 61); suyeon.updateMarks ("Heavy Metal Music", 79); /* non-existing course -> do nothing */ suyeon.updateMarks ("Psychology I", 89); assertTrue (suyeon.getRegistrations)[].getMarks) 61); /* Grade: C; GP: 6 */ assertTrue (suyeon.getRegistrations() [1].getMarks() == 79); /* Grade: B; GP: 7 */ assertTrue (suyeon.marksOf("Intro. to OOP") == 61); assert True (suyeon.marksof("Heavy Metal Music") == 79); assertTrue (suyeon.marksOf("Psychology I") == -1); /* GPA = sum of GPs divided by number of courses */ 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)); /* Q. Can you understand the two occurrences of anonymous objects below? */ 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); assert True (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); assert True (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(); /* Suyeon and Yuna are classmates of two courses, * but the registration objects are distinct. */ assertEquals(suyeon.getRegistrations() [@].getTitle(), yuna.getRegistrations()[1].getTitle(); assertTrue (suyeon.getRegistrations ( [0] != yuna.getRegistrations ([1]); assertEquals(suyeon.getRegistrations()[1].getTitle(), yuna.getRegistrations() [@].getTitle()); assertTrue (suyeon.getRegistrations() [1] != yuna.getRegistrations ( [0]); /* At the end of the semester, clear registrations of students. */ 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"}; /* Q. Without the loop below, * how many lines of assertions need to be written explicitly? */ for(int i = 0; i do nothing */ suyeon.updateMarks ("Psychology I", 89); assertTrue (suyeon.getRegistrations)[].getMarks) 61); /* Grade: C; GP: 6 */ assertTrue (suyeon.getRegistrations() [1].getMarks() == 79); /* Grade: B; GP: 7 */ assertTrue (suyeon.marksOf("Intro. to OOP") == 61); assert True (suyeon.marksof("Heavy Metal Music") == 79); assertTrue (suyeon.marksOf("Psychology I") == -1); /* GPA = sum of GPs divided by number of courses */ 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)); /* Q. Can you understand the two occurrences of anonymous objects below? */ 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); assert True (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); assert True (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(); /* Suyeon and Yuna are classmates of two courses, * but the registration objects are distinct. */ assertEquals(suyeon.getRegistrations() [@].getTitle(), yuna.getRegistrations()[1].getTitle(); assertTrue (suyeon.getRegistrations ( [0] != yuna.getRegistrations ([1]); assertEquals(suyeon.getRegistrations()[1].getTitle(), yuna.getRegistrations() [@].getTitle()); assertTrue (suyeon.getRegistrations() [1] != yuna.getRegistrations ( [0]); /* At the end of the semester, clear registrations of students. */ 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"}; /* Q. Without the loop below, * how many lines of assertions need to be written explicitly? */ for(int i = 0; i

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_2

Step: 3

blur-text-image_3

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

Database Theory And Application Bio Science And Bio Technology International Conferences DTA And BSBT 2011 Held As Part Of The Future Generation In Computer And Information Science 258

Authors: Tai-hoon Kim ,Hojjat Adeli ,Alfredo Cuzzocrea ,Tughrul Arslan ,Yanchun Zhang ,Jianhua Ma ,Kyo-il Chung ,Siti Mariyam ,Xiaofeng Song

2011th Edition

3642271561, 978-3642271564

More Books

Students also viewed these Databases questions