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:...
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)
<<<<<<<<. 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    *...
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...
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...
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...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
DISCUSS three employee benefits such as medical insurance, vacation and holidays and retirement plan or other...
DISCUSS three employee benefits such as medical insurance, vacation and holidays and retirement plan or other three employee benefits that are on top of your list should you chose to work for an employer. Why are the benefit you've identified important to you?
A incomplete definition of a class Temperature is given below: public class Temperature { private double...
A incomplete definition of a class Temperature is given below: public class Temperature { private double value[] = {36.5, 40, 37, 38.3}; } [6] (i) Copy and put it in a new class. Write a method toString() of the class, which does not have any parameters and returns a string containing all the values separated by newlines. When the string is printed, each value should appear on a line in the ascending order of their indexes. Copy the content of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT