Question

Write a Java program that reads employee information from the file “employee.txt” then the program will...

Write a Java program that reads employee information from the file “employee.txt” then the program will display his/her information on the screen.
The file contains the Employee’s Name, age,join date, quit date, and salary.

• For each year the employee is in the company,10 days of sick leave are allowed. So, if an employee is in the company for two years, 20 days of sick leave are allowed.

• For each year the employee is in the company, one-month salary is allowed. Therefore, if an employee is in a company for 3 years, his/her end of service will be the salary of 3 month.

• The employee is eligible for retirement at the age of 60.

The program shall calculate and display on the screen the employee’s: (name,age,join date, quit date, salary, leave days, end of service, and retirement eligibility).

Sample input/output
           

“employee.txt”

Output

Shamma
38

2010

2020

15,000.0

Employee Name:Shamma
Age: 38Y
Join date: 2010

Quit date: 2020

Salary: 15,000.0
Sick Leave days: 100

End of service: 150,000.0

You are not eligible for retirement

Homework Answers

Answer #1
import java.io.File;
import java.io.FileNotFoundException;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Scanner;

public class EmployeeRead {
        public static void main(String[] args) throws FileNotFoundException {
                Scanner sc = new Scanner(new File("employee.txt"));
                System.out.println("Employee Name: " + sc.nextLine().trim());
                int age = Integer.parseInt(sc.nextLine().trim());
                System.out.println("Age: " + age + "Y");
                int join = Integer.parseInt(sc.nextLine().trim());
                System.out.println("Join Date: " + join);
                int quit = Integer.parseInt(sc.nextLine().trim());
                System.out.println("Quit Date: " + quit);
                String sal = sc.nextLine().trim();
                float salary = Float.parseFloat(sal.replaceAll("[^\\d.]+", ""));
                System.out.println("Salary: " + sal);
                System.out.println("Sick Leave days: " + ((quit - join) * 10));
                float eos=salary*(quit-join);
                NumberFormat formatter=NumberFormat.getCurrencyInstance(Locale.US);  
                System.out.println("End of service: " + formatter.format(eos).substring(1));
                if (age >= 60)
                        System.out.println("You are eligible for retirement");
                else
                        System.out.println("You are not eligible for retirement");
                sc.close();
        }
}

Know the answer?
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
Similar Questions
This program is in C++: Write a program to allow the user to: 1. Create two...
This program is in C++: Write a program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to...
Write a Java program that reads words from a text file and displays all the words...
Write a Java program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The words must start with a letter. 1. You must use one of following Concrete class to store data from the input.txt file. Vector, Stack, ArrayList, LinkedList 2. To sort those words, you should use one of existing interface methods available in Collection or List class.
C# Reading from Files Write a program to open a text file containing information about buildings....
C# Reading from Files Write a program to open a text file containing information about buildings. The program must display all the buildings in the file and then find the lowest cost building based on the cost per square foot. Format for one building: <building name> <size> sqft $<cost> Example: Allgood Hall 35000 sqft $8,250,099.75 Create the text file and add three or more of your favorite buildings.
Payroll Management System C++ The project has multiple classes and sub-classes with numerous features within them....
Payroll Management System C++ The project has multiple classes and sub-classes with numerous features within them. Basic operations users can perform via this program project that are based on file handling are adding new employee record, modifying employee record and deleting record, displaying one or all employee’s record. Besides these, payroll management also allows users to print the salary slip for a particular employee. Features: 1. Addition of New Employee: You can find this feature under the public category of...
EMPLOYEE Field Name EMP_ID EMP_LNAME EMP_MI EMP_FNAME EMP_SEX EMP_AGE EMP_SALARY EMP_HIREDATE DEPT_CODE Table: DEPARTMENT DEPT_CODE BIOL...
EMPLOYEE Field Name EMP_ID EMP_LNAME EMP_MI EMP_FNAME EMP_SEX EMP_AGE EMP_SALARY EMP_HIREDATE DEPT_CODE Table: DEPARTMENT DEPT_CODE BIOL CPTR HIST MATH RELB Data Type Text Text Text Text Text Number Currency Date/Time Text DEPT_TITLE Biology Computer Science History Mathematics Religion    Field Name DEPT_CODE DEPT_TITLE Data Type Text Text INSTRUCTIONS Use SQL commands to create the tables and enter the data shown above using MS Access. Write the following SQL statement given below: 1. 2. 3. 4. 5. 6. 7. 8. 9....
SITUATION : Assume that you have to write a program to provide solution to problem face...
SITUATION : Assume that you have to write a program to provide solution to problem face by the company of ABC. The company is providing a service of renting a venue and place such as futsal court, badminton court booking and etc. There are several problems which face by the company in which they have to do it manually. One of the problems maybe during booking of venue. Another problem maybe face by the employee is to reserve the place...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Exercise 13-27 St. Thomas Auto Repairs is preparing the financial statements for the year ended November...
Exercise 13-27 St. Thomas Auto Repairs is preparing the financial statements for the year ended November 30, 2020. As the accountant, you are looking over the information regarding short-term liabilities, and determining the amounts that should be reported on the balance sheet. St. Thomas Auto Repairs reports under ASPE. The following information regarding new corporate initiatives has been brought to your attention. 1. St. Thomas printed a coupon in the local newspaper in November 2020. The coupon permits customers to...
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
Subject: Human Resource Management Main question: Which benefit plans would you choose, and which wouldn't you...
Subject: Human Resource Management Main question: Which benefit plans would you choose, and which wouldn't you choose and give reasons why you would or would not want a benefit that were used in making the benefit selections (specially at at entry level making $30000). PROCEDURES: Assume that you recently graduated from college and are just starting a new job at a large firm. You will be receiving a starting net pay (net of all taxes and mandatory deductions) of $30,000....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT