Prog 120: Programs that Write to Files
//Name: Ilana Levy
//Period: 5
//Program Name: Programs that Write to Files
//File Name: programsToFiles
//Date Finished: 2/10/16
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class programsToFiles {
public static void main(String[] args) {
PrintWriter fileOut;
try{
fileOut = new PrintWriter("myReceipt.txt");
} catch(IOException e) {
System.out.println("Sorry, I can't open the file 'receipt.txt' for editing.");
System.out.println("Maybe the file exists and is read-only?");
fileOut = null;
System.exit(1);
}
double galPrice = 3.50;
Scanner keyboard = new Scanner( System.in);
System.out.print( "How many gallons do you want?");
double gallons = keyboard.nextInt();
double total = galPrice * gallons;
fileOut.println( "+------------------------+" );
fileOut.println( "| |" );
fileOut.println( "| CORNER STORE |" );
fileOut.println( "| |" );
fileOut.println( "| 2016-01-25 04:38PM |" );
fileOut.println( "| |" );
fileOut.println( "| Gallons: "+gallons+" |" );
fileOut.println( "| Price/gallon: $ "+galPrice+" |" );
fileOut.println( "| |" );
fileOut.println( "| Fuel total: $ "+total+" |" );
fileOut.println( "| |" );
fileOut.println( "+------------------------+" );
fileOut.close();
}
}