6 Replies - 2531 Views - Last Post: 30 November 2009 - 06:06 PM Rate Topic: -----

#1 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

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

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	
}



Is This A Good Question/Topic? 0
  • +

Replies To: main method not public error

#2 dukky  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 111
  • Joined: 28-November 09

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...
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

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

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

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
Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2871
  • View blog
  • Posts: 11,026
  • Joined: 15-July 08

Re: main method not public error

Posted 30 November 2009 - 05:38 PM

View Postpbl, 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


pbl, I have a quick question/possible fix?
class ch6Num31 {



Does that have to be public class?
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

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

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

Re: main method not public error

Posted 30 November 2009 - 05:46 PM

View PostDogstopper, on 30 Nov, 2009 - 04:38 PM, said:

View Postpbl, 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


pbl, I have a quick question/possible fix?
class ch6Num31 {



Does that have to be public class?

No it has
private static void main(....
Was This Post Helpful? 1
  • +
  • -

#6 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2871
  • View blog
  • Posts: 11,026
  • Joined: 15-July 08

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!

This post has been edited by Dogstopper: 30 November 2009 - 05:58 PM

Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

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

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

Re: main method not public error

Posted 30 November 2009 - 06:06 PM

View PostDogstopper, 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!

Sorry :rolleyes:


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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1