• Log in or sign up for an account here: https://www.sythe.org/login

help me with my script

pin plaza

Apprentice
Joined
Jul 24, 2008
Sythe Gold
0
Messages
635
Location
ask ur mom
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.


}
}
}
 
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.


}
 
Vouch For Hapne-92 Good Java Coder...
Lol Helped Me With My Code =)
 
Runescape Gamblingrunescape gambling
Back
Top