Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I posted a question and forgot to include the code for manager's class. An expert repied with some suggestions. I have done that but my

I posted a question and forgot to include the code for manager's class. An expert repied with some suggestions. I have done that but my stuck. the manager class need tiding. Below is the reply from the expert , code for manager class and what I want to achieve

expert reply

Hi, there was a very minor mistake in the initialization of the Employee objects in the main. The first Two attributes were swapped, hence the error related to the data types.

There was another mistake in the initializations. you were passing a String instead of a Manager object. So I made a sample Manager class to get it to work on my side. So, the output may be slightly different from what you expect. You may remove/ replace it.

I've bolded the modifications

please drop a comment if there's a problem

//----------OUTPUT-----------

Ari 1 John

Jon 2 John

//----------------------------------

public class Employee {

// instance variables

private String name;

private int id;

private Manager manager;

/**

* Constructor for objects of class Employee

*/

public Employee(int id, String name, Manager manager) {

// initialise instance variables

super();

this.name = name;

this.id = id;

this.manager = manager;

}

/**

* Getter for theemployee's manager.

*/

public Manager getManager() {

return this.manager;

}

/**

* Setter for a employee's manager.

*/

public void setManager(Manager manager) {

this.manager = manager;

}

/**

* Getter for a employee's name.

*/

public String getName() {

return this.name;

}

/**

* Setter for a employee's name.

*/

public void setName(String name) {

this.name = name;

}

/**

* Getter for a employee's id.

*/

public int getId() {

return this.id;

}

/**

* Setter for a employee's id.

*/

public void setId(int id) {

this.id = id;

}

/**

* Returns a string describing this object.

*/

@Override

public String toString() {

return name + " " + id + " " + manager;

}

public static void main(String args[]) {

Manager John=new Manager("John");

Employee e1 = new Employee(01, "Ari", John);

Employee e2 = new Employee(02, "Jon", John);

System.out.println(e1);

System.out.println(e2);

}

//

}

class Manager{

String name;

Manager(String name){

this.name=name;

}

public String toString(){

return name;

}

};

my manager code

public class Manager extends Employee { private String name;

private int yearOfAppointment;

/** * Constructor for objects of class Manager */ public Manager(String name,int id,Manager theManager, String yearOfAppointment) { super(name,id,theManager); this.name = name; this.yearOfAppointment = 2018; } /** * Getter for the manager's name. */ public String getName() { return this.name; } /** * Setter for the manager's name. */ public void setName(String name) { this.name = name; } /** * Getter for the manager's year of appointmrnt. */ public int getYearOfAppointment() { return this.yearOfAppointment; } /** * Setter for an artist's year of birth. */ public void setYearOfAppointment(String aYearOfApppintment) { this.yearOfAppointment = yearOfAppointment; } /** * Setter for an artist's year of birth. */ public void main(String[] args) { { if (yearOfAppointment >= 2018 && yearOfAppointment <= 2020) this.yearOfAppointment = yearOfAppointment; else {

yearOfAppointment = 2018; } } }

// public void print() { System.out.println("I'm a new manager"); System.out.println(this.getName()); System.out.println(this.getId()); System.out.println(this.getManager()); System.out.println(this.getYearOfAppointment()); } manager(String name){ this name = name; } public String toString(){ return this name; } /** * Returns a string describing this object. */ @Override public String toString() { return ""; }

what i want the code to achieve

One class (the composite class) should have an instance variable that references an instance of the other class (the component class). This represents the has-a relationship between the classes.

In addition to the instance variable described above, each class should have at least two instance variables that represent attributes. It is not advisable to have more than the minimum number of instance variables unless you are confident of what you are doing and can spare the extra time.

The composite class should have a method, other than toString(), that sends its component object a message and makes use of the message answer in a computation of some sort.

Further requirements:

Each class should include at least one constructor with one or more arguments. In most cases you will need only one per class.

Each class should have, where appropriate, getter and setter methods for each of its instance variables.

Each class should have a method toString() that returns a description of an object of that class as a String that would be meaningful to a human reader.

The toString() method in the composite class must include at least one item of information obtained from the component object by sending it a message.

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

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

2. When is the job to be completed?

Answered: 1 week ago

Question

What are the steps involved in the HR planning process?

Answered: 1 week ago