inadaze@mac.com
Registered
Hi,
I am trying a tutorial and nothing happens. I am using xCode java tool and in a folder I have GameLauncher.java,Player.java and GuessGame.java.
Here is the code in each:
//
// GuessGame.java
// GuessGame
//
// Created by Jay on Tue Oct 26 2004.
// Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//
public class GuessGame {
//GuessGame has three variables for each player
Player p1;
Player p2;
Player p3;
public void startGame() {
//create three objects for the three variables
p1 = new Player();
p2 = new Player();
p3 = new Player();
//declare three variables to hold player guess
int guessp1 = 0;
int guessp2 = 0;
int guessp3 = 0;
//declare three variables to hold a true or false player answer
boolean p1isRight = false;
boolean p2isRight = false;
boolean p3isRight = false;
//Make a number for player to guess
int targetNumber = (int) (Math.random() * 10);
System.out.println("I'm thinking of a number between 0 and 9...");
while(true) {
System.out.println("Number to guess is "+targetNumber);
//call each players guess() method
p1.guess();
p2.guess();
p3.guess();
//get each players guess
guessp1 = p1.number;
System.out.println("Player one guessed " + guessp1);
guessp2 = p2.number;
System.out.println("Player one guessed " + guessp2);
guessp3 = p3.number;
System.out.println("Player one guessed " + guessp3);
//test each players answer
if (guessp1 == targetNumber){
p1isRight = true;
}
if (guessp2 == targetNumber){
p2isRight = true;
}
if (guessp3 == targetNumber){
p3isRight = true;
}
//give results of the game
if (p1isRight || p2isRight || p3isRight){
System.out.println("We have a winner!");
System.out.println("Player 1" + p1isRight);
System.out.println("Player 2" + p2isRight);
System.out.println("Player 3" + p3isRight);
System.out.println("The Game is Over!");
break;
} else {
System.out.println("No players were right!!");
}
}
}
}
//
// Player.java
// GuessGame
//
// Created by Jay on Tue Oct 26 2004.
// Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//
public class Player {
//Variable to hold the guess
int number = 0;
public void guess(){
number = (int) (Math.random() * 10);
System.out.println("I'm guessing " + number);
}
}
//
// GameLauncher.java
// GuessGame
//
// Created by Jay on Tue Oct 26 2004.
// Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//
public class GameLauncher {
public static void main (String[] args){
GuessGame game = new GuessGame();
game.startGame();
}
}
When I try the generate .jar file it gives me an error "The jar file "GuessGame.jar" couldn't be launched. Check the Console for possible error messages."
The run log says "Exception in thread "main" java.lang.NoSuchMethodError: main
java has exited with status 1."
And that is all. Any suggestions?
Thanks
Jay
I am trying a tutorial and nothing happens. I am using xCode java tool and in a folder I have GameLauncher.java,Player.java and GuessGame.java.
Here is the code in each:
//
// GuessGame.java
// GuessGame
//
// Created by Jay on Tue Oct 26 2004.
// Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//
public class GuessGame {
//GuessGame has three variables for each player
Player p1;
Player p2;
Player p3;
public void startGame() {
//create three objects for the three variables
p1 = new Player();
p2 = new Player();
p3 = new Player();
//declare three variables to hold player guess
int guessp1 = 0;
int guessp2 = 0;
int guessp3 = 0;
//declare three variables to hold a true or false player answer
boolean p1isRight = false;
boolean p2isRight = false;
boolean p3isRight = false;
//Make a number for player to guess
int targetNumber = (int) (Math.random() * 10);
System.out.println("I'm thinking of a number between 0 and 9...");
while(true) {
System.out.println("Number to guess is "+targetNumber);
//call each players guess() method
p1.guess();
p2.guess();
p3.guess();
//get each players guess
guessp1 = p1.number;
System.out.println("Player one guessed " + guessp1);
guessp2 = p2.number;
System.out.println("Player one guessed " + guessp2);
guessp3 = p3.number;
System.out.println("Player one guessed " + guessp3);
//test each players answer
if (guessp1 == targetNumber){
p1isRight = true;
}
if (guessp2 == targetNumber){
p2isRight = true;
}
if (guessp3 == targetNumber){
p3isRight = true;
}
//give results of the game
if (p1isRight || p2isRight || p3isRight){
System.out.println("We have a winner!");
System.out.println("Player 1" + p1isRight);
System.out.println("Player 2" + p2isRight);
System.out.println("Player 3" + p3isRight);
System.out.println("The Game is Over!");
break;
} else {
System.out.println("No players were right!!");
}
}
}
}
//
// Player.java
// GuessGame
//
// Created by Jay on Tue Oct 26 2004.
// Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//
public class Player {
//Variable to hold the guess
int number = 0;
public void guess(){
number = (int) (Math.random() * 10);
System.out.println("I'm guessing " + number);
}
}
//
// GameLauncher.java
// GuessGame
//
// Created by Jay on Tue Oct 26 2004.
// Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//
public class GameLauncher {
public static void main (String[] args){
GuessGame game = new GuessGame();
game.startGame();
}
}
When I try the generate .jar file it gives me an error "The jar file "GuessGame.jar" couldn't be launched. Check the Console for possible error messages."
The run log says "Exception in thread "main" java.lang.NoSuchMethodError: main
java has exited with status 1."
And that is all. Any suggestions?
Thanks
Jay