Java Programming Exercises

Java Programming Exercises

Please do exercises 7.2 and 7.3. You do not need to do 7.1, but you may refer to the answer of 7.1 (Attached as PDF)

Exercise 7.1:

Write the UML diagram first, then write the class in Java for the Commissioned class (details below).

The superclass given here is called Employee. The UML class diagram and class in attached file called “Employee Class Example”. One subclass of Employee (called Salaried) is also shown in the same file.

Write another subclass of Employee called Commissioned. The Commissioned class has a private instance variable for commission rate. Include a constructor, accessor method, mutator method (for the commision rate) and toString method.

Answer: Attached PDF

Exercise 7.2:

Using the example code for the abstract Employee class (Attached), write a subclass of the abstract Employee class called Commissioned, which includes private instance variables for amount sold and commission rate, and a constructor that includes parameters to initialize those as well as the superclass variables. Don’t forget to override the computePay method (just multiply the amount sold times the commission rate). Write a driver program that will contain an array Employee objects, initialized to instances of Commissioned and Salaried shown below. Then write a loop to print the toString AND return value of computePay on each Employee array element (you DON’T need to check if Salaried or Commissioned!)

Employee [] empArray= new Employee[] {
new Commissioned(“Donald Duck”, “123-45-6789”, 5000.0, 0.22),
new Salaried(“Mickey Mouse”, “987-65-4321”, 100000.),
new Salaried(“Bugs Bunny”, “121-21-2121”, 90000.),
new Commissioned(“Elmer Fudd”, “343-43-4343”, 3000., 0.25) };
UPLOAD ONLY THE Commissioned.java file and the driver file.

Exercises 7.3:

Write an interface called Comparable that has an instance method that returns an int called compareTo with 1 Object parameter. (Note that there is a library interface for this, but don’t use the library version, write it as an exercise.) Modify the Employee class from Exercise 7.1 to implement this interface. Override the compareTo (be sure to cast the parameter appropriately) to first compare the names (use compareToIgnoreCase), but if they’re the same, compare the SSNs using compareTo (don’t compare Strings using ==). The return value should be either the result of compareToIgnoreCase for the names (if not 0) or compareTo for the SSNs (if the names are the same).

"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.


Discount Code: CIPD30



Click ORDER NOW..

order custom paper