Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The first programming project involves writing a program that computes the salar

ID: 3882880 • Letter: T

Question

The first programming project involves writing a program that computes the salaries for a collection of employees of different types. This program consists of four classes.

1. The first class is Employee, which contains the employee's name and monthly salary which is specified in whole dollars. It should have three methods: a. A constructor that allows the name and monthly salary to be initialized. b. A method named annualSalary that returns the salary for a whole year. c. A toString method that returns a string containing the name and monthly salary, appropriately labeled. The Employee class has two subclasses: Salesman and Executive.

2. The Salesman class has an additional instance variable that contains the number of sold items. It should have the same three methods: a. A constructor that allows the name, monthly salary and number of sold items to be initialized. b. An overridden method annualSalary that returns the salary for a whole year. The salary for a salesman consists of the base salary computed from the monthly salary plus a commission. The commission is zero if the number of sold items is less than 200, equal to one month salary if the number of sold items is between 200 and 300 and equal to two month salary if the number of sold items is 300 or more. c. An overridden toString method that returns a string containing the name, monthly salary and number of sold items, appropriately labeled.

3. The Executive class has an additional instance variable that reflects the current stock price. It should have the same three methods: a. A constructor that allows the name, monthly salary and stock price to be initialized. b. An overridden method annualSalary that returns the salary for a whole year. The salary for an executive consists of the base salary computed from the monthly salary plus a bonus. The bonus is $20,000 if the current stock price is greater than $100 and nothing otherwise. c. An overridden toString method that returns a string containing the name, monthly salary and stock price, appropriately labeled.

4. Finally there should be a fourth class P1Driver that contains the main method. It should read in employee information from a text file inputData.txt. The file will contain employee information for only two years: 2015 and 2016. Each line of the text file will represent the information for one employee for one year. An example of how the text file will look is shown below: 2015 Employee Smithson,John 2000 2016 Salesman Jokey,Will 3000 236 2015 Executive Obama,Barack 5000 150 The year is the first data element on the line. Next is the type of the employee followed by the employee name and the monthly salary. For salesmen, the final value is the number of sold items and for executives the stock price. As the employees are read in, Employee objects of the appropriate type should be created and stored in an array depending upon the year. There should be two arrays, one corresponding to 2015 and one corresponding to year 2016. You may assume that the file will contain no more than 200 employee records for each year and that 2 the data in the file will be formatted correctly. Once all the employee data is read in, a report should be displayed on the console for each of the two years. Each line of the report should contain all original data supplied for each employee together with that employee's annual salary for the year. The last line of the report should display the total number of employees and the average of all salaries for that year. Your program should compile without errors. The Google recommended Java style guide (https://google.github.io/styleguide/javaguide.html), should be used to format and document your code.

Explanation / Answer

Given below are the classes needed for the question. Hope it helps. If it does , please don't forget to rate the answer. Thank you very much.

Employee.java



public class Employee {
protected String name;
protected double monthlySalary;
public Employee(String name1, double monthlySal1)
{
name = name1;
monthlySalary = monthlySal1;
}
public double annualSalary()
{
return 12 * monthlySalary;
}
public String toString()
{
return "Name: " + name + " Monthly Salary: $" + monthlySalary;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getMonthlySalary() {
return monthlySalary;
}
public void setMonthlySalary(double monthlySalary) {
this.monthlySalary = monthlySalary;
}
}

Salesman.java


public class Salesman extends Employee {
private int itemsSold;
public Salesman(String name1, double monthlySal1, int itemsSold1)
{
super(name1, monthlySal1);
itemsSold = itemsSold1;
}
@Override
public double annualSalary()
{
double total = super.annualSalary();
double commission = 0;
if(itemsSold >= 200 && itemsSold < 300)
commission = monthlySalary;
else if (commission >= 300)
commission= 2 * monthlySalary;
total += commission;
return total;
}
public int getItemsSold() {
return itemsSold;
}
public void setItemsSold(int itemsSold) {
this.itemsSold = itemsSold;
}
public String toString()
{
return super.toString() + " Items Sold: " + itemsSold;
}
}

Executive.java



public class Executive extends Employee {
private double stockPrice;
public Executive(String name1, double monthlySal1, double stkPrice1)
{
super(name1, monthlySal1);
stockPrice = stkPrice1;
}
public double annualSalary()
{
double total = super.annualSalary();
if(stockPrice > 100)
total += 20000; //add bonus
return total;
}
public double getStockPrice() {
return stockPrice;
}
public void setStockPrice(double stockPrice) {
this.stockPrice = stockPrice;
}
public String toString()
{
return super.toString() + " Stock Price: $" + stockPrice;
}
}

P1Driver.java



import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class P1Driver {
private static void showEmployeeDetails(int year, Employee[] emps, int count)
{
double avg = 0;
System.out.println("Report of the year " + year);
for(int i = 0; i < count; i++ )
{
avg += emps[i].annualSalary();
System.out.println(emps[i]);
}
avg /= count;
System.out.println(" Average annual salary: $" + avg);
System.out.println("---------------------------------- ");
}
public static void main(String[] args) {
Employee[] emps2015, emps2016;
int count1 = 0 , count2 = 0;
emps2015 = new Employee[200];
emps2016 = new Employee[200];
try {
Scanner infile = new Scanner(new File("inputData.txt"));
int year, itemsSold;
String type, name;
double monthlySal, stockPrc;
Employee e;
while(infile.hasNext())
{
year = infile.nextInt();
type = infile.next();
name = infile.next();
monthlySal = infile.nextDouble();
if(type.equals("Salesman"))
{
itemsSold = infile.nextInt();
e = new Salesman(name, monthlySal, itemsSold);
}
else if (type.equals("Executive"))
{
stockPrc = infile.nextDouble();
e = new Executive(name, monthlySal, stockPrc);
}
else
e = new Employee(name, monthlySal);
if(year == 2015)
emps2015[count1++] = e;
else
emps2016[count2++] = e;
}
infile.close();
showEmployeeDetails(2015, emps2015, count1);
showEmployeeDetails(2016, emps2016, count2);
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
}
}

input file: inputData.txt

2015 Employee Smithson,John 2000
2016 Salesman Jokey,Will 3000 236
2015 Executive Obama,Barack 5000 150
2015 Employee Jackson,Michael 3000
2015 Salesman William,Robert 2000 350
2016 Executive Trumph,Donald 4000 80

output


Report of the year 2015
Name: Smithson,John Monthly Salary: $2000.0
Name: Obama,Barack Monthly Salary: $5000.0 Stock Price: $150.0
Name: Jackson,Michael Monthly Salary: $3000.0
Name: William,Robert Monthly Salary: $2000.0 Items Sold: 350
Average annual salary: $41000.0
----------------------------------
Report of the year 2016
Name: Jokey,Will Monthly Salary: $3000.0 Items Sold: 236
Name: Trumph,Donald Monthly Salary: $4000.0 Stock Price: $80.0
Average annual salary: $43500.0
----------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote