2 Replies - 1048 Views - Last Post: 12 April 2007 - 08:04 PM Rate Topic: -----

#1 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Buisness Program Help Needed

Posted 12 April 2007 - 08:46 AM

We have finished our program but it doesnt meet the requirements. We need 7 functions and a recursive statement. The program calculates/prints your companies payroll checks and deduction statements for employe's. We just need help with putting 7 functiosn and 1 or more recursive statements.
The requirements are:
1. Creat public/private classes with at least 7 functions: next6ed (recursion)
2. create an input text file (*we have this done)
3. calculate hors/overtime (*we have the code for this)
4. taxes: recursion (need help on this)
5. passing parameters between classes
6. create an output txt file of checks/ stub (*we have this done)
7. open & close input/output txt file (*we have this done)

Here is what the input file looks like and we need to read in all the profiles to the outfile. Our code right now does the rock n roll, we need to read in the profile Darth Raiders, Oh Masterful One, Whaz-up, into the outfile so it looks like the rock n roll. could this be done with a simple for loop?
Rock N Roll
112-23-3445
56
5.26
.06
.22

Darth Raiders
010-10-1010
40
28.00
.004
.075

Oh Masterful One
Aaa-bb-cccc
47.5
13.78
.8
.03

Whaz-up
224-46-6880
37.25
16.66
.888
.094



***Our code***
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
public class Business
{
	private static double RegularPay, OvertimePay, GrossPay, StateTax, FederalTax, TotalDeductions, 
						  NetPay, HrPay, TotalHrs, MinHour = 40, StateTaxRate, FederalTaxRate;
	private static int TotalHours;
	private static String name, SocialSecurity;
	static Scanner scan = new Scanner(System.in);
	static FileOutputStream OutFile;
	static PrintStream print;
	static DecimalFormat fmt = new DecimalFormat("0.##");
	static DecimalFormat fmt2 = new DecimalFormat(".##");
	public static void main(String[] args)throws IOException
	{
		Business business = new Business();
		business.InOutFile();
	}														
	public static void InOutFile()throws FileNotFoundException
	{
		String Text = null;
		Text = new String();
		Scanner InFile = new Scanner(new FileReader("C:\\Documents and Settings\\220008514\\My Documents\\InFile.txt"));
		try
		{
			OutFile = new FileOutputStream("OutFile.txt");
			print = new PrintStream(OutFile);
		}
		catch(Exception e)
		{
			System.out.println("Could not load file");
		}
		name = InFile.nextLine();
		SocialSecurity = InFile.nextLine();
		TotalHrs = InFile.nextInt();
		HrPay = InFile.nextDouble();
		if (TotalHrs <= MinHour)
			RegularPay = (TotalHrs * HrPay);
		else
			RegularPay = (MinHour * HrPay);
		OvertimePay = (TotalHrs - MinHour) * HrPay * 1.5;
		GrossPay = RegularPay + OvertimePay;
		StateTaxRate = InFile.nextDouble();
		StateTax = GrossPay * StateTaxRate;
		FederalTaxRate = InFile.nextDouble();
		FederalTax = GrossPay * FederalTaxRate;
		TotalDeductions = StateTax + FederalTax;
		NetPay = GrossPay - TotalDeductions;
		print.println("(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)");
		print.println("~\tJ&K Enterprises\t\t\tCheck#1  Date: April 13, 2007\t~");
		print.println("~\tAP Java Avenue\t\t\t\t\t\t\t~");
		print.println("~\tRio Rancho, Nm 87124\t\t\t\t\t\t~");
		print.println("~\tPay to the order of: "+name+"\t\t\t\t\t\t~");
		print.println("~\tSocial Security#: "+SocialSecurity+"\t\t\t\t\t\t~");
		print.println("~\tThe amount of:$ "+fmt.format(NetPay)+"\t\t\t\t\t\t\t~");
		print.println("~\t\t\t\t\t\t\tJohn Buric\t~");
		print.println("~\t\t\t\t\t\t\tOwner\t\t~");
		print.println("(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)");
		print.println("~\tTotal Hours Worked: "+TotalHrs+" at $"+HrPay+"per hour");
		print.println("~\tRegular Pay:			$ "+fmt.format(RegularPay)+"");
		print.println("~\tOvertime Pay:		   $ "+fmt.format(OvertimePay)+"");
		print.println("~\t\t\t\t				  -----------");
		print.println("~\tGross Pay:			  $ "+fmt.format(GrossPay)+"");
		print.println("~\tState Tax:			  $ "+fmt.format(StateTax)+" at "+fmt2.format(StateTaxRate)+" % ");
		print.println("~\tFederal Tax:			$ "+fmt.format(FederalTax)+" at "+fmt2.format(FederalTaxRate)+" % ");
		print.println("~\tTotal Deductions:	   $ "+fmt.format(TotalDeductions)+"");
		print.println("~\tNet Pay:		   	  $ "+fmt.format(NetPay)+"");
		print.println("(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)");
	}
}



Our output file currently looks like this and only does the rock n roll but doesnt do the other profile, as stated above would we use a for loop to read in other profiles?
////////////////////////////////////////////////////////
/J&K Enterprises	   Check #1 Date: April 13, 2007   
/AP Java Avenue										
/Rio Rancho, NM 87124								  
/													  
/Pay to the order of:Rock N Roll					   
/Social Security #:112-23-3445				   
/													  
/The Amount of:$ 242.38						   
/										   
/										   Owner	  
////////////////////////////////////////////////////////
/TotalHours Worked:56 at $ 5.26 per hour
/Regular Pay:		   $ 210.4
/Overtime Pay:		  $ 126.24
/					   -------					  
/Gross Pay:			 $ 336.64
/State Tax:			 $  20.2 at .06%
/Federal Tax:		   $  74.06 at .22%
/Total Deductions:	  $  94.26
/Net Pay:			   $  242.38
////////////////////////////////////////////////////////



After this said we need to create 7 functions at least and atleast 1 recursion statement to meet the requirements of the program, thx for your time and any help is appreciated.
:fool:
O yea we need this by like tommorow lol

This post has been edited by ProGraM: 12 April 2007 - 09:00 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Buisness Program Help Needed

#2 ajwsurfer  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 373
  • Joined: 24-October 06

Re: Buisness Program Help Needed

Posted 12 April 2007 - 10:10 AM

Yes, you could do this with a simple for loop. However the program requirement is to have a recursive function.
Take a look at this to see the defenition of a recursive function:
http://www.dreaminco...mp;#entry210354

So you could burn up two functions building the recursion. That leaves 4 more to go. It would probably be much easier to build the regular functions first. This will make it much easier to see what is going on in the recursion.

The easiest way to break code out into a function is to look at each function as having a single purpose. Once the purpose of the code changes stop. Cut and paste all the code that is being used for that one purpose into a single function.
Another reason to make a function (probably a little more common) is that if you have to write code for a purpose, and then you end up having to right the same lines of code for another set of data.

I have put comments in the your code where I would break it into functions:

import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
public class Business
{
	private static double RegularPay, OvertimePay, GrossPay, StateTax, FederalTax, TotalDeductions,
						  NetPay, HrPay, TotalHrs, MinHour = 40, StateTaxRate, FederalTaxRate;
	private static int TotalHours;
	private static String name, SocialSecurity;
	static Scanner scan = new Scanner(System.in);
	static FileOutputStream OutFile;
	static PrintStream print;
	static DecimalFormat fmt = new DecimalFormat("0.##");
	static DecimalFormat fmt2 = new DecimalFormat(".##");
	public static void main(String[] args)throws IOException
	{
		Business business = new Business();
		business.InOutFile();
	}														
	public static void InOutFile()throws FileNotFoundException
	{
		String Text = null;
		Text = new String();
		Scanner InFile = new Scanner(new FileReader("C:\\Documents and Settings\\220008514\\My Documents\\InFile.txt"));
		// FileOutputStream  getFileOutputFile(string filename) --------------------------
		try
		{
			OutFile = new FileOutputStream("OutFile.txt");
			print = new PrintStream(OutFile);
		}
		catch(Exception e)
		{
			System.out.println("Could not load file");
		}
		//---------------------------------------------------------------------------------
		// read from file ----------------------------------------------------------------
		name = InFile.nextLine();
		SocialSecurity = InFile.nextLine();
		TotalHrs = InFile.nextInt();
		HrPay = InFile.nextDouble();
		// calulations -------------------------------------------------------------------
		if (TotalHrs <= MinHour)
			RegularPay = (TotalHrs * HrPay);
		else
			RegularPay = (MinHour * HrPay);
		OvertimePay = (TotalHrs - MinHour) * HrPay * 1.5;
		GrossPay = RegularPay + OvertimePay;
		StateTaxRate = InFile.nextDouble();
		StateTax = GrossPay * StateTaxRate;
		FederalTaxRate = InFile.nextDouble();
		FederalTax = GrossPay * FederalTaxRate;
		TotalDeductions = StateTax + FederalTax;
		NetPay = GrossPay - TotalDeductions;
		//---------------------------------------------------------------------------
		// print output ----------------------------------------------------------
		print.println("(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)");
		print.println("~\tJ&K Enterprises\t\t\tCheck#1  Date: April 13, 2007\t~");
		print.println("~\tAP Java Avenue\t\t\t\t\t\t\t~");
		print.println("~\tRio Rancho, Nm 87124\t\t\t\t\t\t~");
		print.println("~\tPay to the order of: "+name+"\t\t\t\t\t\t~");
		print.println("~\tSocial Security#: "+SocialSecurity+"\t\t\t\t\t\t~");
		print.println("~\tThe amount of:$ "+fmt.format(NetPay)+"\t\t\t\t\t\t\t~");
		print.println("~\t\t\t\t\t\t\tJohn Buric\t~");
		print.println("~\t\t\t\t\t\t\tOwner\t\t~");
		print.println("(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)");
		print.println("~\tTotal Hours Worked: "+TotalHrs+" at $"+HrPay+"per hour");
		print.println("~\tRegular Pay:			$ "+fmt.format(RegularPay)+"");
		print.println("~\tOvertime Pay:		   $ "+fmt.format(OvertimePay)+"");
		print.println("~\t\t\t\t				  -----------");
		print.println("~\tGross Pay:			  $ "+fmt.format(GrossPay)+"");
		print.println("~\tState Tax:			  $ "+fmt.format(StateTax)+" at "+fmt2.format(StateTaxRate)+" % ");
		print.println("~\tFederal Tax:			$ "+fmt.format(FederalTax)+" at "+fmt2.format(FederalTaxRate)+" % ");
		print.println("~\tTotal Deductions:	   $ "+fmt.format(TotalDeductions)+"");
		print.println("~\tNet Pay:				 $ "+fmt.format(NetPay)+"");
		print.println("(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)");
		//----------------------------------------------------------------------------------------------
	}
}


Was This Post Helpful? 0
  • +
  • -

#3 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Buisness Program Help Needed

Posted 12 April 2007 - 08:04 PM

How would i go about adding a for loop to this code to get all the profiles to print out in the outfile?
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
public class Business
{
	private static double RegularPay, OvertimePay, GrossPay, StateTax, FederalTax, TotalDeductions,
						  NetPay, HrPay, TotalHrs, MinHour = 40, StateTaxRate, FederalTaxRate;
	private static int TotalHours;
	private static String name, SocialSecurity;
	static Scanner scan = new Scanner(System.in);
	static FileOutputStream OutFile;
	static PrintStream print;
	static DecimalFormat fmt = new DecimalFormat("0.##");
	static DecimalFormat fmt2 = new DecimalFormat(".##");
	public static void main(String[] args)throws IOException
	{
		Business business = new Business();
		business.InOutFile();
	}														
	public static void InOutFile()throws FileNotFoundException
	{
		String Text = null;
		Text = new String();
		Scanner InFile = new Scanner(new FileReader("H:\\John\\Java\\Business\\InFile.txt"));
		try
		{
			OutFile = new FileOutputStream("OutFile.txt");
			print = new PrintStream(OutFile);
		}
		catch(Exception e)
		{
			System.out.println("Could not load file");
		}
		name = InFile.nextLine();
		SocialSecurity = InFile.nextLine();
		TotalHrs = InFile.nextInt();
		HrPay = InFile.nextDouble();
		if (TotalHrs <= MinHour)
			RegularPay = (TotalHrs * HrPay);
		else
			RegularPay = (MinHour * HrPay);
		OvertimePay = (TotalHrs - MinHour) * HrPay * 1.5;
		GrossPay = RegularPay + OvertimePay;
		StateTaxRate = InFile.nextDouble();
		StateTax = GrossPay * StateTaxRate;
		FederalTaxRate = InFile.nextDouble();
		FederalTax = GrossPay * FederalTaxRate;
		TotalDeductions = StateTax + FederalTax;
		NetPay = GrossPay - TotalDeductions;

		print.println("(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)");
		print.println("~\tJ&K Enterprises\t\tCheck#1  Date: April 13, 2007\t~");
		print.println("~\tAP Java Avenue\t\t\t\t\t~");
		print.println("~\tRio Rancho, Nm 87124\t\t\t\t~");
		print.println("~\tPay to the order of: "+name+"\t\t\t\t~");
		print.println("~\tSocial Security#: "+SocialSecurity+"\t\t\t\t~");
		print.println("~\tThe amount of:$ "+fmt.format(NetPay)+"\t\t\t\t~");
		print.println("~\t\t\t\t\t\tJohn Buric\t~");
		print.println("~\t\t\t\t\t\tOwner\t~");
		print.println("(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)");
		print.println("~\tTotal Hours Worked: "+TotalHrs+" at $"+HrPay+" per hour");
		print.println("~\tRegular Pay:			$ "+fmt.format(RegularPay)+"");
		print.println("~\tOvertime Pay:		   $ "+fmt.format(OvertimePay)+"");
		print.println("~\t\t				  -----------");
		print.println("~\tGross Pay:			  $ "+fmt.format(GrossPay)+"");
		print.println("~\tState Tax:			  $ "+fmt.format(StateTax)+" at "+fmt2.format(StateTaxRate)+" % ");
		print.println("~\tFederal Tax:			$ "+fmt.format(FederalTax)+" at "+fmt2.format(FederalTaxRate)+" % ");
		print.println("~\tTotal Deductions:	   $ "+fmt.format(TotalDeductions)+"");
		print.println("~\tNet Pay:				 $ "+fmt.format(NetPay)+"");
		print.println("(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)");
	}
}



Same as in this code but i dont understand about going about the recusrion and for loop :/ and for some reason its giving me an error and doesn't load the outfile. Error is FileNotfoundExeception but i throw that excpetion and it works for the code above :/
//C:\\Documents and Settings\\220008514\\My Documents\\InFile.txt
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
public class Business
{
	private static double RegularPay, OvertimePay, GrossPay, StateTax, FederalTax, TotalDeductions,
						  NetPay, HrPay, TotalHrs, MinHour = 40, StateTaxRate, FederalTaxRate;
	private static int TotalHours;
	private static String name, SocialSecurity;
	static Scanner scan = new Scanner(System.in);
	static FileOutputStream OutFile;
	static PrintStream print;
	static DecimalFormat fmt = new DecimalFormat("0.##");
	static DecimalFormat fmt2 = new DecimalFormat(".##");
	public static void main(String[] args)throws IOException, FileNotFoundException
	{
		ReadFromFile();
		Calculations();
		PrintOutput();
	}														
	public static void InOutFile()throws FileNotFoundException
	{
		String Text = null;
		Text = new String();
		Scanner InFile = new Scanner(new FileReader("H:\\John\\Java\\Business"));
		try
		{
			OutFile = new FileOutputStream("OutFile.txt");
			print = new PrintStream(OutFile);
		}
		catch(Exception e)
		{
			System.out.println("Could not load file");
		}
	}
		public static void ReadFromFile() throws FileNotFoundException
		{
			Scanner InFile = new Scanner(new FileReader("H:\\John\\Java\\Business"));
			name = InFile.nextLine();
			SocialSecurity = InFile.nextLine();
			TotalHrs = InFile.nextInt();
			HrPay = InFile.nextDouble();
		}
		public static void Calculations() throws FileNotFoundException
		{
			Scanner InFile = new Scanner(new FileReader("H:\\John\\Java\\Business"));
			if (TotalHrs <= MinHour)
				RegularPay = (TotalHrs * HrPay);
			else
				RegularPay = (MinHour * HrPay);
				OvertimePay = (TotalHrs - MinHour) * HrPay * 1.5;
				GrossPay = RegularPay + OvertimePay;
				StateTaxRate = InFile.nextDouble();
				StateTax = GrossPay * StateTaxRate;
				FederalTaxRate = InFile.nextDouble();
				FederalTax = GrossPay * FederalTaxRate;
				TotalDeductions = StateTax + FederalTax;
				NetPay = GrossPay - TotalDeductions;
		}
		public static void PrintOutput()
		{
			print.println("(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)");
			print.println("~\tJ&K Enterprises\t\t\tCheck#1  Date: April 13, 2007\t~");
			print.println("~\tAP Java Avenue\t\t\t\t\t\t\t~");
			print.println("~\tRio Rancho, Nm 87124\t\t\t\t\t\t~");
			print.println("~\tPay to the order of: "+name+"\t\t\t\t\t\t~");
			print.println("~\tSocial Security#: "+SocialSecurity+"\t\t\t\t\t\t~");
			print.println("~\tThe amount of:$ "+fmt.format(NetPay)+"\t\t\t\t\t\t\t~");
			print.println("~\t\t\t\t\t\t\tJohn Buric\t~");
			print.println("~\t\t\t\t\t\t\tOwner\t\t~");
			print.println("(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)");
			print.println("~\tTotal Hours Worked: "+TotalHrs+" at $"+HrPay+"per hour");
			print.println("~\tRegular Pay:			$ "+fmt.format(RegularPay)+"");
			print.println("~\tOvertime Pay:		   $ "+fmt.format(OvertimePay)+"");
			print.println("~\t\t\t\t				  -----------");
			print.println("~\tGross Pay:			  $ "+fmt.format(GrossPay)+"");
			print.println("~\tState Tax:			  $ "+fmt.format(StateTax)+" at "+fmt2.format(StateTaxRate)+" % ");
			print.println("~\tFederal Tax:			$ "+fmt.format(FederalTax)+" at "+fmt2.format(FederalTaxRate)+" % ");
			print.println("~\tTotal Deductions:	   $ "+fmt.format(TotalDeductions)+"");
			print.println("~\tNet Pay:				 $ "+fmt.format(NetPay)+"");
			print.println("(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)(o.O)(O.o)");
		}
	}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1