Question

In: Computer Science

Exercise: Three UML class diagrams are given below. Class Employee is the superclass and the other...

Exercise: Three UML class diagrams are given below. Class Employee is the superclass and the other two classes, Manager and Programmer, are subclasses of Employee.
Employee

- name: String
# salary: double
+ Employee( )
+ setEmployee( String, double ): void
+ getName( ): String
+ getSalary( ): double
+ print( ): void
Manager


Programmer

- numEmps: int
- language: String
+ Manager( )
+ setManager( String, double, int ): void
+ getNumEmps( ): int
+ getSalary( ): double
+ print( ): void [overridden]
+ Programmer( )
+ setProgrammer( String, double, String ): void
+ getLanguage( ): String
+ getSalary( ): double
+ print( ): void [overridden]
Note: The symbols -, #, and + mean private, protected, and public members respectively.
Answer the following questions based on the above diagrams:​
1.
Write the Java statement that makes the class Manager inherits the class Employee.
2.
Implement the default constructor of the class Manager.
3.
Implement the method setEmployee( … ) of the class Employee.
4.
Implement the method setProgrammer( … ) of the class Programmer.
5.
Implement the method getSalary( ) of the class Manager.
6.
Implement the overridden method print( ) of the class Manager.
7.
Declare an object named m of type Manager. Use the method setManager( … ) to set name, salary, and number of employees of object m to "Saleh Khalid", 17310, and 35.




8. Declare an object named p of type Programmer. Use the method setProgrammer( … ) to set name, salary, and language of object p to "Ahmed Hasan", 8550, and "Java".



9. Declare a reference variable named e of type Employee. Make e a reference to m. What e.print() will print? Then make e a reference to p. What e.print() will print?

Solutions

Expert Solution

class Employee
{ 
    String name;
    protected double salary;
    Employee()
    {
        
    }
    public void setEmployee( String n, double s)
    {
        name=n;
        salary=s;
    }
    public String getName( )
    {
        return name;
    }
    public double getSalary( )
    {
        return salary;
    }
    public void print( )
    {
        System.out.println("Name: "+name+" Salary: "+salary);
    }
}

class Manager extends Employee
{
    int numEmps;
    Manager()
    {
        
    }
    public void setManager( String n, double s, int e)
    {
        name=n;
        salary=s;
        numEmps=e;
    }
    public int getNumEmps()
    {
        return numEmps;
    }
    public double getSalary()
    {
        return salary;
    }
    public void print()
    {
        System.out.println("Name: "+name+" Salary: "+salary+" NumEmps: "+numEmps);
    }
}

class Programmer extends Employee
{
    
    String language;
    
    Programmer()
    {
        
    }
    public void setProgrammer(String n, double s, String l)
    {
        name=n;
        salary=s;
        language=l;
    }
    public String getLanguage()
    {
        return language;
    }
    public double getSalary( )
    {
        return salary;
    }
    public void print()
    {
        System.out.println("Name: "+name+" Salary: "+salary+" Language: "+language);
    }
    
}
class main
{
    public static void main (String[] args) 
    {
        Programmer p= new Programmer();
        p.setProgrammer("Ahmed Hasan", 8550,"Java");
        
        Manager m=new Manager();
        Employee e=m;
        e.print();
        e=p;
        e.print();
    }
}

I hope it helps.


Related Solutions

Use the UML tool to draw a UML class diagrambased on the descriptions provided below....
Use the UML tool to draw a UML class diagrambased on the descriptions provided below.The diagram should be drawn with a UML toolIt should include all the classes listed below and use appropriate arrows to identify the class relationshipsEach class should include all the described attributes and operations but nothing elseEach constructor and method should include the described parameters and return types - no more and no lessPlease do one of the following in JavaDescriptions of a PriceBecause of the...
Write a Java class called Employee (Parts of the code is given below), which has three...
Write a Java class called Employee (Parts of the code is given below), which has three private fields firstName (String), lastName (String) and yearsEmployed (double). Implement accessor/mutator methods for the private fields and toString() method, that returns a String representation, which contains employee name and years she was employed. public class Employee { private String firstName; ... } Write a client program called EmployeeClient that creates an instance of Employee class, sets values for the fields (name: John Doe, yearsEmployed:...
Given the following UML class diagram, implement the class as described by the model. Use your...
Given the following UML class diagram, implement the class as described by the model. Use your best judgment when implementing the code inside of each method. +---------------------------------------------------+ | Polygon | +---------------------------------------------------+ | - side_count : int = 3 | | - side_length : double = 1.0 | +---------------------------------------------------+ | + Polygon() | | + Polygon(side_count : int) | | + Polygon(side_count : int, side_length : double) | | + getSides() : int | | + setSides(side_count : int) | |...
Using UML, design a class that allows you to store and print employee information: name, id,...
Using UML, design a class that allows you to store and print employee information: name, id, and hourly_salary. Include the appropriate mutator and accessor methods. Write the code to create the class. Write a test program that instantiates an employee object. After the object is created write the code to give the employee a 3% raise. (IN PYTHON)
21. Consider the code below: [13] Employee class: class Employee { public: Employee(string theName, float thePayRate);...
21. Consider the code below: [13] Employee class: class Employee { public: Employee(string theName, float thePayRate); protected: string getName() const; float getPayRate() const; float pay(float hoursWorked) const; private: string name; float payRate; }; Definitions for some of the methods follow: Employee::Employee(string theName, float thePayRate) { name = theName; payRate = thePayRate; } float Employee::pay(float hoursWorked) const { return hoursWorked * payRate; } Manager Class: #include "employee.h" class Manager : public Employee { public: Manager(string theName, float thePayRate, bool isSalaried); protected:...
<<<<<<<<. I need the UML diagram for all classes.java below. >>>>> // Vehicle.java public class Vehicle...
<<<<<<<<. I need the UML diagram for all classes.java below. >>>>> // Vehicle.java public class Vehicle {    // data members declared as private    private String make;    private double weight;    private double height;    private double length;    private int maxSpeed;    private int noOfDoors;    private int numberSeats;    /**    * @param make    * @param weight    * @param height    * @param length    * @param maxSpeed    * @param noOfDoors    *...
Exercise 14.1 The number of movies attended in the preceding three months are given below for...
Exercise 14.1 The number of movies attended in the preceding three months are given below for 30 people. Calculate the mean, the median, the mode, and the range. Show your work. Interpret each statistic. 0 15 26 8 2 3 11 13 0 3 0 1 17 1 9 7 4 18 12 10    10 4 2 7 2 2 5 9 6 6 1. Calculate the mean and interpret the results. 2. Calculate the median and interpret the...
In-class exercise Given below is a Trial Balance of Aliba Trading on 30 June 2019. Aliba...
In-class exercise Given below is a Trial Balance of Aliba Trading on 30 June 2019. Aliba Trading Trial Balance as at 30 June 2019 Debit Credit RM RM Building 60,000 Fixtures and fittings 12,000 Office equipment 10,000 Inventory (1 July 2018) 13,500 Bank 3,450 Cash 2,340 Debtors and creditors 6,300 8,500 Loans 15,000 Capital 70,000 Drawings 1,250 Purchases 51,150 Sales 72,500 Sales returns 900 Purchase returns 400 Carriage inwards 1,100 Purchase discount 680 Sales discount 400 Wages expense 8,000 Interest...
GIVEN THE CODE BELOW Given the following class: /** * Document class. */ public class Document...
GIVEN THE CODE BELOW Given the following class: /** * Document class. */ public class Document { private int words; /** * constructor * pre: none * post: A Document object created. Words initialized to 0. */ public Document() { words = 0; //default words } /** * Changes the number of document words. * pre: none * post: Words has been changed. */ public void setWords(int numWords) { words = numWords; } /** * Calculates the number of pages....
Given the following UML class diagram, implement the class as described by the model. Use your best judgement when implementing the code inside of each method.
In java Given the following UML class diagram, implement the class as described by the model. Use your best judgement when implementing the code inside of each method.+------------------------------+| Circle |+------------------------------+| - radius : double = 1.0 |+------------------------------+| + Circle(radius : double) || + getRadius() : double || + setRadius(radius : double) || + area() : double || + perimeter() : double |+------------------------------+The following information might also be useful:Formula for area of a circle with radius r:       A = πr^2Formula for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT