Consider this code:
private static void colourRead(String s) throws IOException {
FileReader readhandle = new FileReader("C:\\****\\****");
BufferedReader br = new BufferedReader(readhandle);
String line = null;
while ((line = br.readLine()) != null) {
ColourInput(); //there's an error here
}
br.close();
readhandle.close();
}
private static void ColourInput(String s) {
char letter;
String fullWord;
Scanner kb = new Scanner(System.in);
System.out.print("Enter whatever: ");
fullWord = kb.nextLine();
System.out.println(fullWord);
for (int i = 0; i < fullWord.length(); i++) {
letter = fullWord.charAt(i);
switch (Character.toUpperCase(letter)) {
case 'A': {
Blue();
}
break;
}
}
}
Is it possible for me to carry the
line
variable from the colourRead method, and somehow assign it to the
fullWord
variable in the ColourInput() method?
I'm trying to read a text file, and output certain colours associated to each letter. I don't want to create a new switch statement in the colourRead method because apparently, this is a bad programming practice.
Any help please?
If you're still unsure of what I'm asking I'll re-edit
EDIT: The problem is that after calling the ColourInput(line) method, the Scanner method comes in to work (original code). I don't want to remove my Scanner method, I want it to 'skip' the scanner method, and continue into the for loop and switch statements.