her is a sample of a input file i havet.
2.5
2.5 3
3 three
4.4
3.0 5
***well first off my goal is to read the input file and if on one line there is only one number like 2.5 then i store that one so i can send it to my circle class as the radius. Then if the line has two integers, then i store them both and send both of them to my rectangle class as length, width.
I am having trouble reading the input file a distinguishing how to read a line if it has one integer or two and so on. I know how to read each double and then send it to my circle class but when it comes to two integers im not getting it to work.
So this is what i have got so far and im working on it.
Scanner console = new Scanner(System.in);
Scanner input = new Scanner(new File ("Numbers.txt"));
input.nextLine();
while(input.hasNextLine()) {
double line = input.nextDouble();
shape s1 = new Circle(line);
if(input.hasNextDouble()) {
double d = input.hasNextDouble();
Shape r1 = new Rectangle(line, d);
//(here i am trying to read if there is another interger on the line
//and i dont know what to do to make this thing work)
}
}
This code reads each double and then sends it to my circle class, but i want it to read a line that has two integers so i can send those to my rectangle class. (and also deal with the string in there *3 three* and throw it out)
I have been trying a bunch of different thing but i jsut cant get it to read the input file right. i
So hopefully some people can help me out with this please. Thanks
This post has been edited by jaybfox4: 28 April 2009 - 09:15 AM

New Topic/Question
Reply




MultiQuote



|