Commit 3c64f6cb authored by ethan's avatar ethan

--no commit message

--no commit message
parents
<?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>selfCheckoutSystem</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
<?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">
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="324" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="24" max="-2" attributes="0"/>
<Component id="totalLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="payScreen" min="-2" pref="168" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" groupAlignment="1" max="-2" attributes="0">
<Component id="addBtn" alignment="0" max="32767" attributes="0"/>
<Component id="checkoutBtn" alignment="0" max="32767" attributes="0"/>
<Component id="removeBtn" alignment="0" max="32767" attributes="0"/>
<Component id="discountBtn" alignment="0" max="32767" attributes="0"/>
<Component id="productList" pref="146" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<EmptySpace min="12" pref="12" max="-2" attributes="0"/>
<Component id="transactionLabel" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace pref="18" 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"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Group type="102" attributes="0">
<Component id="productList" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="transactionLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="56" max="-2" attributes="0"/>
<Component id="addBtn" min="-2" pref="41" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="removeBtn" min="-2" pref="41" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="discountBtn" min="-2" pref="41" max="-2" attributes="0"/>
</Group>
<Component id="jScrollPane1" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="totalLabel" min="-2" max="-2" attributes="0"/>
<Component id="checkoutBtn" max="32767" attributes="0"/>
<Component id="payScreen" pref="42" max="32767" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="discountBtn">
<Properties>
<Property name="text" type="java.lang.String" value="Add discount"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="discountBtnActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="addBtn">
<Properties>
<Property name="text" type="java.lang.String" value="Add item"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addBtnActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="removeBtn">
<Properties>
<Property name="text" type="java.lang.String" value="Remove item"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removeBtnActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JComboBox" name="productList">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Choose items"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="productListActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="totalLabel">
<Properties>
<Property name="text" type="java.lang.String" value="Total: "/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="checkoutBtn">
<Properties>
<Property name="text" type="java.lang.String" value="Checkout"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="checkoutBtnActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="transactionLabel">
<Properties>
<Property name="text" type="java.lang.String" value="jLabel1"/>
</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="screen">
<Properties>
<Property name="columns" type="int" value="20"/>
<Property name="rows" type="int" value="5"/>
<Property name="text" type="java.lang.String" value="Code Product Price (&#xa3;) Quantity&#xa; 01 Pen 1 20&#xa; 02 Book 1 20&#xa; 03 Water 1 20&#xa; 04 Drink 2 20&#xa; 05 Snack 1 20&#xa; 06 Sweet 1 20&#xa; 07 Chocolate 1 20&#xa; 08 Biscuits 1 20&#xa; 09 Cake 1 20&#xa;"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JTextField" name="payScreen">
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="payScreenActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>
/*
* 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.
*/
/**
*
* @author ethan
*/
import java.io.FileWriter;
import java.util.ArrayList;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class selfCheckoutSystem extends javax.swing.JFrame {
//Arrays used to hold the menu items name, code, price, and quantity
static ArrayList<String> itemName = new ArrayList<String>();//Name
static ArrayList<Integer> itemCode = new ArrayList<Integer>();//Code
static ArrayList<Float> itemPrice = new ArrayList<Float>();//Price
static ArrayList<Integer> itemQty = new ArrayList<Integer>();//Quantity
//Arrays used to hold the menu items name, code, price, and quantity
static ArrayList<String> basketName = new ArrayList<String>();//Name
static ArrayList<Integer> basketCode = new ArrayList<Integer>();//Code
static ArrayList<Float> basketPrice = new ArrayList<Float>();//Price
static ArrayList<Integer> basketQty = new ArrayList<Integer>();//Quantity
int uses, max = 10, min = 1, discount, count1,
count2, multiplier, tempQty, tempCode, input;
String product;
float total;
/**
* Creates new form selfCheckoutSystem
*/
public selfCheckoutSystem() {
initComponents();
// Adds items to combo box and sets other values such as code, price, and quantity for the items
itemName.add("Pen");
itemCode.add(1);
itemPrice.add((float) 1.00);
itemQty.add(20);
itemName.add("Book");
itemCode.add(2);
itemPrice.add((float) 1.00);
itemQty.add(20);
itemName.add("Water");
itemCode.add(3);
itemPrice.add((float) 1.00);
itemQty.add(20);
itemName.add("Drink");
itemCode.add(4);
itemPrice.add((float) 1.00);
itemQty.add(20);
itemName.add("Snack");
itemCode.add(5);
itemPrice.add((float) 2.00);
itemQty.add(20);
itemName.add("Sweet");
itemCode.add(6);
itemPrice.add((float) 1.00);
itemQty.add(20);
itemName.add("Chocolate");
itemCode.add(7);
itemPrice.add((float) 1.00);
itemQty.add(20);
itemName.add("Biscuits");
itemCode.add(8);
itemPrice.add((float) 1.00);
itemQty.add(20);
itemName.add("Cake");
itemCode.add(9);
itemPrice.add((float) 1.00);
itemQty.add(20);
// Writes products to the drop down menu
for( int i=0; i< itemName.size(); i++ ) {
productList.addItem(itemName.get(i));
}
// Sets transaction label to blank temporarily
transactionLabel.setText("");
// Sets pay screen
payScreen.setText("Enter payment here");
}
/**
* 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() {
discountBtn = new javax.swing.JButton();
addBtn = new javax.swing.JButton();
removeBtn = new javax.swing.JButton();
productList = new javax.swing.JComboBox<>();
totalLabel = new javax.swing.JLabel();
checkoutBtn = new javax.swing.JButton();
transactionLabel = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
screen = new javax.swing.JTextArea();
payScreen = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
discountBtn.setText("Add discount");
discountBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
discountBtnActionPerformed(evt);
}
});
addBtn.setText("Add item");
addBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addBtnActionPerformed(evt);
}
});
removeBtn.setText("Remove item");
removeBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removeBtnActionPerformed(evt);
}
});
productList.setToolTipText("Choose items");
productList.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
productListActionPerformed(evt);
}
});
totalLabel.setText("Total: ");
checkoutBtn.setText("Checkout");
checkoutBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
checkoutBtnActionPerformed(evt);
}
});
transactionLabel.setText("jLabel1");
screen.setColumns(20);
screen.setRows(5);
screen.setText("Code Product Price (£) Quantity\n 01 Pen 1 20\n 02 Book 1 20\n 03 Water 1 20\n 04 Drink 2 20\n 05 Snack 1 20\n 06 Sweet 1 20\n 07 Chocolate 1 20\n 08 Biscuits 1 20\n 09 Cake 1 20\n");
jScrollPane1.setViewportView(screen);
payScreen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
payScreenActionPerformed(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()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(totalLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(payScreen, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(addBtn, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(checkoutBtn, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(removeBtn, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(discountBtn, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(productList, 0, 146, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(transactionLabel)))
.addContainerGap(18, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(productList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(transactionLabel)
.addGap(56, 56, 56)
.addComponent(addBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(removeBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(discountBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jScrollPane1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(totalLabel)
.addComponent(checkoutBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(payScreen, javax.swing.GroupLayout.DEFAULT_SIZE, 42, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void discountBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_discountBtnActionPerformed
// Checks if user is heading to checkout - if so they may add discount
if(count2 >= 1){
// Tells user to pay to continue
transactionLabel.setText("Enter amount to pay");
// Counts number of times user asks for discount
uses = uses + 1;
// Adds discount to the total before final payment - discount may only be added once
if(uses == 1){
discount = (int)(Math.random() * ((max - min) + 1)) + min;// Generates random number from 1 - 10
if(discount >= 6){
if(total < 5){ // If total < £5 discount, total = 0
total = 0;
}
else{
total = total - 5; // Otherwise subtract the £5 discount
}
}
else{ // If random number is 1 - 5 then generate discount accordingly
if (discount == 1){
total = total - (total/10); // 10% discount
}
else if(discount == 2){
total = total - ((total/10)*2); // 20% discount
}
else if(discount == 3){
total = total - ((total/10)*3); // 30% discount
}
else if(discount == 4){
total = total - ((total/10)*4); // 40% discount
}
else if(discount == 5){
total = total - ((total/10)*5); // 50% discount
}
}// Couldnt get switch case to work with this but it would have been better
}
}
// If user has not headed to checkout then they cant add discount
else{
transactionLabel.setText("Head to checkout");
}
}//GEN-LAST:event_discountBtnActionPerformed
private void addBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addBtnActionPerformed
// Resets the screen when the user adds an item (shows basket)
count1 = count1 + 1;
if(count1 == 1){
screen.setText("Your basket: \n");
}
// Every item added we will increase the quantity by 1
tempQty = tempQty + 1;
// Append item to screen
if (tempQty <= 1){
screen.append("\n" + tempQty + "x " + product);
}
// If multiple products are added then increase the multiplier
else if (tempQty > 1){
screen.setText(screen.getText().replace("\n" + (tempQty - 1) + "x " + product,"\n" + tempQty + "x " + product));
}
// Adds items to basket
basketCode.add(tempCode + 1);
basketName.add(itemName.get(tempCode));
basketQty.add(tempQty);
basketPrice.add(tempQty * itemPrice.get(tempCode));
for(int i=0; i<basketName.size(); i++){
for(int j=i+1; j<basketName.size(); j++){
if(j!=i && basketName.get(j).equals(basketName.get(i))){
basketCode.remove(basketCode.get(i));
basketName.remove(basketName.get(i));
basketQty.remove(basketQty.get(i));
basketPrice.remove(basketPrice.get(i));
}
}
}
//screen.append("\nCODE add: " + basketCode);
//screen.append("\nNAME add: " + basketName);
//screen.append("\nQTY add: " + basketQty);
//screen.append("\nPRICE add: " + basketPrice);
}//GEN-LAST:event_addBtnActionPerformed
private void removeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeBtnActionPerformed
// Removes 1 from quantity
tempQty = tempQty - 1;
// Remove 1 from the quantity
if (tempQty >= 1){
screen.setText(screen.getText().replace("\n" + (tempQty + 1) + "x " + product,"\n" + tempQty + "x " + product));
}
// If 1 item is left on screen then remove it
else if (tempQty < 1){
screen.setText(screen.getText().replace("\n" + (tempQty + 1) + "x " + product, ""));
tempQty = 0; // Makes sure user cant add negative items
}
// Removes items from basket
for(int i=0; i<basketName.size(); i++){
for(int j=i+1; j<basketName.size(); j++){
if(j!=i && basketName.get(j).equals(basketName.get(i))){
basketCode.remove(basketCode.get(i));
basketName.remove(basketName.get(i));
basketQty.remove(basketQty.get(i));
basketPrice.remove(basketPrice.get(i));
}
}
}
}//GEN-LAST:event_removeBtnActionPerformed
private void productListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_productListActionPerformed
// Reset tempQty
tempQty = 0;
// Get selectd item
product = productList.getSelectedItem().toString();
// Get item code
tempCode = itemName.indexOf(product);
}//GEN-LAST:event_productListActionPerformed
private void checkoutBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkoutBtnActionPerformed
count2 = count2 + 1;
if (count2 <= 1){
// Find the total amount ot pay
for(int i = 0; i < basketPrice.size(); i++){
total = total + basketPrice.get(i);
}
// Set pay screen to blacnk for user input
payScreen.setText("");
// Display total to the user
totalLabel.setText("Total: £" + total);
}
else if (count2 == 2){
// Takes user input as string and converts it to float
input = Integer.parseInt(payScreen.getText());
// Final payment
if(input >= total){
transactionLabel.setText("Please take your items");
}
else if(input < total){
transactionLabel.setText("Insufficient amount");
}
//else if(basketQty.get(tempCode) > itemQty.get(tempCode)){
// transactionLabel.setText("Sold out");
//}
checkoutBtn.setText("Continue");
screen.setText("Please take your receipt");
}
else{
// Resets screen
PrintWriter writer = null;
try {
writer = new PrintWriter("receipt.txt", "UTF-8");
writer.println("");
writer.close();
// Writes receipt to file
for(int i=0; i<basketName.size(); i++){
writer.append("\n");
writer.append(basketCode.get(i).toString() + " ");
writer.append(basketName.get(i) + " ");
writer.append(basketPrice.get(i).toString() + " ");
writer.append("x" + basketQty.get(i).toString());
}
writer.append("------------------------------\n------------------------------");
writer.append("\nTotal: " + total);
writer.append("\nDiscount: " + discount);
} catch (FileNotFoundException ex) {
Logger.getLogger(selfCheckoutSystem.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(selfCheckoutSystem.class.getName()).log(Level.SEVERE, null, ex);
} finally {
writer.close();
}
// Removes items from basket
for(int i=0; i<basketName.size(); i++){
for(int j=i+1; j<basketName.size(); j++){
if(j!=i && basketName.get(j).equals(basketName.get(i))){
basketCode.set(i, null);
basketName.set(i, null);
basketQty.set(i, null);
basketPrice.set(i, null);
}
}
}
// Resets check button and screen
checkoutBtn.setText("Checkout");
screen.setText("");
totalLabel.setText("Total: ");
payScreen.setText("Enter payment here");
}
}//GEN-LAST:event_checkoutBtnActionPerformed
private void payScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_payScreenActionPerformed
}//GEN-LAST:event_payScreenActionPerformed
/**
* @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(selfCheckoutSystem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(selfCheckoutSystem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(selfCheckoutSystem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(selfCheckoutSystem.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 selfCheckoutSystem().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addBtn;
private javax.swing.JButton checkoutBtn;
private javax.swing.JButton discountBtn;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField payScreen;
private javax.swing.JComboBox<String> productList;
private javax.swing.JButton removeBtn;
private javax.swing.JTextArea screen;
private javax.swing.JLabel totalLabel;
private javax.swing.JLabel transactionLabel;
// End of variables declaration//GEN-END:variables
}
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