Question: Write a Java program to create a class named Department. In this class, there are three subclasses, namely Production, Accounting, and Marketing, each of

Write a Java program to create a class named Department. In this class, there are three subclasses, namely Production, Accounting, and Marketing, each of which has two member methods named addStaff and displayRevenue. Create these using polymorphism concepts. addStaff method accepts as its input the name of an employee, while the displayRevenue method simply prints the revenue of the department. Use the driver class in Listing 2 to test your program. Listing 2: Departments driver class public class Departments{ /** */ Randomly create the department objects public static Department randomDept() { switch((int)(Math.random()*3)) { case 0: return new Production(); case 1: return new Accounting(); } case 2: return new Marketing(); default: System.out.println("Default"); return new Department(); } public static void main(String args[]) { } Department depts[] = new Department[5]; for(int i=0; i
Step by Step Solution
There are 3 Steps involved in it
Here is the complete Java program that includes the Department class its subclasses Production Accounting Marketing and the Departments driver class t... View full answer
Get step-by-step solutions from verified subject matter experts
