Question
public class Account { private String name; private int accountNum; private double salary; public Account(String name, int accountNum, double salary) { this.name = name; this.accountNum
public class Account { private String name; private int accountNum; private double salary; public Account(String name, int accountNum, double salary) { this.name = name; this.accountNum = accountNum; this.salary = salary; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAccountNum() { return accountNum; } public void setAccountNum(int accountNum) { this.accountNum = accountNum; } public double getSalary() { return salary; } public void setSalary(double salary) { this.salary = salary; } public static void main(String[] args) { Account[] acts=new Account[5]; double average=0; double total=0; acts[0]=new Account("A", 12345, 25000); acts[1]=new Account("B", 53453, 34000); acts[2]=new Account("C", 34564, 45900); acts[3]=new Account("D", 87898, 10000); acts[4]=new Account("E", 678793, 50000); for (int i = 0; i < acts.length; i++) { total=total+acts[i].getSalary(); } average=total/acts.length; System.out.println("Average salary : "+average); System.out.println("Account having salary more than average salary"); for (int i = 0; i < acts.length; i++) { if(acts[i].getSalary()>average) { System.out.printf("%-20s%-20.2f ", acts[i].getName(), acts[i].getSalary()); } } } }
Q: In Above program Add inheritance and polymorphism
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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