Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: CSC Basics - Final Program Problems

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation 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:

     
    //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
    		fin = new Scanner(new FileReader("Salaries.data"));
    	Scanner
    		fin2 = new Scanner(new FileReader("Transaction.data"));
     
    	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];
    }
    return total;
    }//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.
    415.00 was not found in the array.

    50.00 200.00 400.00 800.00


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: CSC Basics - Final Program Problems

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    TylerJH7 (December 3rd, 2013)

  4. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: CSC Basics - Final Program Problems

    Thanks! Like I said, I just joined and don't know the tags involved yet!

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    TylerJH7 (December 3rd, 2013)

  7. #5
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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.

  8. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. I'm a CSC major who hates programming.
    By Ampageg in forum The Cafe
    Replies: 3
    Last Post: August 1st, 2013, 01:21 PM
  2. Lotto program for intro to programing final
    By dozindave in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 28th, 2012, 10:08 PM
  3. Need a little help with the basics
    By Java Neil in forum What's Wrong With My Code?
    Replies: 10
    Last Post: March 17th, 2011, 10:54 PM
  4. final class, final <variable> or <data member>
    By chronoz13 in forum Object Oriented Programming
    Replies: 9
    Last Post: September 20th, 2009, 08:19 AM

Tags for this Thread