I'm also a bit confused about what you're trying to do, including why you're forwarding the answer to e.g. new UserPick(). Also don't understand why these are where u have problems. in any case, check out the code below - perhaps it does something similar to what u want to do. note that since class UserPick is inside class Program, it can 'see' variable stdin.
Code:
public class Program
{
private BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args)
throws IOException
{
new Main();
}
public Program()
throws IOException
{
System.out.print("Do you want computer to pick number? y/n: ");
String answer = stdin.readLine();
if (answer.equalsIgnoreCase("y")) {
Object myRndPick = new RndPick();
}
else if (answer.equalsIgnoreCase("n")) {
UserPick myUserPick = new UserPick();
}
else {
System.out.print("Please enter y or n");
}
}
class UserPick
{
double userNum, total;
String dataIn;
UserPick()
throws IOException
{
System.out.print("Please enter a quantity between 1 and 100: ");
dataIn = stdin.readLine();
userNum = Double.parseDouble(dataIn);
total = userNum * 5;
}
}
}
Bookmarks