Commit ae93b072 authored by robert.sharp's avatar robert.sharp

minor change

parent b0573715
...@@ -309,9 +309,10 @@ public class temp extends javax.swing.JFrame { ...@@ -309,9 +309,10 @@ public class temp extends javax.swing.JFrame {
quant = Double.parseDouble(quantBox.getSelectedItem().toString()); quant = Double.parseDouble(quantBox.getSelectedItem().toString());
//find the slected item and convet it into a double //find the slected item and convet it into a double
quantLabelchange.setText("Selected quantity: "+quant); quantLabelchange.setText("Selected quantity: "+quant);
//update the display to show the quanity of item wanted //update the display to show the quanity of item
cost = price[index]*quant; cost = price[index]*quant;
Total.setText("Total: "+ cost); Total.setText("Total: "+ cost);
} }
private void PurchaseActionPerformed(java.awt.event.ActionEvent evt) { private void PurchaseActionPerformed(java.awt.event.ActionEvent evt) {
...@@ -430,7 +431,6 @@ public class temp extends javax.swing.JFrame { ...@@ -430,7 +431,6 @@ public class temp extends javax.swing.JFrame {
} else { } else {
//if the menu item has no quantity or less than they want, don't let them buy it. //if the menu item has no quantity or less than they want, don't let them buy it.
error.setText("There are not enough items for that."); error.setText("There are not enough items for that.");
amount = amount + cost;
jLabel3.setText("Amount Given: "+amount); jLabel3.setText("Amount Given: "+amount);
return false; return false;
} }
...@@ -438,9 +438,14 @@ public class temp extends javax.swing.JFrame { ...@@ -438,9 +438,14 @@ public class temp extends javax.swing.JFrame {
} }
public void print(){ public void print(){
cost = 0;
try { try {
FileWriter f = new FileWriter("receipt.txt"); FileWriter f = new FileWriter("receipt.txt");
f.write("SafeVend receipt: \n");
f.write("Thank you for choosing SafeVend!" + "\n");
f.write("________________________________\n");
f.write("Items purchased: \n"); f.write("Items purchased: \n");
f.write("Code\tItem\t\tPrice\tQuantity \t" + "\n"); f.write("Code\tItem\t\tPrice\tQuantity \t" + "\n");
...@@ -458,21 +463,27 @@ public class temp extends javax.swing.JFrame { ...@@ -458,21 +463,27 @@ public class temp extends javax.swing.JFrame {
} }
f.write(""+price[i]+"\t"); f.write(""+price[i]+"\t");
//displays the price //displays the price
f.write(basket[i]+"\t"); f.write((basket[i]/2)+"\t");
//this is because for some reason the basket quanity was being doubled;
cost = cost + ((price[i]) * (basket[i]/2));
//adds a new line to display the next item. //adds a new line to display the next item.
f.write("\n"); f.write("\n");
} }
} }
f.write("________________________________\n");
f.write("\n" + "Total cost: " + cost + "\n"); f.write("\n" + "Total cost: " + cost + "\n");
f.write("\n" + "Total payed: " + payed + "\n"); f.write("\n" + "Total payed: " + payed + "\n");
f.write("\n" + "Change Given: " + Double.parseDouble(moneyInput.getText()) + "\n"); f.write("\n" + "Change Given: " + (payed-cost) + "\n");
if (change >= 0){ if (change >= 0){
f.write("\n" + "valid payment: " + true); f.write("\n" + "valid payment: " + true);
} else { } else {
f.write("\n" + "valid payment: " + false); f.write("\n" + "valid payment: " + false);
f.write("\n" + "Service Denied.");
} }
f.write("\n________________________________");
f.close(); f.close();
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
......
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