import javax.swing.*; import java.text.*; class ch6Num31 { private static void main (String [] args) { System.out.println ("hello"); //slot incoin; //incoin = new slot(); //incoin.setIncoin(coins, amtcoins); } } class dslot { private static final double MAX_NUMBER = 3; private static final double MIN_NUMBER = 1; private static final double NO_NUMBER = 0; private double number; public dslot(){ number = NO_NUMBER; } public void turn(){ number = (double)(Math.floor(Math.random()*(MAX_NUMBER - MIN_NUMBER + 1)) + MIN_NUMBER); } public double getNumber(){ return number; } } class slot { private double incoins, outcoins, scoins;//, left; double amtcoins = Double.parseDouble (JOptionPane.showInputDialog (null, "How many coins do you have?" )); double coins = Double.parseDouble (JOptionPane.showInputDialog (null, "Please import 1 to 4 coins that you want to bet." )); private static final double MAX_NUMBER = 3; private static final double MIN_NUMBER = 1; private static final double NO_NUMBER = 0; private double number; public slot () { number = NO_NUMBER; } //roll public void turn(){ number = (double)(Math.floor(Math.random()*(MAX_NUMBER - MIN_NUMBER + 1)) + MIN_NUMBER); } public double getNumber(){ return number; } //Coins2 public double getScoins() { return scoins; } public void setScoins () { scoins = amtcoins * 10; } //Coins public double getInCoins() { return incoins; } public void setIncoins () { if (coins == 0 || coins >= 5){ System.out.println ("IMPOSSIBLE"); } } //Results public double getOutcoins() { return outcoins; } public void setOutcoins () { dslot one, two, three; one = new dslot(); two = new dslot(); three = new dslot (); one.turn(); two.turn(); three.turn(); if (one.getNumber() == 1){ System.out.print( "BELL" ); } if (two.getNumber() == 1){ System.out.print ( "BELL" ); } if (three.getNumber() == 1){ System.out.print ( "BELL" ); System.out.println ( "You won $ " + coins * 10 ); } else if (one.getNumber() == 2){ System.out.print ( "GRAPE" ); } if (two.getNumber() == 2){ System.out.print ( "GRAPE" ); } if (three.getNumber() == 2){ System.out.print ( "GRAPE" ); System.out.println ( "You won $ " + coins * 7); } else if (one.getNumber() == 3){ System.out.print ( "CHERRY" ); } if (two.getNumber() == 3){ System.out.print ( "CHERRY" ); } if (three.getNumber() == 3){ System.out.print ( "CHERRY" ); System.out.println ( "You won $ " + coins * 5); } // else if ((one.getNumber() == 3 && two.getNumber() == 3) || (one.getNumber() == 3 && three.getNumber() == 3) || (two.getNumber() == 3 && three.getNumber() == 3)){ // } } //left }
main method not public error
Page 1 of 16 Replies - 3177 Views - Last Post: 30 November 2009 - 06:06 PM
#1
main method not public error
Posted 30 November 2009 - 04:52 PM
if says main method not public whenever i run this code but it builds without a problem
Replies To: main method not public error
#2
Re: main method not public error
Posted 30 November 2009 - 04:58 PM
umm it's just cause your main method up at the top where it prints out "hello" is declared private...
#3
Re: main method not public error
Posted 30 November 2009 - 05:05 PM
sure it will build
nothing stop you from having a private static void main() method
but when you
> java ch6Num31
the JRE looks looks for a public static void main(String[] args) method in that class which it can't find
nothing stop you from having a private static void main() method
but when you
> java ch6Num31
the JRE looks looks for a public static void main(String[] args) method in that class which it can't find
#4
Re: main method not public error
Posted 30 November 2009 - 05:38 PM
pbl, on 30 Nov, 2009 - 06:05 PM, said:
sure it will build
nothing stop you from having a private static void main() method
but when you
> java ch6Num31
the JRE looks looks for a public static void main(String[] args) method in that class which it can't find
nothing stop you from having a private static void main() method
but when you
> java ch6Num31
the JRE looks looks for a public static void main(String[] args) method in that class which it can't find
pbl, I have a quick question/possible fix?
class ch6Num31 {
Does that have to be public class?
#5
Re: main method not public error
Posted 30 November 2009 - 05:46 PM
Dogstopper, on 30 Nov, 2009 - 04:38 PM, said:
pbl, on 30 Nov, 2009 - 06:05 PM, said:
sure it will build
nothing stop you from having a private static void main() method
but when you
> java ch6Num31
the JRE looks looks for a public static void main(String[] args) method in that class which it can't find
nothing stop you from having a private static void main() method
but when you
> java ch6Num31
the JRE looks looks for a public static void main(String[] args) method in that class which it can't find
pbl, I have a quick question/possible fix?
class ch6Num31 {
Does that have to be public class?
No it has
private static void main(....
#6
Re: main method not public error
Posted 30 November 2009 - 05:56 PM
Alright, in supplement to fixing that, does it matter if it is public class or not? (Just sort of curious)
EDIT: Nvm I ran a test program and found that it indeed does not matter. Thanks anyway!
EDIT: Nvm I ran a test program and found that it indeed does not matter. Thanks anyway!
This post has been edited by Dogstopper: 30 November 2009 - 05:58 PM
#7
Re: main method not public error
Posted 30 November 2009 - 06:06 PM
Dogstopper, on 30 Nov, 2009 - 04:56 PM, said:
Alright, in supplement to fixing that, does it matter if it is public class or not? (Just sort of curious)
EDIT: Nvm I ran a test program and found that it indeed does not matter. Thanks anyway!
EDIT: Nvm I ran a test program and found that it indeed does not matter. Thanks anyway!
Sorry

public class Toto { private static void main(String[] args) { System.out.println("Hello"); } }
My Eclipse refuses to launch it as an Application
At the command prompt I get an "Unsupported class version error"
so main() has to be public
Page 1 of 1