Java programming 5th edition chapter 9 Parallel Arrays Write a Java program to c
ID: 3795676 • Letter: J
Question
Java programming 5th edition chapter 9 Parallel Arrays
Write a Java program to create 4 parallel arrays - one to hold employee names, one to hold gross pays, one to hold deduction amounts, and one to hold net pays. Read the names into the array from the keyboard, read the gross pay data from a file, and assign the deduction amounts when you create the array. Use the data below.
Perform the following functions using the arrays, each in a separate method.
* Calculate the net pay array amounts by subtracting the deduction amount from the gross pay
* Write one method to calculate the sum of the values in any one array and call it 3 times, once to total the gross pay amounts, once to total the deduction amounts, and once to total the net pay amounts
*Determine the employee with the highest net pay.
* Determine the employee with the lowest net pay.
Print the arrays in column form with table headings and the totals below each column( See below for format). Print the name and net pay for the employees with the highest and lowest net pay. Do all output in main().
Name Gross Pay Deductions Net Pay
______________________________________________
John Brown $2000.00 $525.00 $1475.00
Jim Smith $3750.25 $1025.00 $2725.25
Sue Fuller $1115.50 $300.00 $815.50
Bob Allen $2348.50 $730.25 $1618.25
Leslie Brown $1800.00 $675.75 $1124.25
______________________________________________
Total $11014.25 $3256.00 $7758.25
The employee with the highest net pay is Jim Smith with $2725.25
The employee with the lowest net pay is Sue Fuller with $815.50
Explanation / Answer
ParallelArrays.java :
package org.chegg;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Scanner;
public class ParallelArrays {
static String names[] = new String[5];
static double gross[] = new double[5];
static double deduct[]= {525.00,1025.00,300.00,730.25,675.75};
static double net[] = new double[5];
static int high_net = 0;
static int low_net = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter employee Names:");
for(int i=0;i<5;i++){
System.out.println("Enter employee Name "+(i+1)+":");
names[i] = sc.nextLine();
}
try{
FileReader fr = new FileReader("F:\GrossData.txt");
BufferedReader br = new BufferedReader(fr);
String l = null;
l = br.readLine();
String s[ ]= l.split(" ");
for(int i=0;i<5;i++){
gross[i] =Double.parseDouble(s[i]);
}
}
catch(Exception e){
e.printStackTrace();
}
calculate_netpay();
System.out.println("Name GrossPay Deduction NetPay");
System.out.println("----------------------------------------");
for(int i=0;i<5;i++){
System.out.println(names[i]+" $"+gross[i]+" $"+deduct[i]+" $"+ net[i]);
}
System.out.println("---------------------------------------------");
double gross_total = sum_array(gross);
double deduct_total = sum_array(deduct);
double net_total = sum_array(net);
System.out.println("Total "+gross_total+" "+deduct_total+" "+net_total);
System.out.println("The employee with the highest net pay is "+names[high_net]+" with $"+net[high_net]);
System.out.println(" The employee with the lowest net pay is "+names[low_net]+" with $"+net[low_net]);
}
public static void calculate_netpay(){
double h = 0 ;
double l = 1000000;
for(int i=0;i<5;i++){
net[i] = gross[i] - deduct[i];
if(net[i] > h){
high_net = i;
h = net[i];
}
if(net[i]<l){
low_net = i ;
l = net[i];
}
}
}
public static double sum_array(double[] arr){
int total = 0;
for(int i=0;i<arr.length;i++)
total += arr[i];
return total;
}
}
GrossData.txt :
2000.00 3750.25 1115.50 2348.50 1800.00
Sample Input & Output:
Enter employee Names:
Enter employee Name 1:
John Brown
Enter employee Name 2:
Jim Smith
Enter employee Name 3:
Sun Fuller
Enter employee Name 4:
Bob Allen
Enter employee Name 5:
Leslie Brown
Name GrossPay Deduction NetPay
----------------------------------------
John Brown $2000.0 $525.0 $1475.0
Jim Smith $3750.25 $1025.0 $2725.25
Sun Fuller $1115.5 $300.0 $815.5
Bob Allen $2348.5 $730.25 $1618.25
Leslie Brown $1800.0 $675.75 $1124.25
---------------------------------------------
Total 11013.0 3255.0 7757.0
The employee with the highest net pay is Jim Smith with $2725.25
The employee with the lowest net pay is Sun Fuller with $815.5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.