Commit 47bce10d authored by karl.templeton's avatar karl.templeton

Delete SelfService

parent 94d1557b
import java.awt.Color;
import java.lang.reflect.Array;
import java.util.Random;
import javax.swing.DefaultListModel;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
public class ShoppingSystem1 extends javax.swing.JFrame {
public ShoppingSystem1() {
initComponents();
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jFrame1 = new javax.swing.JFrame();
jPanel1 = new javax.swing.JPanel();
list1 = new java.awt.List();
jLabel1 = new javax.swing.JLabel();
jButton11 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jButton12 = new javax.swing.JButton();
jLabel11 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox<>();
jButton1 = new javax.swing.JButton();
jTextField3 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jLabel2 = new javax.swing.JLabel();
jComboBox2 = new javax.swing.JComboBox<>();
jTextField2 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
jTextField5 = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(null);
list1.setName(""); // NOI18N
list1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
list1ActionPerformed(evt);
}
});
getContentPane().add(list1);
list1.setBounds(550, 90, 153, 302);
jLabel1.setFont(new java.awt.Font("Verdana Pro Light", 1, 18)); // NOI18N
jLabel1.setText("ShoppingSystem");
getContentPane().add(jLabel1);
jLabel1.setBounds(305, 6, 160, 65);
jButton11.setText("Discount");
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton11ActionPerformed(evt);
}
});
getContentPane().add(jButton11);
jButton11.setBounds(550, 550, 90, 22);
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
getContentPane().add(jTextField1);
jTextField1.setBounds(670, 580, 110, 22);
jButton12.setText("Total");
jButton12.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton12ActionPerformed(evt);
}
});
getContentPane().add(jButton12);
jButton12.setBounds(670, 550, 110, 22);
getContentPane().add(jLabel11);
jLabel11.setBounds(600, 400, 0, 0);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Please Select An Item", "Pen", "Book", "Water", "Drink", "Snack", "Sweet", "Chocolate", "Biscuit", "Cake", "" }));
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1ActionPerformed(evt);
}
});
getContentPane().add(jComboBox1);
jComboBox1.setBounds(190, 100, 170, 22);
jButton1.setText("Remove All");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(190, 190, 170, 22);
jTextField3.setEditable(false);
jTextField3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField3ActionPerformed(evt);
}
});
getContentPane().add(jTextField3);
jTextField3.setBounds(190, 80, 170, 22);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{"Code", "01", "02", "03", "04", "05", "06", "07", "08", "9"},
{"Price", "£1.00", "£1.00", "£1.00", "£1.00", "£2.00", "£1.00", "£1.00", "£1.00", "£2.00"},
{"Quantity", "20", "20", "20", "20", "20", "20", "20", "20", "20"},
{null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null}
},
new String [] {
"Title 1", "Pen", "Book", "Water", "Drink", "Snack", "Sweet", "Chocolate", "Biscuit", "Cake"
}
) {
boolean[] canEdit = new boolean [] {
false, false, false, false, false, false, false, false, false, false
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane1.setViewportView(jTable1);
getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(0, 520, 530, 130);
getContentPane().add(jLabel2);
jLabel2.setBounds(550, 400, 150, 0);
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Remove Certain Items", "Pen", "Book", "Water", "Drink", "Snack", "Sweet", "Chocolate", "Biscuit", "Cake", "" }));
jComboBox2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox2ActionPerformed(evt);
}
});
getContentPane().add(jComboBox2);
jComboBox2.setBounds(189, 150, 170, 22);
jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});
getContentPane().add(jTextField2);
jTextField2.setBounds(550, 580, 90, 22);
jTextField4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField4ActionPerformed(evt);
}
});
getContentPane().add(jTextField4);
jTextField4.setBounds(550, 520, 90, 20);
jLabel3.setText("Pay Here");
getContentPane().add(jLabel3);
jLabel3.setBounds(570, 500, 60, 20);
jLabel5.setBackground(new java.awt.Color(255, 51, 51));
jLabel5.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
jLabel5.setForeground(new java.awt.Color(255, 51, 51));
jLabel5.setText("Insufficient Amount");
jLabel5.setEnabled(false);
getContentPane().add(jLabel5);
jLabel5.setBounds(550, 400, 150, 20);
jLabel6.setBackground(new java.awt.Color(51, 255, 51));
jLabel6.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
jLabel6.setForeground(new java.awt.Color(102, 255, 51));
jLabel6.setText("Please Take Your Products");
jLabel6.setEnabled(false);
getContentPane().add(jLabel6);
jLabel6.setBounds(550, 420, 170, 20);
jButton2.setText("Accept");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
getContentPane().add(jButton2);
jButton2.setBounds(640, 520, 90, 20);
jLabel4.setText("Change =");
getContentPane().add(jLabel4);
jLabel4.setBounds(610, 620, 60, 16);
jTextField5.setEditable(false);
jTextField5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField5ActionPerformed(evt);
}
});
getContentPane().add(jTextField5);
jTextField5.setBounds(670, 620, 110, 22);
pack();
}// </editor-fold>
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {
//This bit of Code creates a new Random called random
Random random = new Random();
// This Generates A Random Number from 1-10 which is then ran through a if Statement which have different conditions
// including randInt1 == 1 , randInt2 == 2
// Each condition has a different output EG JTextField1.setText("10%") and JTextField1.setText("20%")
int randInt1 = random.nextInt(10);
int Discount = 0;
if(randInt1 == 1)
{
jTextField2.setText("10%");
Discount = 10;
}
if(randInt1 == 2)
{
jTextField2.setText("20%");
Discount = 20;
}
if(randInt1 == 3)
{
jTextField2.setText("30%");
Discount = 30;
}
if(randInt1 == 4)
{
jTextField2.setText("40%");
Discount = 40;
}
if(randInt1 == 5)
{
jTextField2.setText("50%");
Discount = 50;
}
if(randInt1 > 5)
{
jTextField2.setText("£5 Off");
Discount = 500;
}
jButton11.setEnabled(false);
}
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
//Default Amount
int Amount = 0;
//This if Statement will check if the ComboBox has the Item selected "Pen" so that the Condition is run
if(jComboBox1.getSelectedItem().toString().equals("Pen")){
//Display Item Description
jTextField3.setText("A Good and Sturdy Pen");
//Adding the Price to The Total
int penPrice = 1;
int TotalAmount = Amount + penPrice;
String s = String.valueOf(penPrice);
jTextField1.setText(s);
//Displaying items in the list1
list1.add("Pen");
}
if(jComboBox1.getSelectedItem().toString().equals("Book")){
//Display Item Description
jTextField3.setText("Your Favourite Book");
//Adding the Price to the Total
int bookPrice = 1;
//Item Ticker
//Displaying items in the list1
list1.add("Book");
}
if(jComboBox1.getSelectedItem().toString().equals("Water")){
//Display Item Description
jTextField3.setText("A Bottle Of Water");
//Adding the Price to the Total
int waterPrice = 1;
//Item Ticker
//Displaying items in the list1
list1.add("Water");
}
if (jComboBox1.getSelectedItem().toString().equals("Drink")){
//Display Item Description
jTextField3.setText("A Drink");
//Adding the Price to the Total
int drinkPrice = 1;
//Item Ticker
//Displaying items in the list1
list1.add("Drink");
}
if (jComboBox1.getSelectedItem().toString().equals("Snack")){
//Display Item Description
jTextField3.setText("Your Favourite Snack");
//Adding the Price to the Total
int snackPrice = 2;
//Item Ticker
//Displaying items in the list1
list1.add("Snack");
}
if (jComboBox1.getSelectedItem().toString().equals("Sweet")){
//Display Item Description
jTextField3.setText("Your Favourite Sweets");
//Adding the Price to the Total
int sweetPrice = 1;
//Item Ticker
//Displaying items in the list1
list1.add("Sweet");
}
if (jComboBox1.getSelectedItem().toString().equals("Chocolate")){
//Display Item Description
jTextField3.setText("A Bar Of Chocolate");
//Adding the Price to the Total
int chcolatePrice = 1;
//Item Ticker
//Displaying items in the list1
list1.add("Chocolate");
}
if (jComboBox1.getSelectedItem().toString().equals("Biscuit")){
//Display Item Description
jTextField3.setText("A Packet Of Biscuits");
//Items in Basket
int biscuitPrice = 1;
//Item Ticker
//Displaying items in the list1
list1.add("Biscuit");
}
if (jComboBox1.getSelectedItem().toString().equals("Cake")){
//Display Item Description
jTextField3.setText("A Slice Of Cake");
//Items in Basket
int cakePrice = 2;
//Item Ticker
//Displaying items in the list1
list1.add("Cake");
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// An Option available to remove everything in the list by selecting the Button
// "Remove All"
list1.removeAll();
}
private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {
//This If Statement will Check whether a particular Item selected is within the Basket
//If so then it will Remove the Certain Item Selected by Pressing the Button
if (jComboBox1.getSelectedItem().toString().equals("Pen")){
list1.remove("Pen");
}
if (jComboBox1.getSelectedItem().toString().equals("Water")){
list1.remove("Water");
}
if (jComboBox1.getSelectedItem().toString().equals("Book")){
list1.remove("Book");
}
if (jComboBox1.getSelectedItem().toString().equals("Drink")){
list1.remove("Drink");
}
if (jComboBox1.getSelectedItem().toString().equals("Snack")){
list1.remove("Snack");
}
if (jComboBox1.getSelectedItem().toString().equals("Sweet")){
list1.remove("Sweet");
}
if (jComboBox1.getSelectedItem().toString().equals("Chocolate")){
list1.remove("Chocolate");
}
if (jComboBox1.getSelectedItem().toString().equals("Biscuit")){
list1.remove("Biscuit");
}
if (jComboBox1.getSelectedItem().toString().equals("Cake")){
list1.remove("Cake");
}
}
private void list1ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
//This Code will First find whats in jTextField1 and JTextField4 and
//call them both TotalAmount and Payment they are then used in a if
//Statement if the Payment is more or equal to TotalAmount then it
//will set a label visability true so that it can be seen if not
//then it will enabled a different label
double Discount;
int TotalAmount =Integer.parseInt(jTextField1.getText());
int Payment =Integer.parseInt(jTextField4.getText());
if (Payment >= TotalAmount)
{
jLabel6.setEnabled(true);
}
else
{
jLabel5.setEnabled(true);
}
}
private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {
//This will display if there is any change left from the customer
int Total =Integer.parseInt(jTextField1.getText());
int Amount =Integer.parseInt(jTextField4.getText());
int Change = Total - Amount;
String str = String.valueOf(Change);
jTextField5.setText(str);
}
//This Section of Code is Designed for the purpose to print a reciept
//for the customer, outlining what they have bought from the store
public void File(String[] args) throws FileNotFoundException, IOException {
//Create A File
FileWriter myWriter = new FileWriter("reciept.txt");
//Write text into the Created File
myWriter.write("Thank You For Shopping with us the The Price for Your Shopping was" + jTextField1.getText());
}
//Class name Item which has a constuctor for all of the Array names including
//name = n and code = c
class Item{
//Constructors
Item(String n, int c, double p, int q, String d){
name = n;
code = c;
price = p;
qty = q;
description = d;
}
String name;
int code;
double price;
int qty;
String description;
}
public static void main(String args[]) {
//An Array List for Everything to do with the Items
//Using a Scanner so that the Array can be used
Scanner sc = new Scanner(System.in);
ArrayList<String> itemName = new ArrayList<String>(); // name
ArrayList<Integer> itemCode = new ArrayList<Integer>(); // code
ArrayList<Float> itemPrice = new ArrayList<Float>(); // price
ArrayList<Integer> itemQty = new ArrayList<Integer>(); // Quantity
ArrayList<String> itemDescription = new ArrayList<String>(); // Description
//Every Item that needs to be added will be placed under this comment
//Including the name, code, price, quantity and the Description of the Item
itemName.add("Pen");
itemCode.add(00);
itemPrice.add((float) 1.00);
itemQty.add(20);
itemDescription.add("A nice Pen");
itemName.add("Book");
itemCode.add(01);
itemPrice.add((float) 1.00);
itemQty.add(20);
itemDescription.add("A nice Book");
itemName.add("Water");
itemCode.add(02);
itemPrice.add((float) 1.00);
itemQty.add(20);
itemDescription.add("Good Water");
itemName.add("Drink");
itemCode.add(03);
itemPrice.add((float) 1.00);
itemQty.add(20);
itemDescription.add("A good Drink");
itemName.add("Snack");
itemCode.add(04);
itemPrice.add((float) 2.00);
itemQty.add(20);
itemDescription.add("A nice Snack");
itemName.add("Sweet");
itemCode.add(05);
itemPrice.add((float) 1.00);
itemQty.add(20);
itemDescription.add("A nice Sweet");
itemName.add("Chocolate");
itemCode.add(06);
itemPrice.add((float) 1.00);
itemQty.add(20);
itemDescription.add("A bar of Chocolate");
itemName.add("Biscuit");
itemCode.add(07);
itemPrice.add((float) 1.00);
itemQty.add(20);
itemDescription.add("A packet of Biscuits");
itemName.add("Cake");
itemCode.add(8);
itemPrice.add((float) 2.00);
itemQty.add(20);
itemDescription.add("A slice of Cake");
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ShoppingSystem1().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton12;
private javax.swing.JButton jButton2;
private javax.swing.JComboBox<String> jComboBox1;
private javax.swing.JComboBox<String> jComboBox2;
private javax.swing.JFrame jFrame1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private java.awt.List list1;
// End of variables declaration
}
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