View Single Post
  #8 (permalink)  
Old March 20th, 2013, 12:07 PM
Wolverine Wolverine is offline
Authorized User
Points: 30, Level: 1
Points: 30, Level: 1 Points: 30, Level: 1 Points: 30, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Location: uk
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default RE: Compiles, but errors out when trying to run it

Alonsodev

From the command line navigate to your eclipse workspace I'm running on XP and my location is C:\Documents and Settings\user\workspace\lesson5\bin

from here run java TestTax 50000 NJ 2

the 50000 NJ 2 are the arguments that are pass to the Tax class and returns the calculated tax

below is my class TestTax and class Tax Code

Code:
class TestTax {
	public static void main(String[] args) {
		
		if (args.length != 3){
			System.out.println("Sample usage of the program: java TestTax 50000 NJ 2");
			System.exit(0);
		}
		
		double grossIncome = Double.parseDouble(args[0]); //local variables
		String state = args[1];
		int dependents = Integer.parseInt(args[2]);
		
		
		Tax t = new Tax(grossIncome, state, dependents);
	
			double yourTax = t.calcTax();//calculating tax

			
			
			
			//Printing Result
			System.out.println("Your tax is $" + yourTax);
			
	}
}
Code:
class Tax {
	double grossIncome;//class member variables
	String state;
	int dependents;
	static int customerCounter;
	static double convertToEuros = 1.25;
	static double dollars;
	
	//Constructor
	Tax (double gi, String st, int depen){
		grossIncome = gi; //member variable initialisation
		state = st;
		dependents = depen;
		customerCounter ++; //increment the counter by one
		
		
		System.out.println("Preparing the tax data for customer #" + customerCounter);
	}

	public double calcTax() {
		
		return (grossIncome * 0.33 - dependents * 100);
	}
	public double convertTaxEuros(){
		dollars = grossIncome *0.33 - dependents * 100;
		
		return (dollars / convertToEuros);
	}
}
Reply With Quote