Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This code needs to be edited: public class HockerPlayer { String name; int id; public HockerPlayer() { } public HockerPlayer(String name, int id) { this.name

This code needs to be edited:

public class HockerPlayer { String name; int id; public HockerPlayer() { } public HockerPlayer(String name, int id) { this.name = name; this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } } \color{blue}\underline{HockerPlayerTest.java:} import java.util.Scanner; public class HockerPlayerTest { public static void main(String args[]){ //Array of 3 hockey players HockerPlayer hockerPlayers[] = new HockerPlayer[3]; Scanner scanner = new Scanner(System.in); //Reading hockey players from console for(int i = 0;i

image text in transcribed

Overview: In this lab, you will continue the HockeyPlayer example from your last assignment. You will create a new HockeyStick class representing a hockey stick, and HockeyPlayer will have an aggregation (has-a) relationship with HockeyStick A. Hockey Stick class Start by creating a class HockeyStick. It should have two instance fields: a string variable brand, and a dub1 vanable price Give this class a constructor and getters and setters for the instance fields. At this point in the term, it should be easy for you to create such a class and its instance fields, constructors, and getterisetter methods B. HockeyPlayer class, Revision I You can start with the HockeyPlayer class from your assignment. If you don't have it handy, you can spend 5-10 minutes creating a new HockeyPlayer class. Add a new instance field of type HockeyStick to the HockeyPlayer class (in addition to the name and jersey number instance fields). This represents the fact that a hockey player"has-a' hockey stick private HockeyStick stick; You should now revise the HockeyPlayer constructor to take an additional HockeyStick parameter and set the instance field accordingly. You also need to provide a getter and a setter for the stick instance field. One option for getHockeyStick() would look like this l not best practice! public HockeyStick getHockeystick) return stick However, be aware that the getter method getHockeyStick0 would be violating best practices by actually returning the private HockeyStick object as shown. The reason is that it would really be returning the address of the object, and so some external class could then modify the same HockeyStick object. What we really want is to return a duplicate of the HockeyStick object. The easiest way to do that is with a copy constructor, which is what you will do in the next section. C. Hockey Stick class, Revision I Go back to the HockeyStick class and add a second constructor (keep the first one). The second constructor should take a HockeyStick object as its only parameter, and should set the instance fields to be identical to the instance fields of the HockeyStick object parameter. That way, when we create a HockeyStick object using the copy constructor and passing a HockeyStick to the constructor, the new HockeyStick is an identical duplicate of the first. D. HockeyPlayer class, Revision II You can now go back to the HockeyPlayer class and create the getHockeyStick) method. This method should return a duplicate of the HockeyStick instance field, by creating a new object using the copy constructor of the HockeyStick class. E. Hockey Tester Create a tester class with a main) method. Create a HockeyStick and a HockeyPlayer who uses that HockeyStick object. Verify that calling getHockeyStick) and modifying the returned object (eg. changing the brand name) does not actually change the object that the HockeyPlayer object is using (e.g. the brand name of the original object will stay the same). Deliverables: Submit HockeyPlayer.java, HockeyStick.java and your tester class in a zip file

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

More Books

Students also viewed these Databases questions

Question

What is the name of the program?

Answered: 1 week ago

Question

Language in Context?

Answered: 1 week ago