Need Help with Class

B

BlackJackal

Alright this is the deal. The class will compile but when I run it I
receive

java.lang.NoSuchMethodError: main
Exception in thread "main"

Here is the Code

public class Commission
{
private double sales = 8000.00;
private double dubrate = 0.1;
private int intrate = 10;
public void main(String[] args)
{
ComputeCommision(sales, dubrate);
ComputeCommision(sales, intrate);

}
public void ComputeCommision(double a, double b)
{
double c;
c = a*b;
System.out.println("The Commision is " + c);
}
public void ComputeCommision(double a, int b)
{
double c;
c = a * (b/100);
System.out.println("The Commision is " + c);
}
}
 
P

Patricia Shanahan

BlackJackal said:
Alright this is the deal. The class will compile but when I run it I
receive

java.lang.NoSuchMethodError: main
Exception in thread "main" ....
public void main(String[] args)
{
ComputeCommision(sales, dubrate);
ComputeCommision(sales, intrate);

}

The main method needs to be static. You will need to choose between
making the rest of the class static, or creating an instance in which to
call ComputeCommission.

Patricia
 
H

Hal Rosser

BlackJackal said:
Alright this is the deal. The class will compile but when I run it I
receive

java.lang.NoSuchMethodError: main
Exception in thread "main"

Here is the Code

public class Commission
{
private double sales = 8000.00;
private double dubrate = 0.1;
private int intrate = 10;
public void main(String[] args)
{

Change your declaration for the main method to this
public static void main (String[] args){
.....your code here
}
 
P

Phi

BlackJackal said:
Alright this is the deal. The class will compile but when I run it I
receive

java.lang.NoSuchMethodError: main
Exception in thread "main"

Here is the Code

public class Commission
{
private double sales = 8000.00;
private double dubrate = 0.1;
private int intrate = 10;
public void main(String[] args)
{
ComputeCommision(sales, dubrate);
ComputeCommision(sales, intrate);

}
public void ComputeCommision(double a, double b)
{
double c;
c = a*b;
System.out.println("The Commision is " + c);
}
public void ComputeCommision(double a, int b)
{
double c;
c = a * (b/100);
System.out.println("The Commision is " + c);
}
}


This code is evil, when b is an integer:
c = a * (b/100);

If b probably is 95, then (b/100) leads to 0 (zero). Zero times a is
allways zero.
I don't think that is what you expect.

change to
c = a * b / 100;
 
A

Alex Hunsley

BlackJackal said:
Alright this is the deal. The class will compile but when I run it I
receive

java.lang.NoSuchMethodError: main
Exception in thread "main"

Here is the Code

public class Commission
{
private double sales = 8000.00;
private double dubrate = 0.1;
private int intrate = 10;
public void main(String[] args)
{
ComputeCommision(sales, dubrate);
ComputeCommision(sales, intrate);

Btw, methods names should begin with a lower case letter, if you wish to
follow convention (recommended). e.g. computeCommision.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top