help me with my script

Discussion in 'Programming General' started by pin plaza, Jan 6, 2009.

help me with my script
  1. Unread #1 - Jan 6, 2009 at 8:28 PM
  2. pin plaza
    Joined:
    Jul 24, 2008
    Posts:
    635
    Referrals:
    1
    Sythe Gold:
    0

    pin plaza Apprentice
    Banned

    help me with my script

    ILL VOUCH IF U HELP!
    I AM A NEWB WITH JAVA AND I MAKE VERY SMALL MISTAKES
    look out

    my code is supposed to make a file and write the inputs on it...
    and for some reason it wont can u check my code?



    import java.util.Scanner;
    import java.io.*;

    public class PizzaOrderingMachine {

    public static void main(String args[]) {

    //Declaring Variables


    String firstName; // Contains the first name of the user
    String lastName; // Contains the last name of the user
    String streetAddress; // Containd the street address of the user
    String phoneNumber; // Contains the phone number of the user
    String extentionNumber; // Contains the Extention Number or the Buzzer Number of the User

    Scanner input = new Scanner(System.in); // Making a new scanner object.

    // Making a new file.

    File textFile = new File ("C:\\UserInfo.txt"); // Making a file
    FileWriter out;
    BufferedWriter writeFile;
    try {

    textFile.createNewFile();

    out = new FileWriter(textFile);
    writeFile = new BufferedWriter(out);


    // Asking the user for their first name.
    System.out.println("Please enter your first name.");
    firstName = input.nextLine();
    // Asking the user for their last name.
    System.out.println("Please enter your last name.");
    lastName = input.nextLine();
    // Asking the user for their street address.
    System.out.println("Please enter your street address.");
    streetAddress = input.nextLine();
    // Asking the user for their phone number.
    System.out.println("Please enter your phone number.");
    phoneNumber = input.nextLine();
    // Asking the user for their extention number.
    System.out.println("Please enter your extention number.");
    extentionNumber = input.nextLine();

    writeFile.write(firstName);
    writeFile.write(" ");
    writeFile.write(lastName);
    writeFile.newLine();
    writeFile.write(phoneNumber);
    writeFile.write(extentionNumber);
    writeFile.newLine();
    writeFile.write(streetAddress);

    } catch (IOException e){
    System.out.println("IOException: " + e.getMessage()); // Will output the message if IOExeption is found.


    }
    }
    }
     
  3. Unread #2 - Jan 7, 2009 at 4:23 AM
  4. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    help me with my script

    here take a look at it, now it works just fine :) (just a tip, next time, put your code inside code tags):

    Code:
    // Making a new file.
    
    File textFile = new File ("C:\\UserInfo.txt"); // Making a file
    FileWriter writeFile;
    BufferedWriter out;
    try {
    
    textFile.createNewFile();
    writeFile = new FileWriter(textFile);
    out = new BufferedWriter(writeFile);
    
    textFile.createNewFile();
    
    out.write(firstName);
    out.write(" ");
    out.write(lastName);
    out.newLine();
    out.write(phoneNumber);
    out.write(extentionNumber);
    out.newLine();
    out.write(streetAddress);
    
    out.close();
    
    } catch (IOException e){
    System.out.println("IOException: " + e.getMessage()); // Will output the message if IOExeption is found.
    
    
    }
     
  5. Unread #3 - Jan 8, 2009 at 7:48 PM
  6. pin plaza
    Joined:
    Jul 24, 2008
    Posts:
    635
    Referrals:
    1
    Sythe Gold:
    0

    pin plaza Apprentice
    Banned

    help me with my script

    Vouch For Hapne-92 Good Java Coder...
    Lol Helped Me With My Code =)
     
< Computer Science trouble... again | Hmm lil Help. >

Users viewing this thread
1 guest


 
 
Adblock breaks this site