Question

Goals To design and program basic solutions for the small business problem: arranging average incomes. Description...

Goals

To design and program basic solutions for the small business problem: arranging average incomes.

Description

The company XYZ practices two ways of compensations for its employees: fixed salary and hourly wage.

For salary-based employees, the average monthly income is the annual salary divided by 12. For hourly-based employees, the average monthly income is 20.8 * 8 * [hourly rate] under the assumption that there are 250 working days in a year.

You must create a Java language program that makes a list of employees ordered according to their average monthly income.

Program requirements

Create three classes: a superclass and two subclasses to represent employees with a fixed salary and with an hourly wage.  

Employee’s data must include:

  • Employee ID,
  • First Name,
  • Type of Compensation,
  • Annual Salary or Hourly Rate (depending on the type of compensation).

Employee ID must be formed automatically as a total number of employees plus one.

The superclass must have an abstract method to calculate an average monthly income. Subclasses must override this method.

Your program must input data about employees from the console and sort it in descending order of the average monthly income. Employees with equal average monthly income must be listed in the ascending order of their First Names.

Output sorted data to the console and the text file.

Suggestions:

  • use a static field in generating Employee ID,
  • use an array and any sorting algorithm,
  • for debugging purpose, use the test data hardcoded or retrieved from a text file,
  • override default toString() method.

Example: for the input (fixed, “David", 50000), (fixed, “Mark", 20000), (hourly, ”June", 50), (hourly, “Alex", 50), (fixed, “Steve", 25000), the following output expected

Mark #2 fixed  $1,666.67

Steve #5 fixed  $2,083.33

David #1 fixed  $4,166.67

Alex #4 hourly $8,320.00

June #3 hourly $8,320.00

Submission should include:

  1. Java source code as files named P2*.java. Asterisk means that you may choose names for your files, but they all must start with ‘P2’.
  2. A screenshot with your program dialog and outputs.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//CODE:

/////////////////////////////////////////////////////////////////////////////////////
//////AUTHOR : Ramcharan jethu////////////////////////
//////////////////////////////////////////////////////////////////////////////////

import java.util.*;
import java.lang.*;
import java.math.*;


//Employee class
abstract class Employee
{
int Employee_id;
String FirstName;
String TypeofCompensation;
double Rate;
static int count=0;
  
public Employee()       //Default constructor
{
count++;
this.Employee_id=count;
}
public Employee(String name,String toc,double r)   //Parameterized constructor
{
this.FirstName=name;
this.TypeofCompensation=toc;
this.Rate=r;
count++;
this.Employee_id=count;
}
public abstract double CalculateMonthlyIncome();   //abstract method
}

//subclass of Employee
class FixedSalaryEmployee extends Employee
{
public FixedSalaryEmployee()
{
//Default constructor
}
public FixedSalaryEmployee(String name,String toc,double r)
{
super(name,toc,r);
}
public double CalculateMonthlyIncome()       //override abstract method
{
double averageMonthlyIncome=Rate/(12.0);
return averageMonthlyIncome;
}
public String toString()       //override toString method
{
return FirstName+" #"+Employee_id+" "+TypeofCompensation+" $"+String.format("%1.2f",CalculateMonthlyIncome(),2);
}
}

//subclass of Employee
class HourlyWageEmployee extends Employee
{
public HourlyWageEmployee()
{
  
}
public HourlyWageEmployee(String name,String toc,double r)
{
super(name,toc,r);
}
public double CalculateMonthlyIncome()
{
double averageMonthlyIncome=Rate*20.8*8;
return averageMonthlyIncome;
}
public String toString()
{
return FirstName+" #"+Employee_id+" "+TypeofCompensation+" $"+String.format("%1.2f",CalculateMonthlyIncome(),2);
}
}

//sorter class to compare the avrage monthly income in order to sort list of employees
class Sorter implements Comparator<Employee>
{
@Override
public int compare(Employee o1, Employee o2) {
       double m1=o1.CalculateMonthlyIncome();
       double m2=o2.CalculateMonthlyIncome();
       if(m1==m2)
           return o1.FirstName.compareTo(o2.FirstName);
       else
           return Double.compare(o1.CalculateMonthlyIncome(),o2.CalculateMonthlyIncome());
}
}
class P2Manager
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
System.out.println("How many number of Employees are there :");
int n=sc.nextInt();
  
      
ArrayList<Employee> list=new ArrayList<Employee>();
System.out.println("\nEnter Type of compensation, name,rate for each employee:\n");
for(int i=0;i<n;i++)
{
String type=sc.next();
String nm=sc.next();
double r=sc.nextDouble();
if(type.equals("fixed"))
{
list.add(new FixedSalaryEmployee(nm,type,r));
}
else
{
list.add(new HourlyWageEmployee(nm,type,r));
}
}
       System.out.println("\n");
list.sort(new Sorter());
for(int i=0;i<n;i++)
{
System.out.println(list.get(i).toString());
}
}
}

//Screenshot :

Add a comment
Know the answer?
Add Answer to:
Goals To design and program basic solutions for the small business problem: arranging average incomes. Description...
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
  • In java. You are provided an abstract class called MyAbstract. You can only modify the writeFile...

    In java. You are provided an abstract class called MyAbstract. You can only modify the writeFile () class. You are provided another class called Finally you are provided the file you must read from in the MyAbstract class. You will need to extend MyAbstract to MyTestClass. You should have the following outputs. The content of myData employee avg salary number of employees File that was created in myFile() Everything I was provided is listed already. l. Servers ary 1 35...

  • C++ Simple Employee Tracking System

    This assignment involves creating a program to track employee information.  Keep the following information on an employee:1.     Employee ID (string, digits only, 6 characters)2.     Last name (string)3.     First Name (string)4.     Birth date (string as MM/DD/YYYY)5.     Gender (M or F, single character)6.     Start date (string as MM/DD/YYYY)7.     Salary per year (double)Thus you must create a class that has all of this, and get/set methods for each of these fields.  Note: The fields that are designated as string should use the string...

  • Description: A program is needed for a third-party payroll clearinghouse that supports the following: Calculate employee...

    Description: A program is needed for a third-party payroll clearinghouse that supports the following: Calculate employee pay feature Company total pay feature The employee and company totals are stored in a text file for each individual company. 1. Create the following “input.txt” file. Each record consists of a first name, last name, employee ID, company name, hours worked, and pay rate per hour. Maria    Brown 10 Intel   42.75 39.0 Jeffrey Jackson 20 Boeing   38.0 32.5 Bernard Smith 30 Douglas   25.0...

  • BUS 206: Management Information Systems               ASSIGNMENT 2 DETERMINING OPERATING LEVERAGE Pony Espresso is a small business that...

    BUS 206: Management Information Systems               ASSIGNMENT 2 DETERMINING OPERATING LEVERAGE Pony Espresso is a small business that sells specialty coffee drinks at office buildings. Each morning and afternoon, trucks arrive at offices’ front entrances, and the office employees purchase various beverages with names such as Java du Jour and Café de Colombia. The business is profitable. But Pony Espresso offices are located to the north of town, where lease rates are less expensive, and the principal sales area is south of...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

  • CASE 1-5 Financial Statement Ratio Computation Refer to Campbell Soup Company's financial Campbell Soup statements in...

    CASE 1-5 Financial Statement Ratio Computation Refer to Campbell Soup Company's financial Campbell Soup statements in Appendix A. Required: Compute the following ratios for Year 11. Liquidity ratios: Asset utilization ratios:* a. Current ratio n. Cash turnover b. Acid-test ratio 0. Accounts receivable turnover c. Days to sell inventory p. Inventory turnover d. Collection period 4. Working capital turnover Capital structure and solvency ratios: 1. Fixed assets turnover e. Total debt to total equity s. Total assets turnover f. Long-term...

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