Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need help with project

843785Mar 14 2009 — edited Mar 16 2009
Hello,

I am currently at a stand still. In my project I have to create a .dat file ( which i already have)...then i have to take information from that text file and print it out. I have to have the program repeat this until there is no more information in the text file. I used a while (payroll.hasNext()) (payroll the name of the .dat file) to accomplish this.

I have to create a method to return an employee name...i have to change my string type to a StringBuffer

I have to create a Boolean method named inputData that has reference parameters to input an employee name, hourly rate, hours worked, and tax rate from my file payroll.dat

I have to read and return values for hourly rate, hours worked, and tax rate...I have to use the class DoubleClass. I have to define in the class a constructor with no parameters that is used to initilize the objects instantiated to 0.0. The method setNum() is used to set the data member of the object using the method's parameter. The method getNUM() is used to retrieve the double value stored within the object.

Right now I am stuck on figuring out the use of the DoubleClass...Below the code are my errors:

Here is my code:
import java.io.*;
import java.util.*;
import javax.swing.*;

public class Payroll3
{
	static Scanner console = new Scanner(System.in);
	private static final double FULL_TIME = 40.0;
	
	public static void main(String[] args)throws FileNotFoundException
	{
	
	StringBuffer employeeName;
	
	double grossAmount, netAmount;
	
	DoubleClass hourlyRate = new DoubleClass();
	DoubleClass hoursWorked = new DoubleClass();
	DoubleClass taxRate = new DoubleClass(); 
	
	Scanner inFile = new Scanner(new FileReader("payroll.dat"));
	
	employeeName = new StringBuffer (inFile.next());
	//hourlyRate = inFile.nextDouble();
	//hoursWorked = inFile.nextDouble;
	//taxRate = inFile.nextDouble;
	grossAmount = 0.00;
	netAmount = 0.00;
	
	instructions();
	reportTitle();
	
	while (payroll.hasNext())
		{
		inputData(employeeName, hourlyRate, hoursWorked, taxRate, grossAmount, netAmount);
		printEmployeeInfo(employeeName, hourlyRate, hoursWorked, taxRate, grossAmount, netAmount, FULL_TIME);
		}
	
	inFile.close();
	}//End Main
	
	//Being Instructions
	public static void instructions()
	{
	System.out.print("          Instructions for Payroll Report Program          \n" + 
							  "This program calculates a paycheck for each employee.\n" +
							  "A text file containing the following information wil lbe created:\n" + 
							  "name, pay rate, hours worked, and tax percentage to be deducted.\n\n" +
							  "The program will create a report in columnar format showing the\n" +
							  "employee name, hourly rate, number of hourse worked, tax rate,\n" +
							  "gross pay, and net pay.\n\n" +
							  "After all employees are processed, totals will be displayed,\n" +
							  "including total gross amount and total net pay.\n\n");

	}//End instructions
	
	//Being Report Title
	public static void reportTitle()
	{
	System.out.println("Employee               Hourly    Hours      Tax      Gross     Net");
	System.out.println("Name                    Rate     Worked     Rate     Amount   Amount");
	System.out.println("--------------------  --------  --------  --------  -------- --------");
	
	}//End Report Title
	
	public static void printEmployeeInfo(StringBuffer employeeName, DoubleClass hourlyRate, DoubleClass hoursWorked, DoubleClass taxRate, double grossAmount, double netAmount,double FULL_TIME)
	{
	String overTime;
	
	//Check overtime
	if (hoursWorked > FULL_TIME)
		overTime = "OT";
	else
		overTime = " ";
			
	//Print output
	System.out.println(String.format("%-20s%10.2f%10.2f%10.2f%10.2f%9.2f%4s",employeeName, hourlyRate, hoursWorked, taxRate, grossAmount.getNum(), netAmount.getNum(),overTime));
	
	}//End printEmployeeInfo
	
	public static Boolean inputData(StringBuffer employeeName,DoubleClass hourlyRate,DoubleClass hoursWorked, DoubleClass taxRate, double grossAmount, double netAmount,double FULL_TIME)
	{
	employeeName = inFile.next();
	hourlyRate = inFile.nextDouble();
	hoursWorked = inFile.nextDouble;
	taxRate = inFile.nextDouble;
	grossAmount.setNum();
	netAmount.setNum();

	
	}
}//End Payroll1
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 13 2009
Added on Mar 14 2009
35 comments
352 views