Click here to Skip to main content
15,887,854 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
School of Computing recently hired interns who had completed their Higher Certificate degree. You are one of those interns. You have been tasked to develop a Java program that will calculate the net pay for each of the interns. You have been provided with a textfile called interns.txt with the following intern details: employee number, name, sex, gross pay, and deductions. Below are the contents of the file:
Figure 1 Interns.txt file
1
Develop a Java program using the information provided in the above scenario. The program must consist of two functions namely interns() and ladies(). The interns() function must initially read, from the interns.txt, records containing the following fields: employee number, name, sex, gross pay, and deductions. The program must then calculate the net pay for each intern using the formula:
nett pay = gross pay – deductions

What I have tried:

Java
package cliff;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Program {
    public static void main(String[] args) throws IOException {
        
        // Open this file.
        BufferedReader reader = new BufferedReader(new FileReader(
                "C:\\Users\\user\\OneDrive - University of Mpumalanga\\Desktop\\cliff.txt"));
        
        // Read lines from file.
        while (true) {
            String line = reader.readLine();
            if (line == null) {
                break;
            }
            // Split line on comma.
            
            String[] parts = line.split(",");
            for (String part : parts) {
                System.out.println("Num:" + part);
              
            }
            System.out.println();
        }
        
        reader.close();
    }
}
Posted
Updated 3-Oct-22 2:55am
v2
Comments
Richard MacCutchan 3-Oct-22 8:52am    
You seem to have forgotten to ask a question.
Venki Vky 3-Oct-22 8:55am    
:-) :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900