Reputation: 9
// It keeps popping up with this error when I try to compile it that says that it reached the end of the file while parsing, leading me to believe that I have a problem with my '{}' brackets. Please Help!!!
// Here is the code:
import java.util.*;
class GameOfNim
{ public static void main(String [] args)
{ Scanner in = new Scanner (System.in);
int marbles, player, difficulty, pick;
marbles = (int)(Math.random()*90+10);
player = (int)(Math.random()+0.5);
difficulty = (int)(Math.random()+0.5);
if(difficulty == 0)
System.out.println("The Computer is now in Beast Mode!");
else if(difficulty == 1)
System.out.println("The Computer is now in easy mode.");
System.out.println("The pile of marbles has: " + marbles + "total marbles. Game On!");
while(marbles>0)
{ if(player==0)//person
{System.out.print("Pick some marbles");
pick = in.nextInt();}
if (pick >= 1 && pick <= marbles/2){
marbles = marbles - pick;
System.out.println(marbles+"left");}
else if(pick < 1 || pick > marbles/2 && pile > 1){
System.out.println("Error: Illegal Move.");
player = 0;
continue;}
else {
marbles = marbles - pick;
System.out.println(marbles + "left.");
}}
if(player == 1 && difficulty ==1)
{
System.out.println("Computer's turn to pick");
pick = (int)(Math.random()*marbles/2+1);
marbles = marbles - pick;
System.out.println("computer picks: " + pick + "marbles." + "There are: " + marbles + " marbles left.");}
else if(player == 1 && difficulty == 0)
{
System.out.println("Computer's turn to pick");
if(marbles > 63)
{pick = marbles - 63;
marbles = marbles - pick;}
else if(pile > 31)
{pick = marbles - 32;
marbles = marbles - pick;}
else if(pile > 15)
{pick = marbles - 15;
marbles = marbles - pick;}
else if(pile > 7)
{pick = marbles - 7;
marbles = marbles - pick;}
else if(pile > 3)
{pick = marbles - 3;
marbles = marbles - pick;}
else{
pick = (int)(Math.random()*marbles/2+1);
marbles = marbles - pick;
System.out.println("Computer picks: " + pick + "marbles." + "There are: " + marbles + " marbles left.");
}
{if(player==0)
player=1;
else player=0;
}
{if(player==0)
System.out.println("Computer: 'I give up! You win!");
else
System.out.println("Computer: '...You are pathetic...'");
}}
//Note: By debugging the code in chunks. It seems to be the problem may be in my While Loop. but I really don't know.
Upvotes: -1
Views: 139
Reputation: 1
private String name;
private String email;
private int number;
public String getname(){
return name;
}
public void setname(String name){
this.name= name;
}
public String getemail(){
return email;
}
public void setemail(String name){
this.email= email;
}
public String getnumber()}
return number;
}
public staticvoid setnumber(String number){
this.number= number;
}
public static void main(String[] args) {
NameEmailnumber person= new NameEmailnumber();
person.setname("Tumelo Monese");
person.setemail("[email protected]");
person.setnumber("0676613198");
System.out.println(" I am "+ person.getname());
System.out.println( "my email is "+ person.getemail())
System.out.println( " my phone number is "+person.getnumber())
}
}
Upvotes: 0
Reputation: 21
you shoud try indented properly . you can try to change
{if(player==0)
player=1;
else player=0;
}
{if(player==0)
System.out.println("Computer: 'I give up! You win!");
else
System.out.println("Computer: '...You are pathetic...'");
}} `enter code here`
with :
if(player==0)
player=1;
else player=0;
if(player==0)
System.out.println("Computer: 'I give up! You win!");
else
System.out.println("Computer: '...You are pathetic...'");
}
}
Upvotes: -1
Reputation: 2840
Somewhere you're missing two '}' characters, After copy/pasting your code into an IDE I noticed that there were complains about things not lining up. You missed two end brackets.
Also, upon further inspection, it looks like 'pile' never gets declared or initialized to any value.
Upvotes: 0
Reputation: 163
First, your should indent your code properly. You should read a little bit about indentation conventions for Java. Here's an example of a correct indented code:
class GameOfNim {
public static void main(String[] args) {
[...]
if (difficulty == 0) {
System.out.println("The Computer is now in Beast Mode!");
} else if (difficulty == 1) {
System.out.println("The Computer is now in easy mode.");
}
}
}
After fixing the indentation of your code, I have easily found that you are missing two closing brackets at the end of the file, one for your main method and one for your class.
Upvotes: 3
Reputation: 166
Buddy. You should really start by using a coding convention. A clause should either be:
void function(){
}
OR
void function()
{
}
And same goes for if, while loops and classes. Pick a coding standard and stick to it :) As for your problem, you left out the closing bracket '}' for closing the class.
Upvotes: 2