Hey all. I'm currently doing a project for my Java class, and let's just say I'm not the greatest around when it comes to programming. I'm currently stuck at the outputting lines part and would be very grateful for any help on this. 
Instructions:
1. Create a BlueJ project named C140-YourLastName-FinalProject
2. Create 2 classes: SimpleText and TextProcs and prepare them for use. (Compile each)
3. The TextProcs class will contain your methods. create empty methods named
enterlines(), outputlines, savelines and loadlines. (Compile)
Hint: Place single (temporary) output statements into each that identifies what they are. (Compile)
This will aid in debugging the SimpleText Class without placeing detail in the methods.
These statement can be commented out or removed as detail is added later.
4. SimpleText will contain the program entry method. Place this method in SimpleText (Compile)
5. In the Simpletext entry method place the following:
a. declare and initialize all variables
// a loop variable of boolean data type initialized to true (Compile)
// a string variable to contain a single letter choice input from a menu initialized to a null string (Compile)
// a numberic variable to contain the conversion of the string variable to a number initialized to 0 (Compile)
// A string variable to contain a concatenated string (initialized to prompt the user to select an option and to
// display each menu option on separate lines in an InputDialog) where options are:
// Enter Lines, Output Lines, Save Lines, Load Lines, and Quit (Compile)
b. declare and instantiate an string array to a size of 10 (to contain 10 strings)
c. declare and instantiate any external class to be used (Compile)
d. construct a loop that will run as long as the boolean loop variable is true (Compile at each step)
Inside the loop:
// provide any conversion necessary to ensure that conditional test variables have the correct data type
// and that selection and looping functions properly based upon these values
// construct conditional structure(s) to run methods in the TextProcs class based upon the menu selection
// (i.e., enterlines(), outputlines, savelines and loadlines) or quits the program.
// provide appropriate code for each item. (If done properly can be done with a single line for each)
// if an inappropriate selection is made, display the correct options to the user and reloop
e. After the loop, Output a statement that acknowledges that the program is ended. (Compile)
6. Place detail in the methods contained in the TextProcs class (Compile at each step)
a. the enterlines method()
// requires no arguments
// declares a string array to contain 10 elements
// loops through successive prompts for string values for each line
// returns the resulting populated string array variable
b. the outputlines method()
// requires a string array argument
// loops through the array passed to it and displays each line to the terminal
// returns no value
c. the savelines() method
// requires a string array argument
// saves each line of the strring array passed to it to a text file named savedtext.txt
// returns no value
d. the loadfile() method
// requires no arguments
// declares a string array to contain 10 elements
// reads values from a file named savedtext.txt and places each line into a line of the declared array
// returns a string array variable (declared internally to contain 10 elements)
Code so far(does not compile):
Simple Text class-
TextProcs class-
Currently, the Simple Text class does not compile. It highlights where I am trying to import the outputlines method and says ") expected"

Instructions:
1. Create a BlueJ project named C140-YourLastName-FinalProject
2. Create 2 classes: SimpleText and TextProcs and prepare them for use. (Compile each)
3. The TextProcs class will contain your methods. create empty methods named
enterlines(), outputlines, savelines and loadlines. (Compile)
Hint: Place single (temporary) output statements into each that identifies what they are. (Compile)
This will aid in debugging the SimpleText Class without placeing detail in the methods.
These statement can be commented out or removed as detail is added later.
4. SimpleText will contain the program entry method. Place this method in SimpleText (Compile)
5. In the Simpletext entry method place the following:
a. declare and initialize all variables
// a loop variable of boolean data type initialized to true (Compile)
// a string variable to contain a single letter choice input from a menu initialized to a null string (Compile)
// a numberic variable to contain the conversion of the string variable to a number initialized to 0 (Compile)
// A string variable to contain a concatenated string (initialized to prompt the user to select an option and to
// display each menu option on separate lines in an InputDialog) where options are:
// Enter Lines, Output Lines, Save Lines, Load Lines, and Quit (Compile)
b. declare and instantiate an string array to a size of 10 (to contain 10 strings)
c. declare and instantiate any external class to be used (Compile)
d. construct a loop that will run as long as the boolean loop variable is true (Compile at each step)
Inside the loop:
// provide any conversion necessary to ensure that conditional test variables have the correct data type
// and that selection and looping functions properly based upon these values
// construct conditional structure(s) to run methods in the TextProcs class based upon the menu selection
// (i.e., enterlines(), outputlines, savelines and loadlines) or quits the program.
// provide appropriate code for each item. (If done properly can be done with a single line for each)
// if an inappropriate selection is made, display the correct options to the user and reloop
e. After the loop, Output a statement that acknowledges that the program is ended. (Compile)
6. Place detail in the methods contained in the TextProcs class (Compile at each step)
a. the enterlines method()
// requires no arguments
// declares a string array to contain 10 elements
// loops through successive prompts for string values for each line
// returns the resulting populated string array variable
b. the outputlines method()
// requires a string array argument
// loops through the array passed to it and displays each line to the terminal
// returns no value
c. the savelines() method
// requires a string array argument
// saves each line of the strring array passed to it to a text file named savedtext.txt
// returns no value
d. the loadfile() method
// requires no arguments
// declares a string array to contain 10 elements
// reads values from a file named savedtext.txt and places each line into a line of the declared array
// returns a string array variable (declared internally to contain 10 elements)
Code so far(does not compile):
Simple Text class-
Code:
import javax.swing.JOptionPane;
public class SimpleText
{
public static void main(String[]args){
// a string variable to contain a single letter choice input
//from a menu initialized to a null string (Compile)
String letter;
letter = null;
// a numberic variable to contain the conversion
//of the string variable to a number initialized to 0 (Compile)
int conversion = 0;
// A string variable to contain a concatenated string (initialized to prompt the user to
//select an option and to display each menu option on separate lines in an InputDialog) where options are:
//Enter Lines, Output Lines, Save Lines, Load Lines, and Quit (Compile)
String input = "Select an option\nEnter Lines\nOutput Lines\nSave Lines\nLoad Lines\nQuit";
input = JOptionPane.showInputDialog(null,
"Select an option\nEnter Lines\nOutput Lines\nSave Lines\nLoad Lines\nQuit",
"SimpleText Input", JOptionPane.QUESTION_MESSAGE);
//declare a string array of 10
String[] array = new String [10];
//declare loop of boolean datatype
for (int i = 1; i < 10; i++) {
}
do
{
//instantiate an object for TextProcs
TextProcs textprocs = new TextProcs();
if (input.equals("E")){
//call method containing file IO
textprocs.enterlines();
//trap any error
}
else{
input = JOptionPane.showInputDialog(null,
"Select an option\nEnter Lines\nOutput Lines\nSave Lines\nLoad Lines\nQuit",
"SimpleText Input", JOptionPane.QUESTION_MESSAGE);
}
if (input.equals("L")){
//call method containing file IO
textprocs.loadlines();
//trap any error
}
else{
input = JOptionPane.showInputDialog(null,
"Select an option\nEnter Lines\nOutput Lines\nSave Lines\nLoad Lines\nQuit",
"SimpleText Input", JOptionPane.QUESTION_MESSAGE);
}
try{
if (input.equals("S")) {//call method containing file IO
textprocs.savelines();
//trap any error
}
}
catch (Exception ex){
input = JOptionPane.showInputDialog(null,
"Select an option\nEnter Lines\nOutput Lines\nSave Lines\nLoad Lines\nQuit",
"SimpleText Input", JOptionPane.QUESTION_MESSAGE);
}
try {
if (input.equals("O"))
textprocs.outputlines(String myList);
}
catch (Exception ex) {
input = JOptionPane.showInputDialog(null,
"Select an option\nEnter Lines\nOutput Lines\nSave Lines\nLoad Lines\nQuit",
"SimpleText Input", JOptionPane.QUESTION_MESSAGE);
}
//output a statement that says the program has ended
String output = "Program has ended";
JOptionPane.showMessageDialog(null, output,
"Program has ended", JOptionPane.INFORMATION_MESSAGE);
//exit the program
System.exit(0);
}while (true);}
}
TextProcs class-
Code:
import java.io.*;
import java.util.Scanner;
import java.util.*;
import javax.swing.JOptionPane;
public class TextProcs
{
public void enterlines(){
int[] myList = new int[10];
File file = new File("files/scores2.txt");
// Read all numbers
for (int i = 0; i < myList.length; i++) {
String numString = JOptionPane.showInputDialog(null,
"Enter a number:",
"Example 5.1 Input", JOptionPane.QUESTION_MESSAGE);
// Convert string into integer
myList[i] = Integer.parseInt(numString);
//Display results
//System.out.println(numString);
/* try {
//create a file
PrintWriter output= new PrintWriter(file);
//write formateed outpit to the file
output.print(numString);
}
catch (Exception ex) {
//String output = "The array is ";
/*for (int i = 0; i < myList.length; i++) {
String strInput = JOptionPane.showInputDialog(null, "Enter a number ", "Enter a number", JOptionPane.
INFORMATION_MESSAGE);
output += myList[i] + " ";
System.out.println(strInput);
}*/
System.out.println(numString);
}
}
public void outputlines (String myList)throws Exception{
File file = new File("files/scores2.txt");
Scanner scanner = new Scanner(file);
while (scanner.hasNext()) {
System.out.println(scanner.next());
}
scanner.close();
System.out.println(myList);
}
public void savelines()throws Exception{
FileWriter write = new FileWriter("CreateFile.txt",true );
//FileWriter write = new FileWriter("files/scores2.txt", true );
}
public void loadlines(){
//file.listFiles();
}
}
Currently, the Simple Text class does not compile. It highlights where I am trying to import the outputlines method and says ") expected"

Last edited: