I have one lab assignment to do I have complete it 50 % and 50% remain because I stuck in point number 4 REFINING THE STUDENT CLASS. Here I am attachig images of assignment. I have eclipse workspace zip file. But there is no option to upload zip file here. How can i provide you ?
Activities 2 Document viewer Wed 14:48 1 of 5 Q Lab_09.pdf 140.53% Out... 1 SETTING UP THE PROJECT Set up a new project per the usual method 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 3 6 Final Polish 3 7 Final Testing 4 s 1. Make a new Eclipse project and call it Lab_09_Last_Frist 2. Make a Driver class with a package of com.firstlast.lab_09 a. See lab 08 for details on how to do this if needed 3. Insert the Person, Student, Teacher, and Course classes from lab 08 You can use your classes, but they must match mine exactly. If they don't, please use my classes from BrightSpace b. You will need to adjust the package label in each class's Java file a. 2 REFINING THE COURSE CLASS Now we need to refine our classes a bit. We'll start with the Course class, which represents a class that a student will take. a. 1. In the Course class Override the equals() method i. Remember to use the @Override annotation ii. Remember the principles and steps to address when overriding equals! 1. Check the slides and in-class examples for guidance iii. There are three fields that are significant for comparison: name, grade, and teacher 2. In the main method of the Driver class Activities 2 Document viewer Wed 14:48 1 of 5 Q Lab_09.pdf 140.53% Out... 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 3 6 Final Polish 3 7 Final Testing 4 teacher 2. In the main method of the Driver class a. Make two Teacher objects, t1 and t2, with identical information i. For example, Teacher ("Prof.", "Blade", "Frisch", "ECE"); b. Make two Course objects, c1 and c2, with the same name and same grade, but pass t1 to cl's constructor and t2 to c2's constructor i. For example, Course ("ECE 25100", Course.A, t1); c. Call cl.equals (c2) and print out the result d. Are the two courses equal? s 3 REFINING THE TEACHER CLASS Since we are comparing teacher objects when comparing Course objects, we also need to override the equals method for Teacher 1. In the Teacher class Activities Document viewer Wed 14:49 2 of 5 Q Lab_09.pdf 140.53% equals method for Teacher Out... 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 3 6 Final Polish 3 7 Final Testing 4 s 1. In the Teacher class a. Override the equals() method i. Remember to use the @Override annotation ii. Remember the principles and steps to address when overriding equals! 1. Check the slides and in-class examples for guidance iii. There are four fields that are significant for comparison: first name, last name, title, and subject 2. In the main method of the Driver class a. Compare the two teacher objects you previously made, t1 and t2, and print out the result i. If the result is anything other than "true", double-check the comparisons b. Did the result for comparing the Course objects change? 4 REFINING THE STUDENT CLASS Now that we have a way to compare Course objects, let's refine the student class by adding a method that allows the student to take a course. This method will need to check that the course has not already been taken and, if not, add it to the student's transcript. Once the course has been added, the GPA needs to be updated. a. 1. In the Student class Make a method called take ACourse that accepts a Course as a parameter and returns an int i. This int will act as a status report of the method, so let's make some constants Activities Document viewer Wed 14:49 2 of 5 a Lab_09.pdf 140.53% Out... 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 3 6 Final Polish 3 7 Final Testing 4 s int i. This int will act as a status report of the method, so let's make some constants to help us: 1. Make two static final int variables, SUCCESS and ALREADY_EXISTS, initialized with the values of 1 and 2 respectively b. In this method, check that the course is not already on the transcript i. If it is, return ALREADY_EXISTS ii. If not, add the course to the transcript c. Next, we need to update the GPA in this method: i. Make an iterator variable and store the iterator for the transcript ArrayList in it ii. Make count and sum variables and initialize them to 0 iii. Write a while loop that will run so long as the iterator has a next value to process 1. In the loop, increment count and add the course's grade code to the sum of grade points iv. Recalculate the GPA Activities Document viewer Wed 14:49 3 of 5 Q Lab_09.pdf 140.53% Out... 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 6 Final Polish 3 7 Final Testing 4 s 1. Remember to watch out for integer division, which can be solved by casting! d. Finally, return SUCCESS 2. In the main method of the Driver class a. Make a Student object s and initialize it with dummy data b. Add the course c1 to the student and store the result in an int variable Check that the result is a success, using the static final variable we made in the Student class d. Next, try adding the course c2, store the result, and confirm that the method tells us the course already exists e. Finally print the GPA and confirm that it is 4.0, since we made cl with a grade of A C. 5 KEEPING THE CONTRACT Now, even though we aren't using the hashCode() method, we know it's a best practice to override hashCode() if we override equals(). Let's take care of this in the Course and Teacher classes, starting with Teacher. a. 1. In the Teacher class Override the hashCode() method i. Since the four fields are strings, we will use the string's built-in hashCode) method ii. Use 31 as the primary number, as shown in the Further Reading and in-class Activities Document viewer Wed 14:49 3 of 5 Q Lab_09.pdf 140.53% v Out... 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 6 Final Polish 3 7 Final Testing 4 a. method ii. Use 31 as the primary number, as shown in the Further Reading and in-class examples 2. In the Course class Override the hashCode() method i. Watch out for the mix of field data types! 1. For grade, use the wrapper class's hasCode(int) method 2. For teacher, call the hashCode() method we just wrote in 5.1 ii. Use 31 as the primary number, as shown in the Further Reading and in-class examples s 6 FINAL POLISH We're doing great so far! Let's put the final bit of polish on our classes: making output nice and pretty. Let's override the toString() method for Course , Teacher, and Student to make output all nice. a. 1. In the Teacher class Override the toString() method to return a string that matches this format: Title First Last, Subject" i. For example, mine would be: "Prof. Blade Frisch, ECE" b. You can easily do this with String.format() or StringBuilder 2. In the Course class Activities Document viewer Wed 14:49 4 of 5 Q Lab_09.pdf 140.53% 140.53% Out... a. 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 3 6 Final Polish 3 7 Final Testing 4 Override the toString() method to returna string that matches this format: "Name:
. Instructor: . Grade Received: ." i. For example, the c1 object should be: "Name: ECE 25100. Intructor: Prof. Blade Frisch, ECE. Grade Received: A." 1. Notice how the instructor string is the same as the toString() result from 6.1. You can use that exact method! 2. Notice how the grade is the letter grade, not the number code. Use the getter method to get the correct letter. 3. In the Student class a. Override the toString() method to return a string using the following code: StringBuilder builder = new StringBuilder(); builder.append(String.format("%s, % - %d. GPA: %.2f%n", lastName, firstName, id, gpa)); Iterator i = transcript. iterator(); while(i.hasNext()) { builder.append("\t"); builder.append(i.next()); builder.append(" "); } return builder.toString(); 7 FINAL TESTING Activities Document viewer Wed 14:49 4 of 5 Q Lab_09.pdf 140.53% Out... 7 FINAL TESTING Everything is looking great! Let's see how everything ties together. 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 3 6 Final Polish 3 7 Final Testing 4 a. 1. In the main method of the Driver class Print out the Student object s to see toString() in action i. There should be one course and a GPA of 4.00 b. Make three more course objects, c3-c5 and fill them with dummy data c. Have the student take each course by calling takeACourse(course) and print out the Student object s after each call to takeACourse(course) i. You should see the GPA change and the transcript grow d. Here is some sample output to check your output against: Activities Document viewer Wed 14:49 5 of 5 Q Lab_09.pdf 140.53% Out... 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 3 6 Final Polish 3 7 Final Testing 4 Driver (5) Java Application) C:\Program Files Java\jdk-15.0.1\bin\javaw.exe (Mar 5, 2021, 5:20:28 PM - 5:20:28 PM) true true true true 4.0 Frisch, Blade - 123456789. GPA: 4.00 Name: ECE 25100. Instructor: Prof. Blade Frisch, ECE. Grade received: A. Frisch, Blade - 123456789. GPA: 3.50 Name: ECE 25100. Instructor: Prof. Blade Frisch, ECE. Grade received: A. Name: ECE 15100. Instructor: Prof. Blade Frisch, ECE. Grade received: B. Frisch, Blade - 123456789. GPA: 3.33 Name: ECE 25100. Instructor: Prof. Blade Frisch, ECE. Grade received: A. Name: ECE 15100. Instructor: Prof. Blade Frisch, ECE. Grade received: B. Name: ECE 35100. Instructor: Prof. Blade Frisch, ECE. Grade received: B. Frisch, Blade - 123456789. GPA: 2.75 Name: ECE 25100. Instructor: Prof. Blade Frisch, ECE. Grade received: A. Name: ECE 15100. Instructor: Prof. Blade Frisch, ECE. Grade received: B. Name: ECE 35100. Instructor: Prof. Blade Frisch, ECE. Grade received: B. Name: ECE 45100. Instructor: Prof. Blade Frisch, ECE. Grade received: D. Activities 2 Document viewer Wed 14:48 1 of 5 Q Lab_09.pdf 140.53% Out... 1 SETTING UP THE PROJECT Set up a new project per the usual method 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 3 6 Final Polish 3 7 Final Testing 4 s 1. Make a new Eclipse project and call it Lab_09_Last_Frist 2. Make a Driver class with a package of com.firstlast.lab_09 a. See lab 08 for details on how to do this if needed 3. Insert the Person, Student, Teacher, and Course classes from lab 08 You can use your classes, but they must match mine exactly. If they don't, please use my classes from BrightSpace b. You will need to adjust the package label in each class's Java file a. 2 REFINING THE COURSE CLASS Now we need to refine our classes a bit. We'll start with the Course class, which represents a class that a student will take. a. 1. In the Course class Override the equals() method i. Remember to use the @Override annotation ii. Remember the principles and steps to address when overriding equals! 1. Check the slides and in-class examples for guidance iii. There are three fields that are significant for comparison: name, grade, and teacher 2. In the main method of the Driver class Activities 2 Document viewer Wed 14:48 1 of 5 Q Lab_09.pdf 140.53% Out... 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 3 6 Final Polish 3 7 Final Testing 4 teacher 2. In the main method of the Driver class a. Make two Teacher objects, t1 and t2, with identical information i. For example, Teacher ("Prof.", "Blade", "Frisch", "ECE"); b. Make two Course objects, c1 and c2, with the same name and same grade, but pass t1 to cl's constructor and t2 to c2's constructor i. For example, Course ("ECE 25100", Course.A, t1); c. Call cl.equals (c2) and print out the result d. Are the two courses equal? s 3 REFINING THE TEACHER CLASS Since we are comparing teacher objects when comparing Course objects, we also need to override the equals method for Teacher 1. In the Teacher class Activities Document viewer Wed 14:49 2 of 5 Q Lab_09.pdf 140.53% equals method for Teacher Out... 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 3 6 Final Polish 3 7 Final Testing 4 s 1. In the Teacher class a. Override the equals() method i. Remember to use the @Override annotation ii. Remember the principles and steps to address when overriding equals! 1. Check the slides and in-class examples for guidance iii. There are four fields that are significant for comparison: first name, last name, title, and subject 2. In the main method of the Driver class a. Compare the two teacher objects you previously made, t1 and t2, and print out the result i. If the result is anything other than "true", double-check the comparisons b. Did the result for comparing the Course objects change? 4 REFINING THE STUDENT CLASS Now that we have a way to compare Course objects, let's refine the student class by adding a method that allows the student to take a course. This method will need to check that the course has not already been taken and, if not, add it to the student's transcript. Once the course has been added, the GPA needs to be updated. a. 1. In the Student class Make a method called take ACourse that accepts a Course as a parameter and returns an int i. This int will act as a status report of the method, so let's make some constants Activities Document viewer Wed 14:49 2 of 5 a Lab_09.pdf 140.53% Out... 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 3 6 Final Polish 3 7 Final Testing 4 s int i. This int will act as a status report of the method, so let's make some constants to help us: 1. Make two static final int variables, SUCCESS and ALREADY_EXISTS, initialized with the values of 1 and 2 respectively b. In this method, check that the course is not already on the transcript i. If it is, return ALREADY_EXISTS ii. If not, add the course to the transcript c. Next, we need to update the GPA in this method: i. Make an iterator variable and store the iterator for the transcript ArrayList in it ii. Make count and sum variables and initialize them to 0 iii. Write a while loop that will run so long as the iterator has a next value to process 1. In the loop, increment count and add the course's grade code to the sum of grade points iv. Recalculate the GPA Activities Document viewer Wed 14:49 3 of 5 Q Lab_09.pdf 140.53% Out... 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 6 Final Polish 3 7 Final Testing 4 s 1. Remember to watch out for integer division, which can be solved by casting! d. Finally, return SUCCESS 2. In the main method of the Driver class a. Make a Student object s and initialize it with dummy data b. Add the course c1 to the student and store the result in an int variable Check that the result is a success, using the static final variable we made in the Student class d. Next, try adding the course c2, store the result, and confirm that the method tells us the course already exists e. Finally print the GPA and confirm that it is 4.0, since we made cl with a grade of A C. 5 KEEPING THE CONTRACT Now, even though we aren't using the hashCode() method, we know it's a best practice to override hashCode() if we override equals(). Let's take care of this in the Course and Teacher classes, starting with Teacher. a. 1. In the Teacher class Override the hashCode() method i. Since the four fields are strings, we will use the string's built-in hashCode) method ii. Use 31 as the primary number, as shown in the Further Reading and in-class Activities Document viewer Wed 14:49 3 of 5 Q Lab_09.pdf 140.53% v Out... 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 6 Final Polish 3 7 Final Testing 4 a. method ii. Use 31 as the primary number, as shown in the Further Reading and in-class examples 2. In the Course class Override the hashCode() method i. Watch out for the mix of field data types! 1. For grade, use the wrapper class's hasCode(int) method 2. For teacher, call the hashCode() method we just wrote in 5.1 ii. Use 31 as the primary number, as shown in the Further Reading and in-class examples s 6 FINAL POLISH We're doing great so far! Let's put the final bit of polish on our classes: making output nice and pretty. Let's override the toString() method for Course , Teacher, and Student to make output all nice. a. 1. In the Teacher class Override the toString() method to return a string that matches this format: Title First Last, Subject" i. For example, mine would be: "Prof. Blade Frisch, ECE" b. You can easily do this with String.format() or StringBuilder 2. In the Course class Activities Document viewer Wed 14:49 4 of 5 Q Lab_09.pdf 140.53% 140.53% Out... a. 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 3 6 Final Polish 3 7 Final Testing 4 Override the toString() method to returna string that matches this format: "Name: . Instructor: . Grade Received: ." i. For example, the c1 object should be: "Name: ECE 25100. Intructor: Prof. Blade Frisch, ECE. Grade Received: A." 1. Notice how the instructor string is the same as the toString() result from 6.1. You can use that exact method! 2. Notice how the grade is the letter grade, not the number code. Use the getter method to get the correct letter. 3. In the Student class a. Override the toString() method to return a string using the following code: StringBuilder builder = new StringBuilder(); builder.append(String.format("%s, % - %d. GPA: %.2f%n", lastName, firstName, id, gpa)); Iterator i = transcript. iterator(); while(i.hasNext()) { builder.append("\t"); builder.append(i.next()); builder.append(" "); } return builder.toString(); 7 FINAL TESTING Activities Document viewer Wed 14:49 4 of 5 Q Lab_09.pdf 140.53% Out... 7 FINAL TESTING Everything is looking great! Let's see how everything ties together. 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 3 6 Final Polish 3 7 Final Testing 4 a. 1. In the main method of the Driver class Print out the Student object s to see toString() in action i. There should be one course and a GPA of 4.00 b. Make three more course objects, c3-c5 and fill them with dummy data c. Have the student take each course by calling takeACourse(course) and print out the Student object s after each call to takeACourse(course) i. You should see the GPA change and the transcript grow d. Here is some sample output to check your output against: Activities Document viewer Wed 14:49 5 of 5 Q Lab_09.pdf 140.53% Out... 1 Setting up ... 1 2 Refining th... 1 3 Refining th... 2 4 Refining th... 2 5 Keeping th... 3 6 Final Polish 3 7 Final Testing 4 Driver (5) Java Application) C:\Program Files Java\jdk-15.0.1\bin\javaw.exe (Mar 5, 2021, 5:20:28 PM - 5:20:28 PM) true true true true 4.0 Frisch, Blade - 123456789. GPA: 4.00 Name: ECE 25100. Instructor: Prof. Blade Frisch, ECE. Grade received: A. Frisch, Blade - 123456789. GPA: 3.50 Name: ECE 25100. Instructor: Prof. Blade Frisch, ECE. Grade received: A. Name: ECE 15100. Instructor: Prof. Blade Frisch, ECE. Grade received: B. Frisch, Blade - 123456789. GPA: 3.33 Name: ECE 25100. Instructor: Prof. Blade Frisch, ECE. Grade received: A. Name: ECE 15100. Instructor: Prof. Blade Frisch, ECE. Grade received: B. Name: ECE 35100. Instructor: Prof. Blade Frisch, ECE. Grade received: B. Frisch, Blade - 123456789. GPA: 2.75 Name: ECE 25100. Instructor: Prof. Blade Frisch, ECE. Grade received: A. Name: ECE 15100. Instructor: Prof. Blade Frisch, ECE. Grade received: B. Name: ECE 35100. Instructor: Prof. Blade Frisch, ECE. Grade received: B. Name: ECE 45100. Instructor: Prof. Blade Frisch, ECE. Grade received: D