Assignemnt #120 and Programs That Write to Files
Code
///name: Mark Katz
///period: 6
///program name: Receipt
///file name: Receipt.java
///date finished: 5/6/16
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class receipt {
public static void main(String[] args) {
PrintWriter fileOut;
Scanner kb = new Scanner (System.in);
try{
fileOut = new PrintWriter("receipt.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 ppg = 3.5;
System.out.print("How many gallons would you like to purchase? ");
double g = kb.nextDouble();
double total = g * ppg;
fileOut.println( "+------------------------+" );
fileOut.println( "| |" );
fileOut.println( "| CORNER STORE |" );
fileOut.println( "| |" );
fileOut.println( "| 2016-01-25 04:38PM |" );
fileOut.println( "| |" );
fileOut.println( "| Gallons: " + g + " |" );
fileOut.println( "| Price/gallon: " + ppg + " |" );
fileOut.println( "| |" );
fileOut.println( "| Fuel total: " + total + " |" );
fileOut.println( "| |" );
fileOut.println( "+------------------------+" );
fileOut.close();
}
}