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

created file writing system; need to fix variables;

parent 00cb73ea
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* and open the template in the editor. * and open the template in the editor.
*/ */
import java.io.*; import java.io.*;
import java.util.Scanner;
/** /**
* *
* @author rober * @author rober
...@@ -278,7 +278,7 @@ public class temp extends javax.swing.JFrame { ...@@ -278,7 +278,7 @@ public class temp extends javax.swing.JFrame {
ID = "02"; ID = "02";
break; break;
case "Drink": case "Drink":
Price = 1"; Price = 2";
ID = "03"; ID = "03";
break; break;
case "Snack": case "Snack":
...@@ -329,7 +329,7 @@ public class temp extends javax.swing.JFrame { ...@@ -329,7 +329,7 @@ public class temp extends javax.swing.JFrame {
error.setText("Error: Payment not valid"); error.setText("Error: Payment not valid");
} else if(amount >= cost) { } else if(amount >= cost) {
error.setText("Payment valid"); error.setText("Payment valid");
change = change + (amount - cost); change += amount - cost;
moneyInput.setText(String.valueOf(amount - cost)); moneyInput.setText(String.valueOf(amount - cost));
purchase(); purchase();
} }
...@@ -416,38 +416,58 @@ public class temp extends javax.swing.JFrame { ...@@ -416,38 +416,58 @@ public class temp extends javax.swing.JFrame {
} }
public void print(){ public void print(){
File f = new File("receipt.txt"); try {
//creates a file FileWriter f = new FileWriter("receipt.txt");
f.setWritable(rootPaneCheckingEnabled);
//makes sure the file can be written to f.write("Items purchased: \n");
f.write("Code\tItem\t\tPrice\tQuantity \n");
f.createNewFile(); String line = "";
//f. ("Code\tItem\t\tPrice\tQuantity \t");
//displays the menu the the user
//displays the menu the the user for(int i=0; i < price.length; i++) {
for(int i=0; i < price.length; i++) { if(basket[i]!=0) {
if(basket[i]!=0) {
f.write(itemCode[i]+"\t"); line = (itemCode[i]+"\t");
f.write(line);
//displays the item code //displays the item code
if (i==0||i==1||i==3) { if (i==0||i==1||i==3) {
//this adds a second tab for shorter items which would otherwise display incorrectly //this adds a second tab for shorter items which would otherwise display incorrectly
writer.write(itemName[i]+"\t\t"); line = (itemName[i]+"\t");
f.write(line);
} else { } else {
//if the item name is not short, it only gets one tab //if the item name is not short, it only gets one tab
writer.write(itemName[i]+"\t"); line = (itemName[i]+"\t");
f.write(line);
} }
writer.write(""+price[i]+"\t"); line = (""+price[i]+"\t");
f.write(line);
//displays the price //displays the price
if(basket[i]!=0) { if(basket[i]!=0) {
writer.write(basket[i]+"\t"); line = (basket[i]+"\t");
f.write(line);
} else { } else {
writer.write("Not in Stock"); f.write("Not in Stock");
} }
//adds a new line to display the next item. //adds a new line to display the next item.
writer.write("\n"); line = ("\n");
} f.write(line);
}
f.write("Total cost: " + cost + "\n");
f.write("Total payed: " + amount + "\n");
f.write("Change Given: " + change + "\n");
f.close();
}
} catch(Exception e) {
e.printStackTrace();
//catches execptions, the program wouldn't let me run it until i wrote this.
} }
//creates a file
//streams to the file.
} }
// Variables declaration - do not modify // Variables declaration - do not modify
......
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