/    Sign up×
Community /Pin to ProfileBookmark

; expected error

I get the following error when trying to compile: “40 error: ; expected”

There is a ; at that line

[CODE]

import java.util.Random;
import java.io.*;

public class DealorNoDeal {

public static void main (String[] args) {

System.out.println( “Welcome to Deal or No Deal Game!” );

System.out.println( “In this game, there are 10 cases containing” +

“various amounts of money. Three of those cases contain no money.”+

“Of the seven cases that do contain money, they contain the” +

“following amounts: $1, $10, $100, $1,000, $10,000, $100,000” +

“and $1,000,000”);

System.out.println(“You will be asked to select a case to open.”+

“You’ll have the opportunity to open up to 3 cases. But, if you” +

“decide you like the amount before the third case is opened, you”+

“can stop the game at that point. But, if you use all three” +

“tries,you’ll have to take the amount received on your” +

“third try.”);

System.out.println(“Let’s start the game!”);

//Setup looping mechanism to ensure user can only guess a maximum of three times.

for (numofGuesses=0;numofGuesses < 3;) {
GameHelper helper = new GameHelper();
helper.getUserInput(“Enter a case number between 0 and 9: “);

//Display the amount contained in the case selected by user
System.out.println(“The case you selected contains: ” +

(Val(arr[position])));

helper.getUserYN(“Deal or No Deal? Y or N”);
if (line.equalsIgnoreCase(“N”)) {
numofGuesses++; //If user answers “n” continue loop
}

else {

break; //If user answers “y” terminate the loop

}
}

//Print the amount user has won. Game over at this point.
System println(“The amount you’ve won is:” + (val(arr[position])));

}

}

public class RandomArr {

private static Random rand = new Random ();

// instance variable to hold dollar amounts inside an array
private int [] arr = { 0,0,0,1,10,100,1000,10000,100000,1000000};

// setter method that randomly assigns amounts to positions inside array
public RandomArr(){
int tempVal;
int randPos;

for ( int i=0; i<10; i++ ) {
for ( int j=0; i<arr.length; i++ ) {
randPos = rand.nextInt ( arr.length );
tempVal = arr[j];
arr[j] = arr[randPos];
arr[randPos] = tempVal;
}
}
}

// getter for value of a certian position inside the array
public int getValue(int position){
return arr[position];
}
}

public class GameHelper {

public String getUserInput(String prompt) {

String inputLine = null;
System.out.print(prompt + ” “);

try {
BufferedReader is = new BufferedReader(new

InputStreamReader(System.in));
inputLine = is.readLine();

if (inputLine.length() == 0) return null;
}

catch (IOException e) {
System.out.println(“Exception: ” + e);
}

return inputLine;
}

// getter method that converts String value received from the user into an

//integer
public int getUserInt(String prompt){

String line = getUserInput(prompt);
int val = Integer.parseInt(line);

return val;

}

// getter boolean method that returned true if the user pressed Y and false

//otherwise
// this is for the step when the user is asked Deal or No Deal question
public boolean getUserYN(String prompt){
String line = getUserInput(prompt);

return(line.equalsIgnoreCase(“Y”));
}

}

[/CODE]

to post a comment
Java

1 Comments(s)

Copy linkTweet thisAlerts:
@ssdogSep 20.2013 — [CODE]
import java.util.Random;
import java.io.*;

public class DealorNoDeal {

public static void main (String[] args) {

System.out.println( "Welcome to Deal or No Deal Game!" );

System.out.println( "In this game, there are 10 cases containing" +

"various amounts of money. Three of those cases contain no money."+

"Of the seven cases that do contain money, they contain the" +

"following amounts: $1, $10, $100, $1,000, $10,000, $100,000" +

"and $1,000,000");

System.out.println("You will be asked to select a case to open."+

"You'll have the opportunity to open up to 3 cases. But, if you" +

"decide you like the amount before the third case is opened, you"+

"can stop the game at that point. But, if you use all three" +

"tries,you'll have to take the amount received on your" +

"third try.");

System.out.println("Let's start the game!");

//Setup looping mechanism to ensure user can only guess a maximum of three times.


for (numofGuesses=0;numofGuesses < 3;) {
GameHelper helper = new GameHelper();
helper.getUserInput("Enter a case number between 0 and 9: ");

//Display the amount contained in the case selected by user
System.out.println("The case you selected contains: " +

(Val(arr[position])));


helper.getUserYN("Deal or No Deal? Y or N");
if (line.equalsIgnoreCase("N")) {
numofGuesses++; //If user answers "n" continue loop
}

else {

break; //If user answers "y" terminate the loop

}
}

//Print the amount user has won. Game over at this point.
[SIZE=5][COLOR="#FF0000"]System[B].out.[/B]println("The amount you've won is:" + (val(arr[position])));[/COLOR][/SIZE]
}

}

public class RandomArr {

private static Random rand = new Random ();

// instance variable to hold dollar amounts inside an array
private int [] arr = { 0,0,0,1,10,100,1000,10000,100000,1000000};

// setter method that randomly assigns amounts to positions inside array
public RandomArr(){
int tempVal;
int randPos;

for ( int i=0; i<10; i++ ) {
for ( int j=0; i<arr.length; i++ ) {
randPos = rand.nextInt ( arr.length );
tempVal = arr[j];
arr[j] = arr[randPos];
arr[randPos] = tempVal;
}
}
}

// getter for value of a certian position inside the array
public int getValue(int position){
return arr[position];
}
}



public class GameHelper {


public String getUserInput(String prompt) {

String inputLine = null;
System.out.print(prompt + " ");

try {
BufferedReader is = new BufferedReader(new

InputStreamReader(System.in));
inputLine = is.readLine();

if (inputLine.length() == 0) return null;
}

catch (IOException e) {
System.out.println("Exception: " + e);
}

return inputLine;
}


// getter method that converts String value received from the user into an

//integer
public int getUserInt(String prompt){

String line = getUserInput(prompt);
int val = Integer.parseInt(line);

return val;

}

// getter boolean method that returned true if the user pressed Y and false

//otherwise
// this is for the step when the user is asked Deal or No Deal question
public boolean getUserYN(String prompt){
String line = getUserInput(prompt);

return(line.equalsIgnoreCase("Y"));
}

}
[/CODE]
×

Success!

Help @MichiKen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.22,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...