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...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a name, an address, and a hire date. A name consists of a first name and a last name. An address consists of a street, a city, a state (2 characters), and a 5-digit zip code. A date consists of an integer month, day and year. All fields are required to be non-blank. The Date fields should be reasonably valid values (ex. month 1-12, day...
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...
an intensive care unit of Hospital Sg Buloh keeps information on the patients suffering from Covid...
an intensive care unit of Hospital Sg Buloh keeps information on the patients suffering from Covid 19in the following input file named covid.txt. The file contains the patient's gender, name, age and number of days in ward followed by daily temperatures for 50 patients. The symbol ';' indicate the delimiter of the data. female; Mariam Binti Ramli; 20 4 39.0 39.0 38.5 37.0 female; Aisyah Binti Salleh; 41 3 41.0 39.0 38.0 male; Nuh Harraz bin Amirul; 35 5 41.0...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT