Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am trying to add year2015List array to work with my year2014List but I am having trouble. ------------------------------------------------------------------------------------------------------------------------------ package employee; public class Employee { protected

I am trying to add year2015List array to work with my year2014List but I am having trouble.

------------------------------------------------------------------------------------------------------------------------------

package employee;

public class Employee { protected double monthlySalary; protected String name;

public Employee(String name){ this.name = name; } public Employee(String name, double monthlySalary){ this.name = name; this.monthlySalary = monthlySalary;

}

private double getAnnualSalary() { double annualSalary = monthlySalary * 12; return annualSalary; }

public String toString(){ return " Name: " + name + " Monthly Salary: " + monthlySalary + " Annual Salary:" + getAnnualSalary(); }

}

/////////////////////

package employee;

public class Salesman extends Employee { private double commission; private double annualSales; private double annualSalary;

public Salesman(String name,double montlySalary,double annualSales) { super(name); this.monthlySalary=montlySalary; this.annualSales = annualSales; this.commission = annualSales*.02; if (this.commission > 20000){ this.commission = 20000; } }

private double getAnnualSalary() { annualSalary = monthlySalary*12 + commission; return annualSalary; }

public String toString() { return " Name: " + name + " Monthly Salary: " + monthlySalary + " Annual Salary (including commission):" + getAnnualSalary() + " Annual Sales: " + annualSales;

}

}

//////////////////////////

package employee;

public class Executive extends Employee{ private double bonus; private double stockPrice; double annualSalary; public Executive(String name, double montlySalary, double stockPrice) { super(name); this.stockPrice = stockPrice; this.monthlySalary = montlySalary; if (this.stockPrice >= 50){ this.bonus = 30000; } if(this.stockPrice < 50){ this.bonus = 0; } }

private double getAnnualSalary() { annualSalary = monthlySalary*12 + bonus; return annualSalary; }

public String toString() { return " Name: " + name + " Monthly Salary: " + monthlySalary + " Annual Salary (including bonus):" + getAnnualSalary() + " Stock Price: " + stockPrice; }

}

//////////////////////////////

package employee;

import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.util.ArrayList;

public class Main {

public static void main(String[] args){ ArrayList year2014List= new ArrayList(); ArrayList year2015List= new ArrayList(); try{ File file = new File("EmployeeList.txt"); FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); String line; while((line = br.readLine()) != null){ String[] tokens=line.split(" "); if(Integer.parseInt(tokens[0])==2014) { switch(tokens[1]){ case "Employee": Employee e= new Employee(tokens[2],Integer.parseInt(tokens[3])); year2014List.add(e); break; case "Salesman": Employee s= new Salesman(tokens[2],Integer.parseInt(tokens[3]),Integer.parseInt(tokens[4])); year2014List.add(s); break; case "Executive": Employee ex= new Executive(tokens[2],Integer.parseInt(tokens[3]),Integer.parseInt(tokens[4])); year2014List.add(ex); break; default: } } } System.out.println("Generating Output.."); for(Employee e : year2014List) { System.out.println(e.toString()); } } catch(Exception e){ }

} }

////////////////////////////////////

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building The Data Lakehouse

Authors: Bill Inmon ,Mary Levins ,Ranjeet Srivastava

1st Edition

1634629663, 978-1634629669

More Books

Students also viewed these Databases questions