returning data type problem..

hi...all..I am going to construct a meun.And, this meun have 4 choice for it`s user. In other words, the valid value is only within 1 to 4. it is an ivalid value if it is out of the range. Therefore, i implement a function called getInteger( ) to restrict the value...only 1 to 4.. however , i got a strange return after go through my function ..could anyone give me some suggestion..thx ..i have stated my problem in my code ....

import java.util.Scanner;

import java.io.*;

public class Test{

Test()

{

}

private int getInteger(int checkThing, int lowerBound, int upperBound)

{

int aInt = 0;

try

{

while((checkThing < lowerBound ) || (checkThing > upperBound) )

throw new Exception("Invaild value....Please enter the value between " + lowerBound + " & " + upperBound );

}

catch (Exception e)

{

String message = e.getMessage();

System.out.println(message);

//System.exit(0);

// t("Please the value between " + lowerBound + "&" + upperBound );

}

return aInt;

}

public static void main(String[] args)

{

Scanner scan = new Scanner(System.in);

int userInput;

int outPut;

Test example1 = new Test();

System.out.println("Please enter your value between 1 to 4:");

userInput = scan.nextInt();

System.out.println("Your input is " + userInput);//checking the userInput value

outPut = example1.getInteger(userInput, 1, 4);

System.out.println("Your output is " + outPut); //checking the output value

//Here is my Problem. I could do what i want to do

// when i try to input an invalid value, -1 ,to the program

//The result comes up as the following:

// Your input is -1

//Invaild value....Please enter the value between 1 & 4

// Your output is 0

//But, once i try to input a valid value ,2, to the program

//The result comes up as the following:

//Your input is 2

//Your output is 0 <<- (it should be 2 <_> ....Please help...pls...pls)

//how do i get the return (int) back from the function? what`s wrong with my code?

}

}

[2236 byte] By [Ivan1238a] at [2007-11-27 5:30:15]
# 1
you assign the value "0" to aInt , and return it without never assigning a new value to itso w/e the input you give, your method still returns 0
calvino_inda at 2007-7-12 14:54:08 > top of Java-index,Java Essentials,Java Programming...
# 2
just return checkThing...
apanousisa at 2007-7-12 14:54:09 > top of Java-index,Java Essentials,Java Programming...
# 3

hint:

int typed = -1;

while (typed < lowerBound || typed > upperBound) {

System.out.println("please enter something between the bounds!");

typed = scanner.nextInt();

}

calvino_inda at 2007-7-12 14:54:09 > top of Java-index,Java Essentials,Java Programming...
# 4
int aInt = checkThing; change in getInteger method
AnanSmritia at 2007-7-12 14:54:09 > top of Java-index,Java Essentials,Java Programming...
# 5
why not just return checkThing in the method?
apanousisa at 2007-7-12 14:54:09 > top of Java-index,Java Essentials,Java Programming...
# 6
Hey, I've got an idea... it might be a little crazy, though.Why not just return checkThing in the getInteger method? ;)
kevjavaa at 2007-7-12 14:54:09 > top of Java-index,Java Essentials,Java Programming...
# 7
thx all
Ivan1238a at 2007-7-12 14:54:09 > top of Java-index,Java Essentials,Java Programming...