Assignemnt #120 Programs That Write to Files

Code

     ///Name: Prooz Fereydouni
    ///Period: 7
    ///Project Name: Programs That Write to Files
    ///File Name: Receipt.java
    ///Date: 5/28/2016
    
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 GalPri = 0.001;
            System.out.print("How many gallons would you like to buy? ");
            double Gal = kb.nextDouble();
            double Tot = Gal * GalPri;        

        fileOut.println( "+------------------------+" );
        fileOut.println( "|                        |" );
        fileOut.println( "|     Cheapest STORE     |" );
        fileOut.println( "|                        |" );
        fileOut.println( "| 2016-01-25 04:38PM     |" );
        fileOut.println( "|                        |" );
        fileOut.println( "| Gallons: " + Gal + "        |" );
        fileOut.println( "| Price/gallon: $ " + GalPri + "  |" );
        fileOut.println( "|                        |" );
        fileOut.println( "| Fuel total: $ " + Tot + " |" );
        fileOut.println( "|                        |" );
        fileOut.println( "+------------------------+" );

        fileOut.close();
    }
}
    

    

Picture of the output

assignment120