Commit 2de7299d authored by andrea.munoz-white's avatar andrea.munoz-white

Vending Machine

parent f41cfa35
...@@ -14,6 +14,8 @@ import java.io.FileWriter; ...@@ -14,6 +14,8 @@ import java.io.FileWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.IOException; import java.io.IOException;
import java.io.File; import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
//used to create a file //used to create a file
public class VendingMachine extends javax.swing.JFrame { public class VendingMachine extends javax.swing.JFrame {
...@@ -277,12 +279,18 @@ public class VendingMachine extends javax.swing.JFrame { ...@@ -277,12 +279,18 @@ public class VendingMachine extends javax.swing.JFrame {
File file = new File ("/Users/andrea.munoz-white/Documents/reciept.txt"); File file = new File ("/Users/andrea.munoz-white/Documents/reciept.txt");
//Creates a file in the specified direcotry //Creates a file in the specified direcotry
try {
FileWriter writer = new FileWriter(file); FileWriter writer = new FileWriter(file);
writer.write("Order : \n" + SelectedProducts.getText() +
"\nEntered Amount (£): " + amount + writer.write("Order : \n" + SelectedProducts.getText() +
"\nTotal Price (£): " + cost + "\nEntered Amount (£): " + amount +
"\nChange Due (£): " + change1); "\nTotal Price (£): " + cost +
writer.close(); "\nChange Due (£): " + change1);
writer.close();
} catch (IOException ex) {
Logger.getLogger(VendingMachine.class.getName()).log(Level.SEVERE, null, ex);
}
//used this webpage for refrence https://www.journaldev.com/20891/java-filewriter-example //used this webpage for refrence https://www.journaldev.com/20891/java-filewriter-example
emptytext(); emptytext();
// calls the method empty text // calls the method empty text
...@@ -292,7 +300,7 @@ public class VendingMachine extends javax.swing.JFrame { ...@@ -292,7 +300,7 @@ public class VendingMachine extends javax.swing.JFrame {
// if the user input amount is less than the total amount then the program prints that the user doesn't have enough money. // if the user input amount is less than the total amount then the program prints that the user doesn't have enough money.
} }
}//GEN-LAST:event_jButton2ActionPerformed }//GEN-LAST:event_jButton2ActionPerformed
}
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment