Receipt

Code

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Receipt {

    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);

        double Gal, Cash;
        Gal=3.99;
        Cash=0;
        
        PrintWriter fileOut;

        try{
            fileOut = new PrintWriter("receipt.txt");
            System.out.println( " How many gallons would you like to buy. We currently have 100 gallons, it will cost $ " + Gal + " each gallon "  );
            Cash=keyboard.nextDouble();

            Cash=Cash*Gal;
            
        } 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);
        }

        fileOut.println( "+------------------------+" );
        fileOut.println( "|                        |" );
        fileOut.println( "|     CORNER STORE       |" );
        fileOut.println( "|                        |" );
        fileOut.println( "| 2016-01-25 04:38PM     |" );
        fileOut.println( "|                        |" );
        fileOut.println( "| Gallons: 100           |" );
        fileOut.println( "| Price/gallon: $ 3.99   |" );
        fileOut.println( "|                        |" );
        fileOut.println( "| Fuel total: $ " + Cash + "    |" );
        fileOut.println( "|                        |" );
        fileOut.println( "+------------------------+" );

        fileOut.close();
    }
}

Receipt

Assignment 120