7 Replies - 2377 Views - Last Post: 20 June 2009 - 08:03 PM Rate Topic: -----

#1 Mariko1222  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 19-June 09

can't get this to compile or run

Posted 19 June 2009 - 06:45 PM

public class Commission
{
	public static void main(String[] args)
	{
		double sales=50000.00;
		double doubRate=.05;
		int intRate=5;
		computeCommission(sales,doubRate);
		computeCommission(sales, intRate);
	}
	public void computeCommission(double sales,double rate)
	{
		commission=sales*doubRate;
		System.out.println("Commission on sales of $" + sales +
		"with a rate of " + doubRate + "= " + commission);
	}
	public void computeCommission(double sales,int rate)
	{
		commission=sales*(intRate*100);
		System.out.println("Commission on sales of $ " + sales +
		"with a rate of " + intRate + "% is " + commission);
	}
}



I am to create a class with 3 variables: a double sales figure, a double commission rate, and an integer commission rate. Create 2 overloaded methods named computeCommission(). The first method will take two double arguments representing sales and rate, multiply them and display the results. The second method takes two arguments: a double sales figure and an integer commission rate. This method must divide the commission rate figure by 100.0 before multiplying by the sales figure and displaying the commission. Supply appropriate values for the variables and write a main () method that tests each overloaded method. [b][i]also. I am to add a third overloaded method takes a single argument representing sales. When this method is called, the commission rate is assumed to be 7.5% and the results are displayed. To test this method, add an appropriate call in the Commission program's main () method.-----I haven't done this 3rd overloaded method because I cannot get the first two to compile and run. I keep getting errors and I just can't see them. What am I doing wrong.

Is This A Good Question/Topic? 0
  • +

Replies To: can't get this to compile or run

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: can't get this to compile or run

Posted 19 June 2009 - 08:08 PM

If you want to call computeCommission() from a static method (which main() is) they have to be static
the variable commission within these 2 methods is not defined
Was This Post Helpful? 0
  • +
  • -

#3 Mariko1222  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 19-June 09

Re: can't get this to compile or run

Posted 20 June 2009 - 05:06 AM

View Postpbl, on 19 Jun, 2009 - 07:08 PM, said:

If you want to call computeCommission() from a static method (which main() is) they have to be static
the variable commission within these 2 methods is not defined


Okay, I'm very new at this...teaching an old dog new tricks so to speak, so I would have to list commission in the beginning with double sales, double rate and int rate, correct? Then decide what I want the rate to be?
Was This Post Helpful? 0
  • +
  • -

#4 kingdom  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 16-June 09

Re: can't get this to compile or run

Posted 20 June 2009 - 05:06 AM

As what above pbl have mentioned, try doing the 2 print methods in the main. Change the overloaded methods return type to Double and Int.
I guess that should solve the error.

Edit: Something like this:

public class Commission
{
	public static void main(String[] args)
	{
		double sales=50000.00;
		double doubRate=.05;
		int intRate=5;

		double doubComm = computeCommission(sales,doubRate);
		System.out.println("Commission on sales of $" + sales +
		"with a rate of " + doubRate + "= " + doubComm );

		int intComm = computeCommission(sales, intRate);
		System.out.println("Commission on sales of $ " + sales +
		"with a rate of " + intRate + "% is " + intComm );
	}


	public static double computeCommission(double sales,double rate)
	{
		return commission=sales*doubRate;
	}
	public static int computeCommission(double sales,int rate)
	{
		return (int)commission=sales*(intRate*100);
	}
}


This post has been edited by kingdom: 20 June 2009 - 07:53 AM

Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: can't get this to compile or run

Posted 20 June 2009 - 07:23 AM

View Postkingdom, on 20 Jun, 2009 - 04:06 AM, said:

Edit: Something like this:


haven;t fix the use of "commission" in the 2 methods which has to return something and need to be static
	public static double computeCommission(double sales,double rate)
	{
		return sales*doubRate;
	}
	public static int computeCommission(double sales,int rate)
	{
		return (int) sales*(intRate*100);
	}
}


Was This Post Helpful? 0
  • +
  • -

#6 kingdom  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 16-June 09

Re: can't get this to compile or run

Posted 20 June 2009 - 07:47 AM

View Postpbl, on 20 Jun, 2009 - 06:23 AM, said:

haven;t fix the use of "commission" in the 2 methods which has to return something and need to be static



My boo. I overlook the return statement. Thanks pbl for pointing it out ;)
Guess I still need to work with a compiler :crazy:
Better make the changes...

This post has been edited by kingdom: 20 June 2009 - 07:51 AM

Was This Post Helpful? 0
  • +
  • -

#7 Mariko1222  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 19-June 09

Re: can't get this to compile or run

Posted 20 June 2009 - 02:25 PM

I REALLY appreciate the help this board has shown me. I joined another group that didn't like my post and just deleted the whole posting. Some help, huh? I've bookmarked this one for sure and will continue to use it! :D
Was This Post Helpful? 0
  • +
  • -

#8 Mariko1222  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 19-June 09

Re: can't get this to compile or run

Posted 20 June 2009 - 08:03 PM

public class Commission
{
	public static void main(String[] args)
	{
		double sales=50000.00;
		double commission=0.0;
		double doubRate=.05;
			int intRate=5;
		computeCommission(sales,doubRate);
		System.out.println("Commission on sales of $" + sales +
		"with a rate of " + doubRate + "= " + commission);
		computeCommission(sales, intRate);
		System.out.println("Commission on sales of $ " + sales +
		"with a rate of " + intRate + "% is " + commission);
	}
	public  static void computeCommission(sales, doubRate)
	{
		return commission=sales*doubRate;
		
	}
	public static void computeCommission(sales, intRate)
	{
		return (int)commission=sales*(intRate*100);
		
	}
}



This is what I have done. Did all the changes that were suggested, and for the 4th time after changes, this is what I get after I try to compile with javac.Commission.java

Commission.java:16:<identifier> expected
public static void computeCommission(sales, doubRate)
(with a mark ^ under the comma)
Commission.java:26:'}'
} (with a ^ under the closing bracket.


so what the HECK did I do wrong now????
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1