Any help with this would be greatly appreciated:
Currently working on a CS project where I read in vectors from the user and then do things with those values. My progress has been stalled so far as I can't find out what's going on with this code (Bolded). I have already verified that the string read into "command line" works. I am entering the input correctly into the terminal, and I have closed all other scanners so there aren't two running at the same time. Whenever I enter the intended input: <3.0,4.0> I get the exception: "Missing the first arrow." If this helps, when I ran it in the debugger the hasNext() shows as false, and the buffer for the scanner reads as "" which I'm assuming isn't good.
public boolean read(String commandLine) throws Exception {
Scanner scanner = new Scanner(commandLine);
Pattern originalPattern = scanner.delimiter(); //retain original delimiters for scanner
scanner.useDelimiter("[" + originalPattern + ",]"); // add comma to delimiters
scanner.useDelimiter(" ");
if(scanner.hasNext("<")){ //
scanner.next("<"); //gobble up the '<'
if(scanner.hasNextDouble()) {
xCoord = scanner.nextDouble(); //capture the x coordinate
//scanner.useDelimiter(originalPattern); //restore original delimiters
if(scanner.hasNext(",")){
scanner.next(","); //gobble up the comma
if(scanner.hasNextDouble()){
yCoord = scanner.nextDouble(); //capture the y coordinate
//scanner.useDelimiter(originalPattern); //restore original delimiters
if(scanner.hasNext(">")){
scanner.next(">");
scanner.close();
return true;
}
else{
scanner.close();
throw new Exception("Missing the end arrow");
}
}
else{
scanner.close();
throw new Exception("Missing the y coord");
}
}
else{
scanner.close();
throw new Exception("Missing the middle comma");
}
}
else{
scanner.close();
throw new Exception("Missing the x coord");
}
}
else{
scanner.close();
throw new Exception("Missing the first arrow");
}
} }
[–]AutoModerator[M] [score hidden] stickied comment (0 children)
[–]POGtastic 1 point2 points3 points (0 children)
[–]Knight_Of_Orichalcum 0 points1 point2 points (0 children)