Question: In java, This is the code that must be used: public class UnitTests { /** * Tests the Task 1 implementations. * */ public void

In java,

This is the code that must be used:

public class UnitTests {

/** * Tests the Task 1 implementations. * */ public void test1() throws Exception { assertEquals("John", "" + new Person("John")); assertEquals("Emily", "" + new Person("Emily")); }

/** * Tests the Task 2 implementations. * */ public void test2() throws Exception { assertEquals("Chloy, 1234", "" + new Student("Chloy", 1234)); assertEquals("Ken, 2345", "" + new Student("Ken", 2345)); }

/** * Tests the Task 3 implementations. * */ public void test3() throws Exception { assertEquals(3, new Student("Tom", 3456).studentCount()); assertEquals(4, new Student("Jenny", 4567).studentCount()); }

This are the tasks:

In java, This is the code that must be used: public class

Thank you very much!

Task 1. Complete the constructor "Person(String name)" so that it sets the member variable "name" to the argument "name". Also, add the "public String toString0" method and then implement it (i.e., override the "Object\#toString0" method) so that it returns the name of the Person instance on which the method is called. When you finish this task, the following code in Person\#main(String[) will output "Emily": new Person("John"); // construct a Person instance whose name is "John" Person p= new Person("Emily"); // construct a Person instance whose name is "Emily" System.out.println(p); // output the name of the last Person instance (i.e., "Emily") Your code will also pass the unit test named "test10" in "UnitTests.java". PART 3: Completing Student.java Task 2. Change the "Student" class so that it inherits the member variable "name" from the "Person" class. Also, complete the the constructor "Student(String name, int studentID)" so that the "Student" instance being constructed can remember the "name" and "studentID" given to the constructor. Finally, you need to add the "public String toString0" method so that it returns a string containing the name and student ID in the form of "[name], [studentID]" (e.g., "Ken, 2345"). When you finish this task, the following code in Student\#main(String[]) will output "Ken, 2345": new Student("Chloy", 1234); Student s = new Student("Ken", 2345); System.out.println(s); // output the name and student ID of the last Student instance (i.e., "Ken, 2345")) Your code will also pass the unit test named "test20" in "UnitTests.java". Task 3. Change Student.java in order for the studentCount() method to return the number of Student instances constructed since the beginning of the Java program. When you finish this task, the following code in Student\#main(String[) will output "2: (i.e., 2) System.out.println(s.studentCount()); // output the number of Student instances constructed so far Your code will also pass the unit test named "test30" in "UnitTests.java

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!