• Post Reply Bookmark Topic Watch Topic
  • New Topic

help with parameter passing  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying to code methods that will (first) ask for user input (second) this method validates the number (third) a method that creates an array based on the number entered. I have hit a wall, any input greatly appr.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
post your wall
(we'll see if we can loosen a few bricks for you)
 
Grant Allen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay here it is;
import java.io.*;
public class Test {

public static String readString(){
String value = null;
try{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
value = in.readLine();
}catch(Exception e){}
return value;
}
public static int readInt(){
return Integer.parseInt(readString());
}
private static void Input(){
System.out.println("ENter a max");
int max = Test.readInt();
System.out.println("ENter a min");
int min = Test.readInt();
System.out.println("ENter a value between the two");
int num = Test.readInt();

}
private static int Validate(int min, int max, int size){
size = Integer.parseInt(readString());
if(size > min && size < max){
return size;
}
return -1;
}
private static void populateIntArray(int min, int max, int size){
int[] myArray = new int[size];
}


public static void main(String[] args){
}
}
im lost
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
at present main() doesn't do anything
if you work with an instance of Test in main(), you don't need all of the 'statics'
unless that is your intention



if you do it this way, in Input() all the
Test.readInt();
become
readInt();

also in Input() you will need to validate each of the input numbers.
By validate I don't mean your validate method but the data itself - what if "abc" was entered?
you need to wrap these in a try/catch block, and that wrapped in a while loop,
to continue until a valid number is entered

something like this (for the first one)


when you get to the last readInt() you will also need to include a call to
your Validate(), the while to continue if the return value is < 0
 
Grant Allen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks alot
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!