Assignment #120
Code
//jack newsom
//period 5
//program Receipt
//filename Receipt.java
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Receipt {
public static void main(String[] args) {
PrintWriter fileOut;
Scanner bot = 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);
}
final double PRICE_PER_GALLON = 2.50;
System.out.println("How many gallons do you want?");
double gallons = bot.nextDouble();
double price = PRICE_PER_GALLON*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: $ "+PRICE_PER_GALLON+" |" );
fileOut.println( "| |" );
fileOut.println( "| Fuel total: $ "+price+" |" );
fileOut.println( "| |" );
fileOut.println( "+------------------------+" );
fileOut.close();
}
}
Picture of the output