Question

COMP5200 Class Week 4 EXERCISES CANNOT BE MARKED AFTER THE END OF YOUR DESIGNATED PC CLASS. You have one week to complete all the exercises. Introduction The exercises for this

week involve working with classes that are part of an inheritance hierarchy. You need to be familiar with terminology such as superclass and subclass. Background material Inheritance was covered in the Tuesday lecture of week 2 and the Monday lecture of week 3. You are expected to complete these exercises in a non-BlueJ IDE, such as IntelliJ. Background reading: Inheritance is covered in Chapters 10 and 11 of the course textbook. Aim to read Chapter 10 this week. Download the IntelliJ starter code from the Weekly Class Material section on Moodle. The zip file is called outerlevel-hockey.zip. Assignment 1 parts 1 and 2 The exercises this week are below, but in order to make a good start on assignment 1, we would like you to show your class supervisor this week that you have: ● Completed both parts 1 and 2 of the assignment. There are no marks for this but reaching this point at this stage of the assignment will give you confidence that you are ready to start work on the remaining tasks. When you run the skeleton code you will see the following output. This is what you need to show your class supervisor: Test part 1: Results of printing the vehicle details as they are read in. Taxi T1 driven by Zaffer Chopra Taxi T2 driven by Uwe Rebenich Taxi T3 driven by Kemi Adeyeye Taxi T4 driven by Molly Benjamin Shuttle S1 has the route: [Canterbury West, Canterbury East, Canterbury Bus Station, University of Kent] Shuttle S2 has the route: Westgate Towers] Shuttle S3 has the route: Canterbury Bus Station] [Canterbury Bus Station, University of Kent, Whitstable, Herne Bay, [Keynes College, Darwin College, Rutherford College, Eliot College, Test part 2: Results of printing the HashMap of vehicle details. Taxi T4 driven by Molly Benjamin Shuttle S3 has the route: [Keynes College, Darwin College, Rutherford College, Eliot College, Canterbury Bus Station] Taxi T1 driven by Zaffer Chopra Taxi T2 driven by Uwe Rebenich Shuttle S1 has the route: [Canterbury West, Canterbury East, Canterbury Bus Station, University of Kent] Taxi T3 driven by Kemi Adeyeye Shuttle S2 has the route: [Canterbury Bus Station, University of Kent, Whitstable, Herne Bay, Westgate Towers] ========== Test part 3: Results of printing the list of bookings. Test part 4: Results of calculating takings. T4 £-1 S3 £-1 T1 £-1 T2 £-1 S1 £-1 T3 £-1 S2 £-1 Test part 5: Results of writing the report. Taxi Company Report ========== Introduction to the classes in this week's exercises Download the starter code using the zip file called outerlevel-hockey.zip. Open the hockey folder in IntelliJ - Don't open the outerlevel-hockeyfolder in IntelliJ. In these exercises you will be working with some classes that already partially implement an inheritance hierarchy. The classes model members of a hockey team (HockeyTeam), which consists of hockey players (HockeyPlayer) and coaches (Coach). There is a Main class with a small amount of sample data and you are free to modify this as much as you wish. It currently creates a Hockey Team, populates it with players and a coach, and prints out the team's details. It also creates a Club object to which team members and their coach belong and prints the membership details of the club. The exercises require you to complete the task of using inheritance in the project. Note that none of the changes you make should cause the Main class we have provided to fail to compile or run. If you find that your changes break that class, then you have not made the changes correctly. The inheritance hierarchy The HockeyPlayer and Coach classes are already subclasses of the Member class. The Member class has a name field and a getter method for it. The field and method are inherited by HockeyPlayer and Coach. Section 1 Exercise: For this exercise, you will only need to make changes to three classes: ● Hockey Player ● Coach Both HockeyPlayer and Coach have a field called membership. Because this is used identically in both classes, it must be moved from the subclasses into the Member superclass. Member The field must now be initialized in the superclass constructor. You will need to modify the current call to super (name) in the subclass constructors. (This is because the parameter for membership is received by the subclass constructor, but it must be passed on to the superclass constructor in the super call). The getter method for the membership field must also be moved to the superclass and removed from both the subclasses. You can check that you have done this correctly by running these methods of the JUnit test class called ClubTest: ● ● testSectionOneSuperClassFields testSectionOneSuperclassConstructor testSectionOnePlayerFields testSection OneCoach Fields testSectionOnePlayer Methods testSection OneCoach Methods Show that you have completed this exercise by showing that all the 'SectionOne' test methods have passed. Section 2 Exercise: For this exercise, you will only need to make changes to one class: Club The Club class has two ArrayList fields for separate lists of hockey players and coaches and its print Membership method iterates over each list separately. Players and coaches are added to the separate lists in the addTeam method. Change the Club class so that it has only one ArrayList field called members, instead of the two it has now. The ArrayList must store Member objects. The addTeam method will now add both players and coaches to that one list. The print Membership method will iterate over that list to print the members. You can check that you have done this correctly by running this method of the JUnit test class called Club Test: testSection TwoClubFields Show that you have completed this exercise by showing that the 'Section Two' test method has passed. Section 3 Exercise: For this exercise, you will only need to make changes to one class: Club Add a HashMap field called indexedMap to the Club class. The ArrayList members must not be removed. The new HashMap field must use the membership ID of a Member as its key and store Member objects as its values. Modify the addTeam method so that players and the coach are put into the HashMap as well as into the ArrayList. Add a method called lookup with the following header: /** * Get the Member with matching membership ID. * @param membership The membership ID to look up. * @return The matching member, or null if there isn't one. */ public Member lookup (String membership) You can check that you have done this correctly by running these methods of the JUnit test class called Club Test: testSection ThreeClubFields testSection ThreeClubLookup Method testSection ThreeLookup Exists ● testSection ThreeLookupDoesnt Exist ● Show that you have completed this exercise by showing that all the 'SectionOne' test methods have passed. The assignment If you have completed all the exercises above, but haven't completed parts 1 and 2 of the assignment, you need to try to finish these by the end of the class, if possible, to give yourself plenty of time to work on it before the deadline. Show your class supervisor what you have completed so far. Don't be tempted to leave before the end of the class if you still have work to do to complete these parts, because you can receive help within the class.