Objectives: • Create a class hierarchy that is useful for solving different kind
ID: 3636760 • Letter: O
Question
Objectives:• Create a class hierarchy that is useful for solving different kinds of real-world problems by modeling people and types of people.
• Explore how inheritance works in java (is-a).
• Explore some common models for inter-class relationships including aggregation (has-a).
1. Create a Netbeans project called ClassDesign.
2. Now create a new java class file called Person.java
Persons have these fields:
firstName (String)
lastName (String)
ID (String)
Make all fields private and use Netbeans to auto create the accessor/mutators
Create a default constructor
Create another constructor that takes 3 parameters for the 3 fields
Use Netbeans to implement a toString method to reasonably display the Person info
3. Now create a java main file ClassDesignRunner.java
Create an array of 3 person objects
Write a for loop that displays the array (prints out the person objects to the console)
4. Create a new java class file called Worker.java
Worker inherits from Person
Workers are Persons that have the following additional fields:
employerName (String)
hourlyPayRate (double)
Create appropriate constructors: at least one that takes all the fields
(Be sure to use the super() technique to call the parent constructor in Person.
This must be the first statement in the constructor.)
Add accessor and mutators for the new fields
Override the toString method to display the new field info in addition to the inherited fields. You might be able to very cleverly call the toString() in the parent class within the toString() of the child class you do this with super.toString().
Code a method: double calculateHourlyPay(int hourWorked)
that returns the amount of pay for a given number of hours
Add more code to your ClassDesignRunner.java file:
- Create an array of 3 worker objects with different hourly rates
- Code a for loop that displays the amount earned for 8 hours of work
5. Create another java class file called Shop.java
Shops have these fields:
name (String) the name of the business
employees (an Arraylist that holds worker objects)
- Implement an addEmployee method
- Implement the toString method
6. Add additional code in your ClassDesignRunner.java main class:
- Write code to create a shop instance
- Add 3 workers with different hourly rates
- Code a for loop that displays the amount earned by each for 8 hours of work
Explanation / Answer
public class GraphSceneImpl extends GraphScene { public GraphSceneImpl() { } @Override protected Widget attachNodeWidget(Object node) { return null; } @Override protected Widget attachEdgeWidget(Object edge) { return null; } @Override protected void attachEdgeSourceAnchor(Object edge, Object oldSourceNode, Object newSourceNode) { } @Override protected void attachEdgeTargetAnchor(Object edge, Object oldTargetNode, Object newTargetNode) { }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.