Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Three employees in a company are up for a special pay increase. You are given a

ID: 3800103 • Letter: T

Question

Three employees in a company are up for a special pay increase. You are given a file, say SalaryData.txt, with the following data:

Miller Andrew 65789.87 5
Green Sheila 75892.56 6
Sethi Amit 74900.50 6.1

Each input line consists of an employee’s last name, first name, current salary, and percent pay increase. For example, in the first input line, the last name of the employee is Miller, the first name is Andrew, the current salary is 65789.87, and the pay increase is 5%. Write a program that reads data from the specified file and stores the output in the file SalaryOutput.dat. For each employee, the data must be output in the following form: firstName lastName updatedSalary. Format the output of decimal numbers to two decimal places.

To solve this problem, you must create the input data file manually. To do this in CodeBlocks, go to the File menu and select New and then Empty File. A popup will ask if you want to add this file to the project. When you say yes, you will have to name the file. It is best to put a .txt extension on the file name. This type of file is called a flat file. A flat file is similar to a spread sheet in that all the fields (columns) contain the same type of information and the records (rows) contain different data values.

Turn in:

Your structure chart as a screen shot or picture

Your source code with

The name of your program as a comment at the top of the file

Your IPO chart incorporated as comments after the name of the file

A screen shot or picture of the results after running your program with your test data

Explanation / Answer

public class Employee {
   // declaring the variables
   public String fname;
   public String lname;
   public double salary;
   public double increment;

   public Employee(String fname, String lname, double salary, double increment) {
       this.fname = fname;
       this.lname = lname;
       this.salary = salary;
       this.increment = increment;
   }

   public double getSalary() {
       return salary;
   }

   public void setSalary(double salary) {
       this.salary = salary;
   }

   public String toString() {
       return fname + " " + lname + " " + salary;
   }

   public double updatesalary(double increment) {

       double incrementamount = salary * (increment / 100);

       double totalAmount = salary + incrementamount;
       double roundOff = (double) Math.round(totalAmount * 100) / 100;

       setSalary(roundOff);

       return roundOff;
   }

}

**********************************************************************************************************************

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class EmployeeDemo {

   public static void main(String[] args) throws IOException {
       List<Employee> employees = new ArrayList<Employee>();

       BufferedReader reader = new BufferedReader(new FileReader(new File(
               "D:\salary.txt")));
       String line = " ";
       // read the file till end line of the file
       while ((line = reader.readLine()) != null) {

           System.out.println(line);
           // split the line using whitespace
           String[] words = line.split("\s+ ");
           String fname = words[0];
           String lname = words[1];
           double salary = Double.parseDouble(words[2]);
           double increment = Double.parseDouble(words[3]);

           Employee e = new Employee(fname, lname, salary, increment);

           e.updatesalary(increment);

           employees.add(e);
       }

       System.out.println("do you want add the file to this project type y/n");

       Scanner scanner = new Scanner(System.in);

       String confirmation = scanner.next();

       if (confirmation.equals("y".trim())) {
           System.out.println("1.new ");
           System.out.println("2.exit");

           System.out.println("enter your choice");

           int choice = scanner.nextInt();

           switch (choice) {
           case 1:
               System.out.println("enter the new file name ");
               Scanner scanner1 = new Scanner(System.in);
               String filename = scanner1.nextLine();
               String extfilename = "D:\" + filename + ".txt";
               FileWriter writer = new FileWriter(new File(extfilename.trim()));

               for (Employee emp : employees) {
                   writer.write(emp.toString());
                   writer.flush();
                   writer.write(" ");
               }
               break;

           case 2:
               System.exit(0);

           default:
               System.out.println("you choose wrong option");
               break;
           }

       }

   }

}

***********************************************************************************************************

inputfile

Miller Andrew 65789.87 5
Green Sheila 75892.56 6
Sethi Amit 74900.50 6.1

*********************************************************************************************

//after updating the salary

Miller Andrew 65789.87 5
Green Sheila 75892.56 6
Sethi Amit 74900.50 6.1
do you want add the file to this project type y/n
y
1.new
2.exit
enter your choice
1
enter the new file name
report

//the report file is

Miller Andrew 69079.36
Green Sheila 80446.11
Sethi Amit 79469.43

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote