Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
VendingMachine_Robert_Sharp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
robert.sharp
VendingMachine_Robert_Sharp
Commits
b1d3b27a
Commit
b1d3b27a
authored
Jan 07, 2020
by
robert.sharp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created file writing system; need to fix variables;
parent
00cb73ea
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
22 deletions
+42
-22
temp.java
src/main/java/temp.java
+42
-22
No files found.
src/main/java/temp.java
View file @
b1d3b27a
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment