The assignment instructions themselves are quite vague, but here is what is needed:
"Using a JFileChooser, prompt the user for a file to open. Using a Scanner, read one line from this file
at a time, until the end, printing out each line in upper case to System.out."
I take it he means a .txt file. So if "I like cats" is in the .txt file I would have to get it to print through System.out as "I LIKE CATS", correct? If so, I'm having a bit of trouble. I'm able to prompt the user to open a file, but I'm not exactly sure how I would go about getting it to print in all uppercase characters. Here's what I have so far:
import javax.swing.JFileChooser; import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; public class Program2 { public static void main (String[] args) throws FileNotFoundException { JFileChooser chooser = new JFileChooser(); Scanner in = null; if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File selectedFile = chooser.getSelectedFile(); in = new Scanner(selectedFile); while(in.hasNextLine()) { String str = new String(in.nextLine()); System.out.println(str.toUpperCase()); } } } }
Thanks for the help in advance.
Edit: Solved. All I had to do was put the Scanner in a String object so I could gain access to the toUpperCase() method. Updated code to signify this just in case anyone else was having the same problem.