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

created file writing system; need to fix variables;

parent 00cb73ea
......@@ -4,7 +4,7 @@
* and open the template in the editor.
*/
import java.io.*;
import java.util.Scanner;
/**
*
* @author rober
......@@ -278,7 +278,7 @@ public class temp extends javax.swing.JFrame {
ID = "02";
break;
case "Drink":
Price = 1";
Price = 2";
ID = "03";
break;
case "Snack":
......@@ -329,7 +329,7 @@ public class temp extends javax.swing.JFrame {
error.setText("Error: Payment not valid");
} else if(amount >= cost) {
error.setText("Payment valid");
change = change + (amount - cost);
change += amount - cost;
moneyInput.setText(String.valueOf(amount - cost));
purchase();
}
......@@ -416,38 +416,58 @@ public class temp extends javax.swing.JFrame {
}
public void print(){
File f = new File("receipt.txt");
//creates a file
f.setWritable(rootPaneCheckingEnabled);
//makes sure the file can be written to
try {
FileWriter f = new FileWriter("receipt.txt");
f.createNewFile();
//f. ("Code\tItem\t\tPrice\tQuantity \t");
f.write("Items purchased: \n");
f.write("Code\tItem\t\tPrice\tQuantity \n");
String line = "";
//displays the menu the the user
for(int i=0; i < price.length; i++) {
if(basket[i]!=0) {
f.write(itemCode[i]+"\t");
line = (itemCode[i]+"\t");
f.write(line);
//displays the item code
if (i==0||i==1||i==3) {
//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 {
//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
if(basket[i]!=0) {
writer.write(basket[i]+"\t");
line = (basket[i]+"\t");
f.write(line);
} else {
writer.write("Not in Stock");
f.write("Not in Stock");
}
//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
......
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