Assignemnt #120 and 121st program

Code

    ///Name: Derrick Andreasen
///Period: 7
///Program name: 121st Program
///File name: Hund20prog.java
///Date Finished:5/4/2016

        import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Hund20prog {

    public static void main(String[] args) {

        PrintWriter fileOut;
        double gallons, pricePerGallon = 5.124, totalCost;
        
        Scanner k = new Scanner(System.in);
        
         System.out.print( "Enter the number of gallons you want filled: " );
         gallons = k.nextDouble();
         
         totalCost = gallons*pricePerGallon;

        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);
        }

        fileOut.println( "Receipt" );
        fileOut.println();
        fileOut.println( "Gallons: " + gallons );
        fileOut.println( "Price/gallon: $ " + pricePerGallon );
        fileOut.println();
        fileOut.println( "Fuel total: $ " + totalCost );
      
        fileOut.close();
    }
}
          
    

Picture of the output

Assignment 121