Skip to content

Instantly share code, notes, and snippets.

@yassaa
Created November 15, 2014 19:21
Show Gist options
  • Save yassaa/1cb8651ff62f9b6ef2ff to your computer and use it in GitHub Desktop.
Save yassaa/1cb8651ff62f9b6ef2ff to your computer and use it in GitHub Desktop.
confirmation class
package exam.project.sketch;
import java.util.*;
import java.io.*;
public class Test_Confirmation {
public static void main(String[] args) {
//create a confirmation
Confirmation confirmation1 = new Confirmation();
//print booking number
System.out.println("Your payment has been confirmed. Your booking number is " +
confirmation1.getBookingNumber() + ".\nPlease keep this number to pick up your tickets at the counter.\n");
//Create an output with booking number, price, number of seats, movie info
try(DataOutputStream output = new DataOutputStream(
new FileOutputStream("confirmation1_email.dat"))){
/*try statements - try writing all objects to file - please note
most of these are placeholders till we compile all the code*/
Date startTime = new Date();
output.writeInt(confirmation1.getBookingNumber());
/*output.writeDouble(payment1.getTotalPrice());
output.writeInt(order1.getNumberOfTickets());*/
output.writeUTF("movie title");
output.writeUTF(startTime.toString());
}
//adding catch blocks
catch (IOException ex) {
System.out.println("Something went wrong while sending the confirmation mail.");
}
//test the writing
try(DataInputStream input = new DataInputStream(
new FileInputStream("confirmation1_email.dat"))){
//try statements - try reading all objects to file
System.out.println("Booking number: " + input.readInt());
/*System.out.println("Total price: " + input.readDouble());
System.out.println("Number of reserved tickets: " + input.readInt());*/
System.out.println("Movie title: " + input.readUTF());
System.out.println("Start time: " + input.readUTF());
}
//adding catch blocks
catch (IOException ex) {
System.out.println("Something went wrong while sending the confirmation mail.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment