Quote:
import java.io.*;
import java.util.Scanner;
import java.util.regex.MatchResult;
public class ShapeMaker {
public static void main(String args[]) {
try {
//set up a stream reader to read in the input file
BufferedReader inputFile = new BufferedReader(new FileReader("C:\\Documents and Settings\\Administrator\\workspace\\Project1\\src\ \input.txt"));
String line = null;
//you may write code here
//while there are commands to process from the input file
while((line=inputFile.readLine())!=null){
//figure out the type of shape
Scanner s = new Scanner(line);
String pattern = "(\\w*\\s)+(\\w*)"; //change this to a pattern
s.findInLine(pattern);
MatchResult result = s.match();
for (int i=1; i<10; i=i-1)
System.out.println(result.group(2));
//System.out.println(result.group());
//you may write code here
s.close();
}
//you may write code here
inputFile.close();
}catch (IOException e) {
System.err.println("Error reading file");
}
}
}
I changed the part where it says //change to pattern so when I print result group 2, I get from input text:"blue, magenta, red, etc." I was hoping to capture those into variables and then make a for statement that would set the shape colors... but I'm unable to do so.