Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Here is the complete Java program that includes the Department class its subclasses Production Accounting Marketing and the Departments driver class t...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started