Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
VendingMachine_William_France
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
william.france
VendingMachine_William_France
Commits
fcbbbf89
Commit
fcbbbf89
authored
Jan 13, 2020
by
william.france
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First commit
parents
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
495 additions
and
0 deletions
+495
-0
Receipt
Receipt
+2
-0
pom.xml
pom.xml
+14
-0
vendingmachineGui.form
src/main/java/vendingmachinepackage/vendingmachineGui.form
+163
-0
vendingmachineGui.java
src/main/java/vendingmachinepackage/vendingmachineGui.java
+316
-0
No files found.
Receipt
0 → 100644
View file @
fcbbbf89
thank you for your purchase of Chocolate £2.0 1Water £0.5 1Snack £2.0 1
\ No newline at end of file
pom.xml
0 → 100644
View file @
fcbbbf89
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.mycompany
</groupId>
<artifactId>
Vendingmachine
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<packaging>
jar
</packaging>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<maven.compiler.source>
13
</maven.compiler.source>
<maven.compiler.target>
13
</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
src/main/java/vendingmachinepackage/vendingmachineGui.form
0 → 100644
View file @
fcbbbf89
<?xml version="1.0" encoding="UTF-8" ?>
<Form
version=
"1.3"
maxVersion=
"1.9"
type=
"org.netbeans.modules.form.forminfo.JFrameFormInfo"
>
<Properties>
<Property
name=
"defaultCloseOperation"
type=
"int"
value=
"3"
/>
</Properties>
<SyntheticProperties>
<SyntheticProperty
name=
"formSizePolicy"
type=
"int"
value=
"1"
/>
<SyntheticProperty
name=
"generateCenter"
type=
"boolean"
value=
"false"
/>
</SyntheticProperties>
<AuxValues>
<AuxValue
name=
"FormSettings_autoResourcing"
type=
"java.lang.Integer"
value=
"0"
/>
<AuxValue
name=
"FormSettings_autoSetComponentName"
type=
"java.lang.Boolean"
value=
"false"
/>
<AuxValue
name=
"FormSettings_generateFQN"
type=
"java.lang.Boolean"
value=
"true"
/>
<AuxValue
name=
"FormSettings_generateMnemonicsCode"
type=
"java.lang.Boolean"
value=
"false"
/>
<AuxValue
name=
"FormSettings_i18nAutoMode"
type=
"java.lang.Boolean"
value=
"false"
/>
<AuxValue
name=
"FormSettings_layoutCodeTarget"
type=
"java.lang.Integer"
value=
"1"
/>
<AuxValue
name=
"FormSettings_listenerGenerationStyle"
type=
"java.lang.Integer"
value=
"0"
/>
<AuxValue
name=
"FormSettings_variablesLocal"
type=
"java.lang.Boolean"
value=
"false"
/>
<AuxValue
name=
"FormSettings_variablesModifier"
type=
"java.lang.Integer"
value=
"2"
/>
</AuxValues>
<Layout>
<DimensionLayout
dim=
"0"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
alignment=
"1"
attributes=
"0"
>
<EmptySpace
pref=
"24"
max=
"32767"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
alignment=
"1"
attributes=
"0"
>
<Component
id=
"paymentlbl"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"91"
max=
"-2"
attributes=
"0"
/>
</Group>
<Group
type=
"102"
alignment=
"1"
attributes=
"0"
>
<Component
id=
"itemcombox"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
type=
"separate"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"Addbtn"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"80"
max=
"-2"
attributes=
"0"
/>
</Group>
<Group
type=
"102"
alignment=
"1"
attributes=
"0"
>
<Component
id=
"cashtxt"
min=
"-2"
pref=
"164"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"purchasebtn"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"12"
max=
"-2"
attributes=
"0"
/>
</Group>
<Group
type=
"102"
alignment=
"1"
attributes=
"0"
>
<Group
type=
"103"
groupAlignment=
"1"
attributes=
"0"
>
<Component
id=
"jScrollPane2"
min=
"-2"
pref=
"258"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"jScrollPane1"
min=
"-2"
pref=
"258"
max=
"-2"
attributes=
"0"
/>
</Group>
<EmptySpace
min=
"-2"
pref=
"54"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
</Group>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<EmptySpace
min=
"-2"
pref=
"120"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"changelbl"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"0"
pref=
"0"
max=
"32767"
attributes=
"0"
/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout
dim=
"1"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"paymentlbl"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"20"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"1"
attributes=
"0"
>
<Component
id=
"cashtxt"
min=
"-2"
pref=
"26"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"purchasebtn"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
</Group>
<EmptySpace
min=
"-2"
pref=
"28"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"3"
attributes=
"0"
>
<Component
id=
"Addbtn"
alignment=
"3"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"itemcombox"
alignment=
"3"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
</Group>
<EmptySpace
type=
"unrelated"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"jScrollPane1"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"jScrollPane2"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
type=
"unrelated"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"changelbl"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
pref=
"62"
max=
"32767"
attributes=
"0"
/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component
class=
"javax.swing.JButton"
name=
"Addbtn"
>
<Properties>
<Property
name=
"text"
type=
"java.lang.String"
value=
"ADD"
/>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"AddbtnActionPerformed"
/>
</Events>
</Component>
<Component
class=
"javax.swing.JComboBox"
name=
"itemcombox"
>
<Properties>
<Property
name=
"model"
type=
"javax.swing.ComboBoxModel"
editor=
"org.netbeans.modules.form.editors2.ComboBoxModelEditor"
>
<StringArray
count=
"5"
>
<StringItem
index=
"0"
value=
"Chocolate"
/>
<StringItem
index=
"1"
value=
"Water"
/>
<StringItem
index=
"2"
value=
"Drink"
/>
<StringItem
index=
"3"
value=
"Snack"
/>
<StringItem
index=
"4"
value=
"Sweet"
/>
</StringArray>
</Property>
</Properties>
<AuxValues>
<AuxValue
name=
"JavaCodeGenerator_TypeParameters"
type=
"java.lang.String"
value=
"<String>"
/>
</AuxValues>
</Component>
<Component
class=
"javax.swing.JTextField"
name=
"cashtxt"
>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"cashtxtActionPerformed"
/>
</Events>
</Component>
<Component
class=
"java.awt.Label"
name=
"paymentlbl"
>
<Properties>
<Property
name=
"text"
type=
"java.lang.String"
value=
"please enter your cash here"
/>
</Properties>
</Component>
<Container
class=
"javax.swing.JScrollPane"
name=
"jScrollPane1"
>
<AuxValues>
<AuxValue
name=
"autoScrollPane"
type=
"java.lang.Boolean"
value=
"true"
/>
</AuxValues>
<Layout
class=
"org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"
/>
<SubComponents>
<Component
class=
"javax.swing.JTextArea"
name=
"baskettxt"
>
<Properties>
<Property
name=
"columns"
type=
"int"
value=
"20"
/>
<Property
name=
"rows"
type=
"int"
value=
"5"
/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container
class=
"javax.swing.JScrollPane"
name=
"jScrollPane2"
>
<AuxValues>
<AuxValue
name=
"autoScrollPane"
type=
"java.lang.Boolean"
value=
"true"
/>
</AuxValues>
<Layout
class=
"org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"
/>
<SubComponents>
<Component
class=
"javax.swing.JTextArea"
name=
"totalcosttxt"
>
<Properties>
<Property
name=
"columns"
type=
"int"
value=
"20"
/>
<Property
name=
"rows"
type=
"int"
value=
"5"
/>
</Properties>
</Component>
</SubComponents>
</Container>
<Component
class=
"javax.swing.JButton"
name=
"purchasebtn"
>
<Properties>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Purchase"
/>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"purchasebtnActionPerformed"
/>
</Events>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"changelbl"
>
</Component>
</SubComponents>
</Form>
src/main/java/vendingmachinepackage/vendingmachineGui.java
0 → 100644
View file @
fcbbbf89
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
vendingmachinepackage
;
import
java.io.IOException
;
import
java.io.FileWriter
;
import
java.util.ArrayList
;
import
javax.swing.DefaultComboBoxModel
;
/**
*
* @author william.france
*/
public
class
vendingmachineGui
extends
javax
.
swing
.
JFrame
{
// To start we need to create an array to store all the items into the vending machine these willl be called the same as table in the instructions
ArrayList
<
Integer
>
Code
=
new
ArrayList
<
Integer
>();
ArrayList
<
String
>
Product
=
new
ArrayList
<
String
>();
ArrayList
<
Double
>
Price
=
new
ArrayList
<
Double
>();
ArrayList
<
Integer
>
Quantity
=
new
ArrayList
<
Integer
>();
ArrayList
<
Integer
>
Stock
=
new
ArrayList
<
Integer
>();
// the second group of array lists is for the items that have been selected and put into the basket/Bag
ArrayList
<
Integer
>
BCode
=
new
ArrayList
<
Integer
>();
ArrayList
<
String
>
BProduct
=
new
ArrayList
<
String
>();
ArrayList
<
Double
>
BPrice
=
new
ArrayList
<
Double
>();
ArrayList
<
Integer
>
BQuantity
=
new
ArrayList
<
Integer
>();
double
change
,
payment
,
bagcost
;
/**
* Creates new form vendingmachineGui
*/
public
vendingmachineGui
()
{
initComponents
();
// we then need to populate the rrays with the details about our items
Code
.
add
(
0
);
Product
.
add
(
"Chocolate"
);
Price
.
add
(
2.0
);
Quantity
.
add
(
1
);
Stock
.
add
(
20
);
Code
.
add
(
1
);
Product
.
add
(
"Water"
);
Price
.
add
(
0.5
);
Quantity
.
add
(
1
);
Stock
.
add
(
20
);
Code
.
add
(
2
);
Product
.
add
(
"Drink "
);
Price
.
add
(
1.0
);
Quantity
.
add
(
1
);
Stock
.
add
(
20
);
Code
.
add
(
3
);
Product
.
add
(
"Snack"
);
Price
.
add
(
2.0
);
Quantity
.
add
(
1
);
Stock
.
add
(
20
);
Code
.
add
(
4
);
Product
.
add
(
"Sweet"
);
Price
.
add
(
1.0
);
Quantity
.
add
(
1
);
Stock
.
add
(
20
);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings
(
"unchecked"
)
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private
void
initComponents
()
{
Addbtn
=
new
javax
.
swing
.
JButton
();
itemcombox
=
new
javax
.
swing
.
JComboBox
<>();
cashtxt
=
new
javax
.
swing
.
JTextField
();
paymentlbl
=
new
java
.
awt
.
Label
();
jScrollPane1
=
new
javax
.
swing
.
JScrollPane
();
baskettxt
=
new
javax
.
swing
.
JTextArea
();
jScrollPane2
=
new
javax
.
swing
.
JScrollPane
();
totalcosttxt
=
new
javax
.
swing
.
JTextArea
();
purchasebtn
=
new
javax
.
swing
.
JButton
();
changelbl
=
new
javax
.
swing
.
JLabel
();
setDefaultCloseOperation
(
javax
.
swing
.
WindowConstants
.
EXIT_ON_CLOSE
);
Addbtn
.
setText
(
"ADD"
);
Addbtn
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
AddbtnActionPerformed
(
evt
);
}
});
itemcombox
.
setModel
(
new
javax
.
swing
.
DefaultComboBoxModel
<>(
new
String
[]
{
"Chocolate"
,
"Water"
,
"Drink"
,
"Snack"
,
"Sweet"
}));
cashtxt
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
cashtxtActionPerformed
(
evt
);
}
});
paymentlbl
.
setText
(
"please enter your cash here"
);
baskettxt
.
setColumns
(
20
);
baskettxt
.
setRows
(
5
);
jScrollPane1
.
setViewportView
(
baskettxt
);
totalcosttxt
.
setColumns
(
20
);
totalcosttxt
.
setRows
(
5
);
jScrollPane2
.
setViewportView
(
totalcosttxt
);
purchasebtn
.
setText
(
"Purchase"
);
purchasebtn
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
purchasebtnActionPerformed
(
evt
);
}
});
javax
.
swing
.
GroupLayout
layout
=
new
javax
.
swing
.
GroupLayout
(
getContentPane
());
getContentPane
().
setLayout
(
layout
);
layout
.
setHorizontalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
layout
.
createSequentialGroup
()
.
addContainerGap
(
24
,
Short
.
MAX_VALUE
)
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
layout
.
createSequentialGroup
()
.
addComponent
(
paymentlbl
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
91
,
91
,
91
))
.
addGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
layout
.
createSequentialGroup
()
.
addComponent
(
itemcombox
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
Addbtn
)
.
addGap
(
80
,
80
,
80
))
.
addGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
layout
.
createSequentialGroup
()
.
addComponent
(
cashtxt
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
164
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
purchasebtn
)
.
addGap
(
12
,
12
,
12
))
.
addGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
layout
.
createSequentialGroup
()
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
)
.
addComponent
(
jScrollPane2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
258
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
jScrollPane1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
258
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addGap
(
54
,
54
,
54
))))
.
addGroup
(
layout
.
createSequentialGroup
()
.
addGap
(
120
,
120
,
120
)
.
addComponent
(
changelbl
)
.
addGap
(
0
,
0
,
Short
.
MAX_VALUE
))
);
layout
.
setVerticalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addComponent
(
paymentlbl
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
20
,
20
,
20
)
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
)
.
addComponent
(
cashtxt
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
26
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
purchasebtn
))
.
addGap
(
28
,
28
,
28
)
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
Addbtn
)
.
addComponent
(
itemcombox
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
UNRELATED
)
.
addComponent
(
jScrollPane1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
jScrollPane2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
UNRELATED
)
.
addComponent
(
changelbl
)
.
addContainerGap
(
62
,
Short
.
MAX_VALUE
))
);
pack
();
}
// </editor-fold>//GEN-END:initComponents
private
void
AddbtnActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_AddbtnActionPerformed
// TODO add your handling code here:
// we will no use a case system to set up the combobo so when an item is selected it will place the prdut into the basket
// this links the text area to the array and the combobox
switch
(
itemcombox
.
getSelectedIndex
()){
case
0
:
baskettxt
.
append
(
Product
.
get
(
0
)
+
" "
+
"£"
+
Price
.
get
(
0
)
+
" "
+
Quantity
.
get
(
0
));
BProduct
.
add
(
Product
.
get
(
0
));
BPrice
.
add
(
Price
.
get
(
0
));
BQuantity
.
add
(
Quantity
.
get
(
0
));
bagcost
+=
BPrice
.
get
(
0
);
totalcosttxt
.
setText
(
"your Total cost is £"
+
bagcost
);
break
;
case
1
:
baskettxt
.
append
(
Product
.
get
(
1
)
+
" "
+
"£"
+
Price
.
get
(
1
)
+
" "
+
Quantity
.
get
(
1
));
BProduct
.
add
(
Product
.
get
(
1
));
BPrice
.
add
(
Price
.
get
(
1
));
BQuantity
.
add
(
Quantity
.
get
(
1
));
bagcost
+=
BPrice
.
get
(
1
);
totalcosttxt
.
setText
(
"your Total cost is £"
+
bagcost
);
break
;
case
2
:
baskettxt
.
append
(
Product
.
get
(
2
)
+
" "
+
"£"
+
Price
.
get
(
2
)
+
" "
+
Quantity
.
get
(
2
));
BProduct
.
add
(
Product
.
get
(
2
));
BPrice
.
add
(
Price
.
get
(
2
));
BQuantity
.
add
(
Quantity
.
get
(
2
));
bagcost
+=
BPrice
.
get
(
2
);
totalcosttxt
.
setText
(
"your Total cost is £"
+
bagcost
);
break
;
case
3
:
baskettxt
.
append
(
Product
.
get
(
3
)
+
" "
+
"£"
+
Price
.
get
(
3
)
+
" "
+
Quantity
.
get
(
3
));
BProduct
.
add
(
Product
.
get
(
3
));
BPrice
.
add
(
Price
.
get
(
3
));
BQuantity
.
add
(
Quantity
.
get
(
3
));
bagcost
+=
BPrice
.
get
(
3
);
totalcosttxt
.
setText
(
"your Total cost is £"
+
bagcost
);
break
;
case
4
:
baskettxt
.
append
(
Product
.
get
(
4
)
+
" "
+
"£"
+
Price
.
get
(
4
)
+
" "
+
Quantity
.
get
(
4
));
BProduct
.
add
(
Product
.
get
(
4
));
BPrice
.
add
(
Price
.
get
(
4
));
BQuantity
.
add
(
Quantity
.
get
(
4
));
bagcost
+=
BPrice
.
get
(
4
);
totalcosttxt
.
setText
(
"your Total cost is £"
+
bagcost
);
}
}
//GEN-LAST:event_AddbtnActionPerformed
private
void
cashtxtActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_cashtxtActionPerformed
// TODO add your handling code here:
}
//GEN-LAST:event_cashtxtActionPerformed
private
void
purchasebtnActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_purchasebtnActionPerformed
// TODO add your handling code here:
double
value
=
Double
.
parseDouble
(
cashtxt
.
getText
());
change
=
value
-
bagcost
;
if
(
value
>=
bagcost
){
changelbl
.
setText
(
" Thank you for your purchase please take your items and receipt "
);
}
else
{
changelbl
.
setText
(
" insufficent funds please reenter your amount "
);
}
if
(
value
>=
bagcost
){
try
{
FileWriter
mywriter
=
new
FileWriter
(
"Receipt"
);
mywriter
.
write
(
"thank you for your purchase of "
+
baskettxt
.
getText
());
mywriter
.
close
();
}
catch
(
IOException
e0
){
}}
}
//GEN-LAST:event_purchasebtnActionPerformed
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
args
[])
{
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try
{
for
(
javax
.
swing
.
UIManager
.
LookAndFeelInfo
info
:
javax
.
swing
.
UIManager
.
getInstalledLookAndFeels
())
{
if
(
"Nimbus"
.
equals
(
info
.
getName
()))
{
javax
.
swing
.
UIManager
.
setLookAndFeel
(
info
.
getClassName
());
break
;
}
}
}
catch
(
ClassNotFoundException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
vendingmachineGui
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
InstantiationException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
vendingmachineGui
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
IllegalAccessException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
vendingmachineGui
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
javax
.
swing
.
UnsupportedLookAndFeelException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
vendingmachineGui
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
//</editor-fold>
/* Create and display the form */
java
.
awt
.
EventQueue
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
vendingmachineGui
().
setVisible
(
true
);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private
javax
.
swing
.
JButton
Addbtn
;
private
javax
.
swing
.
JTextArea
baskettxt
;
private
javax
.
swing
.
JTextField
cashtxt
;
private
javax
.
swing
.
JLabel
changelbl
;
private
javax
.
swing
.
JComboBox
<
String
>
itemcombox
;
private
javax
.
swing
.
JScrollPane
jScrollPane1
;
private
javax
.
swing
.
JScrollPane
jScrollPane2
;
private
java
.
awt
.
Label
paymentlbl
;
private
javax
.
swing
.
JButton
purchasebtn
;
private
javax
.
swing
.
JTextArea
totalcosttxt
;
// End of variables declaration//GEN-END:variables
}
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