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.
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.
For this assignment, you need to submit a Python program that gathers the following employee information...
For this assignment, you need to submit a Python program that gathers the following employee information according to the rules provided: Employee ID (this is required, and must be a number that is 7 or less digits long) Employee Name (this is required, and must be comprised of primarily upper and lower case letters. Spaces, the ' and - character are all allowed as well. Employee Email Address (this is required, and must be comprised of primarily of alphanumeric characters....
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...
Write a Java program that Reads baseball data in from a comma delimited file. Each line...
Write a Java program that Reads baseball data in from a comma delimited file. Each line of the file contains a name followed by a list of symbols indicating the result of each at bat: 1 for single, 2 for double, 3 for triple, 4 for home run, o for out, w for walk, s for sacrifice Statistics are computed and printed for each player. EXTRA CREDIT (+10 points); compute each player's slugging percentage https://www.wikihow.com/Calculate-Slugging-Percentage Be sure to avoid a...
Could you script in Matlab : Script Name General Algorithm AddNewEmployee Display all of the ID...
Could you script in Matlab : Script Name General Algorithm AddNewEmployee Display all of the ID numbers currently in use Read in a new ID number If the ID number read in is already in use Report this fact End this script Else (this is a new ID number) Read in: Years with the company Salary Vacation days Sick days Add this new employee to the database (by appending a new row to the end of the EmployeeData matrix) Note...
Objective: Write a Java program that will use a JComboBox from which the user will select...
Objective: Write a Java program that will use a JComboBox from which the user will select to convert a temperature from either Celsius to Fahrenheit, or Fahrenheit to Celsius. The user will enter a temperature in a text field from which the conversion calculation will be made. The converted temperature will be displayed in an uneditable text field with an appropriate label. Specifications Structure your file name and class name on the following pattern: The first three letters of your...
Write a program that will read the information from a file into a list and then...
Write a program that will read the information from a file into a list and then display the list to the screen. Remove the fifth item in the list and display the list again. Ask the program user for an entry into the list and add it to the list. Display the list one last time. disneyin.txt file daisy   123 donald   345 goofy   654 mickey   593 minnie   489 daffy   432 pluto   765 huey   321 dewey   987 lewey   554 porky   333...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT