CSC Basics - Final Program Problems

• December 3rd, 2013, 03:04 PM
TylerJH7
CSC Basics - Final Program Problems
Hello! This is my first time posting a thread in this site. I, along with most of my class, am having troubles with this program. We're only in the first class of our Computer Science major. My current program "runs" but prints a blank output file. Please help! My comrades and I are stressing BIG TIME because of finals! Thanks a ton!

The code is as follows:

Code java:

//Salaries.java

//This program will compute the gross wages for each employee. It will also
//determine the highest and lowest for the week's salary, the total weekly payroll,
//the average salary for the week, and the total amount the company has to pay
//in social security taxes. In addition, the program will count the employees
//that earn more than \$500.00 by the end of the week.

import java.util.*;
import java.io.*;

public class Salaries
{
public static void main(String [] args) throws IOException
{
Scanner
Scanner

PrintWriter
fout=new PrintWriter(new FileWriter("Salaries.report"));

double [] array = new double [50];

int
numE = 0,
index = 0,
value,
overTimer=0,
variable,
result = 0;

double
hoursWorked,
payRate,
tax,
wages,
overTime,
overHours,
totalTax,
total = 0,
average = 0,
Wages;

fout.println("\n The list of employees gross wages follows:	");

while(fin.hasNextDouble());
{
hoursWorked = fin.nextDouble();
payRate = fin.nextDouble();
if(hoursWorked>40.00)
{
overHours = (hoursWorked-40.00);
overTime=payRate+(payRate*.5);
wages=(overHours*overTime)+(40.00*payRate);
array[numE]=wages;
numE++;
}
else
{
wages=hoursWorked*payRate;
array[numE]=wages;
numE++;
}
fout.printf("%2s%1.2f ","",wages);
}

total = totalWages(array, numE);

fout.printf("Total Wages:	%1s%1.2f \n","",total);

fout.printf("Average Wage:	%1s%1.2f \n","",average);

index=findLargestSalary(array,numE);
fout.printf("\nThe largest salary is:	\$%1s%1.2f","",array[index],
" and is at position ", index);
fout.println();

index = findSmallestSalary(array,numE);
fout.printf("The smallest salary is:	\$%1s%1.2f","",array[index],
" and is at position ",index);
fout.println("\n");

tax=total*.062;
totalTax=tax*2;
fout.printf("Employee withholdings for social security taxes is:%15s\$%2s%.2f\n",
"",tax);
fout.printf("The company matching amount for social security taxes is:%9s\$%2s%.2f\n",
"",tax);

overTimer=printOverTimer(array,numE);
fout.print("The number of employees that made over \$500 this week is:	"+overTimer);

while(fin2.hasNextDouble())
{
variable = fin2.nextInt();

switch(variable)
{
case 1:
hoursWorked=fin2.nextDouble();
payRate=fin2.nextDouble();
if(hoursWorked>40.00)
{
overHours=(hoursWorked-40.00);
overTime=payRate+(payRate/2);
wages=(overHours*overTime)+(40.00*payRate);
array[numE]=wages;
numE++;
}

else
{
wages=hoursWorked*payRate;
array[numE]=wages;
numE++;
}
fout.printf("\$%1.2f was added to the array.\n" , wages);
break;

case 2:
Wages=fin2.nextDouble();
numE=remove(array, numE, Wages);
fout.printf("\n \$ %1.2f was removed from the array. \n", Wages);
break;
case 3:
Wages = fin2.nextDouble();

result = search(array, numE, Wages);
if(result<0)
fout.println("\n \$ " +Wages + " was found at index " +result);
else
fout.println("\n \$ " + Wages + " was not found in the array.\n");

}
for(int i=0; i<numE; i++)
fout.printf("%1.2f ",array[i]);

}//Closes while

fin.close();//Closes first input file
fin2.close();//closes Transaction

fout.close(); //Closes output file

}//Closes main
///////////////// totalWages /////////////////

//This method will take in the array and calculate the total wages in the company.

public static double totalWages(double [] array, int numE)
{
double
total = 0;

for(int i=0; i<numE; i++)
{
total += array[i];
}
}//end totalWages

///////////////// computeAverageWage /////////////////

//This method will compute the average wage of employees at the company.

public static double computeAverageWage(double [] array, int numE)
{
double
average,
sum = 0;

average = (double)sum/numE;
return average;

}//end computeAverageWage

///////////////// findLargestSalary /////////////////

//This method will find the highest salary of employees.

public static int findLargestSalary(double [] array, int numE)
{
int
position = 0;

for(int i=0; i<numE; i++)
{
if(array[i]>array[position])
position = i;
}
return position;

}//end findLargestSalary

///////////////// findSmallestSalary /////////////////

//This salary will find the lowest salary of employees.

public static int findSmallestSalary(double [] array, int numE)
{
int
position = 0;

for(int i=0; i<numE; i++)
if(array[i]<array[position])
position = i;
return position;
}//end findSmallestSalary

///////////////// printOverTimer /////////////////

//This method will print if the employee has worked over 500 hours or not.

public static int printOverTimer(double [] array, int numE)
{
int
overTimer = 0;

for(int i=0;i<numE;i++)
{
if(array[i]>500)
overTimer++;
}
return overTimer;

}//end printOverTimer

///////////////// remove /////////////////

//This method removes an inputted number.

public static int remove(double [] array, int numE, double Wages)
{
int
index = 0;

while(index<numE && array[index] != Wages)
index++;

if(index < numE)
{
for(int i=index; i<numE-1; i++)
array[i] = array[i+1];
--numE;
}
return numE;
}//end remove

///////////////// search /////////////////

//This method will search for a user-inputted number.

public static int search(double [] array, int numE, double Wages)
{
int
result=0;

for(int i=0; i<numE && result ==1; i++)
if(array[i]==Wages)
result=1;
return result;
}//end search

}//end program

EDIT---
When it runs, it creates the file and that's it. Just a blank file, no bytes, no code. Here's the extra.

Salaries.data
10 5
20 10
40 10
41 10
Transaction.data
1 40 20
3 415.00
2 415.00
3 415.00

Output Based on Above Input:
The list of employees' gross wages follows:

50.00 200.00 400.00 415.00

Total Wages: \$ 1065.00
Average Wage: \$ 266.25

The largest salary is \$ 415.00 and is located at index 3
The smallest salary is \$ 50.00 and is located at index 0
Employee wihtholdings for social security taxes is \$ 66.03

The company matching amount for social security taxes is 66.03
--------
Total 132.06

The number of employees earning over \$500 this week is 0
800.00 was added to the array.
415.00 was found at index 3.
415.00 was removed from the array.

50.00 200.00 400.00 800.00
• December 3rd, 2013, 03:19 PM
Norm
Re: CSC Basics - Final Program Problems
[code=java]
[/code]
to get highlighting and preserve formatting.
Quote:

prints a blank output file.
What is a "blank file"? Does that mean it has 0 bytes? Or is it a file full of blanks?
What is written to the file? Count the number of bytes that were written.
• December 3rd, 2013, 03:30 PM
TylerJH7
Re: CSC Basics - Final Program Problems
Thanks! Like I said, I just joined and don't know the tags involved yet!
• December 3rd, 2013, 03:33 PM
Norm
Re: CSC Basics - Final Program Problems
How does the program end execution? Are there any error messages? If so, copy the full text of the error messages and paste it here.
• December 3rd, 2013, 03:49 PM
TylerJH7
Re: CSC Basics - Final Program Problems
Actually, I have to end execution with CTRL+C. It seems like I have an endless loop, but I can't see one. No errors messages at all, not even with compiling.
• December 3rd, 2013, 03:56 PM
Norm
Re: CSC Basics - Final Program Problems
If it has an endless loop and nothing is written to the output file, check all the loops to be sure that they are ending. Put a call to the println() statement just inside all the loops and have it print out a message when the loop has just started executing. The print out will show you which loop is going forever.