import java.io.*;
import java.util.*;
/**@author Erik Reinhart
* @date 9/3/2018
*The purpose of this program is to read in a text file Project1.txt and separate it into 2 arrays sorted by year.
*The program will read through the text and determine if the person on each line of the text file is either an
*Employee, Salesman, or Executive and then run their data through the respective classes.
*
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader input = null;
Scanner scan = new Scanner(System.in);
//reads in text file Project1.txt
String fileLine;
try {
input = new BufferedReader(new FileReader("Project1.txt"));
System.out.println("Employees:");
// Read one Line using BufferedReader
while ((fileLine = input.readLine()) != null) {
System.out.println(fileLine);
}
} catch (IOException io) {
System.out.println("File IO exception" + io.getMessage());
}finally {
// Need another catch for closing the streams
try {
if (input != null) {
input.close();
}
} catch (IOException io) {
System.out.println("Issue closing the Files" + io.getMessage());
}
}
//Class Testers
Employee emp = new Employee("Reinhart", "Erik", 2000);
Salesman sales1 = new Salesman("Reinhart", "Erik", 2000, 990000);
Salesman sales2 = new Salesman("Reinhart", "Erik", 2000, 1500000);
Executive exe1 = new Executive("Reinhart", "Erik", 2000, 50);
Executive exe2 = new Executive("Reinhart", "Erik", 2000, 55);
Executive exe3 = new Executive("Reinhart", "Erik", 2000, 45);
System.out.println(emp.empToString());
System.out.println(sales1.toString());
System.out.println(sales2.toString());
System.out.println(exe1.toString());
System.out.println(exe2.toString());
System.out.println(exe3.toString());
}//end main()
}//end class Main
/**@author Erik Reinhart
* @date 9/3/2018
* The Employee class is the Super class. It has the basic function of accepting a line read in from the text file
* Project1.txt and then displaying the information. It holds the toString() template used by the two sub classes,
* class Salesman and class Executive
*
*/
public class Employee {
//Variables
private String firstName;
private String lastName;
private double monthlySalary;
private double annualSalary;
//End Variables
//Constructor
public Employee(String lastName, String firstName, double monthlySalary) {
this.firstName = firstName;
this.lastName = lastName;
this.monthlySalary = monthlySalary;
}//End Constructor
//Setters and Getters
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getFirstName() {
return firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getLastName() {
return lastName;
}
public void setMonthlySalary(double monthlySalary) {
this.monthlySalary = monthlySalary;
}
public double getMontlySalary() {
return monthlySalary;
}
public void setAnnualSalary(double annualSalary) {
this.annualSalary = annualSalary;
}
public double getAnnualSalary() {
return annualSalary = monthlySalary * 12;
}//End Setters and Getters
//toString() template for all classes
public String toString() {
return ("\n\tName: " + lastName + ", " + firstName + "\n\tMonthly Salary: " + monthlySalary);
}//End toString
//Employee class toString()
public String empToString() {
return this.toString() + "\n\tAnnual Salary: " + this.getAnnualSalary();
}//End Employee class only toString
}//End class Employee
/**@author Erik Reinhart
* @date 9/3/2018
* The Salesman class reads in the last name, first name, monthly salary of the Salesman employee
* and adds a new instance "annualsSales" from the text file Project1.txt. This class will compute the total
* commission earned by multiplying annualSales * commissionRate. It will then test the value against the max
* commission using a if/else statement. If the totalCommission <= maxCommission, return totalCommission. Else,
* return maxCommission The information will then be displayed
*/
public class Salesman extends Employee {
//variables
private double annualSales;
private double totalCommission;
private double maxCommission;
private double commissionRate;
//end variables
//super constructor
public Salesman(String lastName, String firstName, double monthlySalary, double annualSales) {
super(lastName, firstName, monthlySalary);
this.annualSales = annualSales;
}//end super constructor
//Setters and Getters
public void setAnnualSales(double annualSales) {
this.annualSales = annualSales;
}
public double getAnnualSales() {
return annualSales;
}
public void setCommissionRate(double commissionRate) {
this.commissionRate = commissionRate;
}
public double getCommissionRate() {
return commissionRate = .02;
}
public void setTotalCommission(double totalCommission) {
this.totalCommission = totalCommission;
}
public double getTotalCommission() {
return totalCommission = (annualSales * this.getCommissionRate());
}
public void setMaxCommission(double maxCommission) {
this.maxCommission = maxCommission;
}
public double getMaxCommission() {
return maxCommission = 20000;
}
//End Setters and Getters
//Test to see if Salesman Commissions exceed the limit of 20,000
public double maxCommissionTest() {
if (this.getTotalCommission() <= this.getMaxCommission())
return this.getTotalCommission();
else
return this.getMaxCommission();
}//End test
//Adds Salesman class details to Employee.toString
public String toString() {
return super.toString() + "\n\tAnnual Sales: " + annualSales + "\n\tCommission: " + this.maxCommissionTest();
}//End toString
}//End class Salesman
/**@author Erik Reinhart
* @ 9/3/2018
* The Executive class reads in the last name, first name, and monthly salary of the Executive employee and adds
* a new instance "stockPrice" from the text file Project1.txt. This class will test the stockPrice to determine
* if the Executive employee will receive a bonus of 30,000 by using a if/else statement. If, stockPrice > 50,
* employee receives bonus. Else, employee receives noBonus. It is then displayed
*
*/
public class Executive extends Employee {
//Variables
private double stockPrice;
private double bonus;
private double noBonus;
//End Variables
//super constructor
public Executive(String lastName, String firstName, double monthlySalary, double stockPrice) {
super(lastName, firstName, monthlySalary);
this.stockPrice = stockPrice;
}//end super constructor
//Setters and Getters
public void setStockPrice(double stockPrice) {
this.stockPrice = stockPrice;
}
public double getStockPrice() {
return stockPrice;
}
public void setBonus(double bonus) {
this.bonus = bonus;
}
public double getBonus() {
return bonus = 30000;
}
public void setNoBonus(double noBonus) {
this.noBonus = noBonus;
}
public double getNoBonus() {
return noBonus;
}//End Setters and Getters
//Test to determine if the Executive gets a bonus or not
public double bonusTest() {
if (this.getStockPrice() > 50)
return this.getBonus();
else
return this.getNoBonus();
}//End Test
//Adds Executive class details to Employee.toString()
public String toString() {
return super.toString() + "\n\tStock Price: " + stockPrice + "\n\tBonus: " + this.bonusTest();
}//End toString
}//End class Executive