Results 1 to 2 of 2
  1. #1
    vuzuggu is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Saving string to list to add to file

    Hey,

    I have to design a program to create a file of sums. The user inputs the sum and then it gets outputted to a new file. The problem for me is that the file should only be written once, when all the sums are completed and the user ends the program. So as it goes along each sum should be added to a list and then I can write the list to the file. I have pasted the code so far below so you can get a general idea. I'd really appreciate it if someone could give me a few tips.

    Thanks!

    Java Code:
    import tcdIO.*;
    public class SumCreator {
    	public static void main(String[] args) {
    		Terminal terminal = new Terminal("Sum Program");
    		
    		terminal.println("Welcome to my program.");
    		terminal.println("");
    		terminal.println("Please follow the instructions to create your file.");
    		terminal.println("1. Addition Sum");
    		terminal.println("2. Subtraction Sum");
    		terminal.println("3. Division Sum");
    		terminal.println("4. Multiplication sum");
    		terminal.println("0. End program and create file");
    		terminal.println("");
    		int type = terminal.readInt("Enter your selection: ");  
    		terminal.println("");
    		if (type == 1) {
    			terminal.println("You have selected addition.");
    			terminal.println(" ");
    			String a = terminal.readString("Please select your first operand or a to abort: ");
    			String b = terminal.readString("Please select your second operand or a to abort: ");
    			String sum = a + " + " + b;
    			terminal.println(sum);
    		}
    		else if (type == 2) {
    			terminal.println("You have selected subtraction.");
    			terminal.println(" ");
    			String a = terminal.readString("Please select your first operand or a to abort: ");
    			String b = terminal.readString("Please select your second operand or a to abort: ");
    			String sum = a + " - " + b;
    			terminal.println(sum);
    		}
    		else if (type == 3) {
    			terminal.println("You have selected division.");
    			terminal.println(" ");
    			String a = terminal.readString("Please select your first operand or a to abort: ");
    			String b = terminal.readString("Please select your second operand or a to abort: ");
    			String sum = a + " / " + b;
    			terminal.println(sum);
    		}
    		else if (type == 4) {
    			terminal.println("You have selected multiplication.");
    			terminal.println(" ");
    			String a = terminal.readString("Please select your first operand or a to abort: ");
    			String b = terminal.readString("Please select your second operand or a to abort: ");
    			String sum = a + " * " + b;
    			terminal.println(sum);
    }
    	}
    
    }

  2. #2
    dheaven is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

Similar Threads

  1. Replies: 8
    Last Post: 11-04-2011, 08:30 PM
  2. Saving a File
    By sneeak in forum New To Java
    Replies: 1
    Last Post: 08-17-2011, 05:40 AM
  3. saving a string data.
    By imorio in forum New To Java
    Replies: 7
    Last Post: 11-18-2010, 11:33 AM
  4. Saving a file in a gui
    By rav in forum AWT / Swing
    Replies: 9
    Last Post: 07-07-2010, 05:27 PM
  5. Replies: 8
    Last Post: 02-18-2010, 12:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •