Question

I really need help with this, please. This is a java programming assignment.

Project 1

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 the Employee class, 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.

2. The Employee class has two subclasses.

The first is Salesman. It has an additional instance variable that contains the annual sales in whole dollars for that salesman. It should have the same three methods:

a. A constructor that allows the name, monthly salary and annual sales 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 computed as 2% of that salesman's annual sales. The maximum commission a salesman can earn is $20,000.

c. An overridden toString method that returns a string containing the name, monthly salary and annual sales, appropriately labeled.

3. The second subclass is Executive. It 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 $30,000 if the current stock price is greater than $50 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 that contains the main method. It should read in employee information from a text file. 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:

2014 Employee Smith,John 2000

2015 Salesman Jones,Bill 3000 100000

2014 Executive Bush,George 5000 55

The year is the first data element on the line. The file will contain employee information for only two years: 2014 and 2015.

Next is the type of the employee followed by the employee name and the monthly salary.

For salesmen, the final value is their annual sales and for executives the stock price.

As the employees are read in, Employee objects of the appropriate type should be created and they should be stored in one of two arrays depending upon the year.

You may assume that the file will contain no more than ten employee records for each year and that 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 2 that employee's annual salary for the year. For each of the two years, an average of all salaries for all employees for that year should be computed and displayed.

This is what the output has to look like:

Annual Pay Employee name Monthly Pay Sales Stock Туре Bonus John Smith Employee 9999 99999 George Bush Executive 9999 99 9999

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Employee.java

public class Employee {
   String name;
   int monthlySalary;
  
   Employee(String name, int monthlySalary) {
       this.name = name;
       this.monthlySalary = monthlySalary;
   }
  
   public int annualSalary() {
       return monthlySalary * 12;
   }
  
   public String toString() {
       return ("Name: " + name + " Salary: " + monthlySalary);
   }
}

Salesman.java


public class Salesman extends Employee{
  
   int sales;
  
   Salesman(String name, int monthlySalary, int sales) {
       super(name, monthlySalary);
       this.sales = sales;
   }
  
   @Override
   public int annualSalary() {
       return super.annualSalary() + Math.min(sales/50, 20000);
   }
  
   @Override
   public String toString() {
       return (super.toString() + " Sales: "+sales);
   }

}


Executive.java


public class Executive extends Employee{
   int stock;
  
   Executive(String name, int monthlySalary, int stock) {
       super(name, monthlySalary);
       this.stock = stock;
   }
  
   @Override
   public int annualSalary() {
       int bonus = 0;
       if(stock > 50)
           bonus = 30000;
       return super.annualSalary() + bonus;
   }
  
   @Override
   public String toString() {
       return (super.toString() + " Stock:" +stock);
   }
}


MainClass.java

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class MainClass {

   public static void main(String[] args) {
      
       ArrayList<Employee> array2014 = new ArrayList<Employee> ();
       ArrayList<Employee> array2015 = new ArrayList<Employee> ();
      
       BufferedReader in = null;
       try {
           in
           = new BufferedReader(new FileReader("input.txt"));
       } catch (FileNotFoundException e) {
           e.printStackTrace();
       }
      
       while(true) {
           String line = null;
           try {
               line = in.readLine();
           } catch (IOException e) {
               e.printStackTrace();
               break;
           }
          
           if(line == null)
               break;
           StringTokenizer st = new StringTokenizer(line);
           String year, type, name, salary, bonus;
           year = st.nextToken();
           type = st.nextToken();
           name = st.nextToken();
           salary = st.nextToken();
          
           Employee newEmpl = null;
           if(type.equals("Employee")) {
               newEmpl = new Employee(name, Integer.parseInt(salary));
           }
           if(type.equals("Salesman")) {
               bonus = st.nextToken();
               newEmpl = new Salesman(name, Integer.parseInt(salary), Integer.parseInt(bonus));
           }
           if(type.equals("Executive")) {
               bonus = st.nextToken();
               newEmpl = new Executive(name, Integer.parseInt(salary), Integer.parseInt(bonus));
           }
              
           if(year.equals("2014"))
               array2014.add(newEmpl);
           if(year.equals("2015"))
               array2015.add(newEmpl);
          
       }
      
       double avarage = 0.0;
       for(Employee x : array2014) {
           System.out.println(x.toString());
           avarage += x.annualSalary();
       }
       avarage = avarage / array2014.size();
       System.out.println("Avarage salary of 2014 is " + avarage);
      
       avarage = 0.0;
       for(Employee x : array2015) {
           System.out.println(x.toString());
           avarage += x.annualSalary();
       }
       avarage = avarage / array2015.size();
       System.out.println("Avarage salary of 2015 is " + avarage);
   }

}



Output
e Console 3 Problems Javadoc Declaration <terminated> MainClass [Java Application] C:\Program Files\Java\jdk-12\bin\javaw.exe


Comment down for any queries

Please give a thumb up

Add a comment
Know the answer?
Add Answer to:
I really need help with this, please. This is a java programming assignment. Project 1 The first programming project inv...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA: How do I output all the data included for each employee? I can only get...

    JAVA: How do I output all the data included for each employee? I can only get it to output the name, monthly salary and annual salary, but only from the Employee.java file, not Salesman.java or Executive.java. Employee.java package project1; public class Employee { private String name; private int monthlySalary; public Employee(String name, int monthlySalary) { this.name = name; this.monthlySalary = monthlySalary; } public int getAnnualSalary() { int totalPay = 0; totalPay = 12 * monthlySalary; return totalPay; } public String...

  • In the processLineOfData method, write the code to handle case "H" of the switch statement such...

    In the processLineOfData method, write the code to handle case "H" of the switch statement such that: • An HourlyEmployee object is created using the firstName, lastName, rate, and hours local variables. Notice that rate and hours need to be converted from String to double. You may use parseDouble method of the Double class as follows: Double.parseDouble(rate) Call the parsePaychecks method in this class passing the Hourly Employee object created in the previous step and the checks variable. Call the...

  • Please help me write in C++ language for Xcode. Thank you. In this lab you are...

    Please help me write in C++ language for Xcode. Thank you. In this lab you are going to write a time card processor program. Your program will read in a file called salary.txt. This file will include a department name at the top and then a list of names (string) with a set of hours following them. The file I test with could have a different number of employees and a different number of hours. There can be more than...

  • I need help with this one method in java. Here are the guidelines. Only public Employee[]...

    I need help with this one method in java. Here are the guidelines. Only public Employee[] findAllBySubstring(String find). EmployeeManager EmployeeManager - employees : Employee[] - employeeMax : final int = 10 -currentEmployees : int <<constructor>> EmployeeManager + addEmployee( type : int, fn : String, ln : String, m : char, g : char, en : int, ft : boolean, amount : double) + removeEmployee( index : int) + listAll() + listHourly() + listSalary() + listCommision() + resetWeek() + calculatePayout() :...

  • I need help with this assignment. It's due Tuesday at 8 AM. Please follow the instructions thorou...

    I need help with this assignment. It's due Tuesday at 8 AM. Please follow the instructions thoroughly as to not use any advanced material we may not have gone over in class. The instructions let you know what all should be used. Thanks! Use only what you have learned in Chapters 1 - 7. Use of "advanced" material, material not in the text, or project does not follow the instructions, will result in a GRADE OF 0% for the project....

  • Please I need Help with: BM155 Project 5 Managing and Interpreting Key Financial Information & Statements Project De...

    Please I need Help with: BM155 Project 5 Managing and Interpreting Key Financial Information & Statements Project Description: T & T, Inc. is an up-and-upcoming small business that makes widgets. As a founding partner in this small business, you are responsible for managing the company’s financials. To help you complete this responsibility, use the information you learned in Chapter 10 and 11 on understanding a company’s finances. Using the Project 5 Supplement Data Sheet, compose the Income Statement for the...

  • Question 1 and 2 already solved. I need help on Question 3 and 4. Should prepaid...

    Question 1 and 2 already solved. I need help on Question 3 and 4. Should prepaid assets make difference in ROA calculation? (8 points) Some costs are post paid, therefore, it creates liabilities. For example, salary is post-paid, meaning that the employees will get paid after they provide services. In class, we find that operating liabilities such as salary payable should be excluded in the denominator for ROA to be consistent with the idea. Some costs are pre-paid. Rent (if...

  • Use program control statements in the following exercises: Question 1 . Write pseudocode for the following:...

    Use program control statements in the following exercises: Question 1 . Write pseudocode for the following: • Input a time in seconds. • Convert this time to hours, minutes, and seconds and print the result as shown in the following example: 2 300 seconds converts to 0 hours, 38 minutes, 20 seconds. Question 2. The voting for a company chairperson is recorded by entering the numbers 1 to 5 at the keyboard, depending on which of the five candidates secured...

  • Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the...

    Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of...

  • I need help calculating all kf these questions. Really stuck on all of them! Thank you!...

    I need help calculating all kf these questions. Really stuck on all of them! Thank you! Year using the returns for the first three years. The next rolling ace would be calculated using the returns from Years 2. 3. and 4, and so on Using the annual returns for large company stocks and Treasury bills, calculate both the 5- and 10-year rolling average return and standard deviation. h Over how many 5-year periods did Treasury bills outreform Caree company stocks?...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT