Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
COM4001M_Karl_Templeton
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
karl.templeton
COM4001M_Karl_Templeton
Commits
c76037e8
Commit
c76037e8
authored
Jan 13, 2021
by
karl.templeton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Self Service Code
parent
47bce10d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
632 additions
and
0 deletions
+632
-0
SelfService
SelfService
+632
-0
No files found.
SelfService
0 → 100644
View file @
c76037e8
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();
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();
jTextField6 = new javax.swing.JTextField();
jTextField7 = new javax.swing.JTextField();
jTextField8 = new javax.swing.JTextField();
jTextField9 = new javax.swing.JTextField();
jTextField10 = new javax.swing.JTextField();
jTextField11 = new javax.swing.JTextField();
jTextField12 = new javax.swing.JTextField();
jTextField13 = new javax.swing.JTextField();
jTextField14 = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jLabel14 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
jLabel16 = new javax.swing.JLabel();
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.setText("0.00");
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);
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);
jTextField6.setText("20");
getContentPane().add(jTextField6);
jTextField6.setBounds(20, 620, 50, 22);
jTextField7.setText("20");
getContentPane().add(jTextField7);
jTextField7.setBounds(170, 620, 50, 22);
jTextField8.setText("20");
getContentPane().add(jTextField8);
jTextField8.setBounds(220, 620, 50, 22);
jTextField9.setText("20");
getContentPane().add(jTextField9);
jTextField9.setBounds(70, 620, 50, 22);
jTextField10.setText("20");
getContentPane().add(jTextField10);
jTextField10.setBounds(120, 620, 50, 22);
jTextField11.setText("20");
getContentPane().add(jTextField11);
jTextField11.setBounds(420, 620, 50, 22);
jTextField12.setText("20");
jTextField12.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField12ActionPerformed(evt);
}
});
getContentPane().add(jTextField12);
jTextField12.setBounds(320, 620, 50, 22);
jTextField13.setText("20");
getContentPane().add(jTextField13);
jTextField13.setBounds(270, 620, 50, 22);
jTextField14.setText("20");
getContentPane().add(jTextField14);
jTextField14.setBounds(370, 620, 50, 22);
jLabel7.setText("Cake");
getContentPane().add(jLabel7);
jLabel7.setBounds(430, 600, 37, 16);
jLabel8.setText("Pen");
getContentPane().add(jLabel8);
jLabel8.setBounds(20, 600, 20, 16);
jLabel9.setText("Water");
getContentPane().add(jLabel9);
jLabel9.setBounds(120, 600, 31, 16);
jLabel10.setText("Drink");
getContentPane().add(jLabel10);
jLabel10.setBounds(170, 600, 28, 16);
jLabel12.setText("Snack");
getContentPane().add(jLabel12);
jLabel12.setBounds(220, 600, 31, 16);
jLabel13.setText("Sweet");
getContentPane().add(jLabel13);
jLabel13.setBounds(270, 600, 31, 16);
jLabel14.setText("Chocolate");
getContentPane().add(jLabel14);
jLabel14.setBounds(320, 600, 40, 16);
jLabel15.setText("Biscuit");
getContentPane().add(jLabel15);
jLabel15.setBounds(380, 600, 35, 16);
jLabel16.setText("Book");
getContentPane().add(jLabel16);
jLabel16.setBounds(70, 600, 27, 16);
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);
if(randInt1 == 1)
{
jTextField2.setText("10%");
}
if(randInt1 == 2)
{
jTextField2.setText("20%");
}
if(randInt1 == 3)
{
jTextField2.setText("30%");
}
if(randInt1 == 4)
{
jTextField2.setText("40%");
}
if(randInt1 == 5)
{
jTextField2.setText("50%");
}
if(randInt1 > 5)
{
jTextField2.setText("£5 Off");
}
// Aplying the discount to the total
if (jTextField2.getText().equals("10%")){
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) /100*90));
}
if (jTextField2.getText().equals("20%")){
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) /100*80));
}
if (jTextField2.getText().equals("30%")){
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) /100*70));
}
if (jTextField2.getText().equals("40%")){
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) /100*60));
}
if (jTextField2.getText().equals("50%")){
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) /100*50));
}
if (jTextField2.getText().equals("£5 Off")){
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) - 5));
}
//Re-Enables the Jbutton11
jButton11.setEnabled(false);
}
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
//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
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) + 1));
//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
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) + 1));
//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
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) + 1));
//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
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) + 1));
//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
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) + 2));
//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
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) + 1));
//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
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) + 1));
//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
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) + 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
jTextField1.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) + 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();
//these will remove all the other fields in the program to let you Add more if needs be
jTextField1.setText(String.valueOf(0));
jTextField2.setText(null);
jButton11.setEnabled(true);
jLabel5.setEnabled(false);
jLabel6.setEnabled(false);
jLabel5.setEnabled(false);
jTextField5.setText(null);
jTextField4.setText(null);
}
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 checks to see if that the JTextField1 is less then or equal to jTextfield4
//this will then enabled one of the labels to either say "Inseficiant funds" or "Please take your Products"
if(Double.parseDouble(jTextField1.getText()) <= Double.parseDouble(jTextField4.getText())){
//Enables the label
jLabel6.setEnabled(true);
jTextField5.setText(String.valueOf(Double.parseDouble(jTextField1.getText()) - Double.parseDouble(jTextField4.getText())));
// creates a File that will be created when you checkout including all your items you have purchased
// the price of the items, Discount you got and your change if you have any
try {
FileWriter writer = new FileWriter("receipt.txt");
writer.write("Thank you for shopping with us, This is your reciept with all your information: \n");
writer.write(String.valueOf(list1.getItems()) + "\n");
if (jButton11.isSelected()){
writer.write("You had a " + jTextField2 + " discount. \n");
writer.write("Your final cost was: £" + jTextField2.getText() + "\n");
}
writer.write("You paid: £" + jTextField3.getText() + "\n");
writer.write("Your change was: £" + jTextField4.getText() + "\n");
}
catch(IOException e){
e.printStackTrace();
}
}
if(Double.parseDouble(jTextField1.getText()) > Double.parseDouble(jTextField4.getText())){
{
jLabel5.setEnabled(true);
}
if(Double.parseDouble(jTextField1.getText()) == Double.parseDouble(jTextField4.getText())){
{
jLabel6.setEnabled(true);
}
}
}
}
private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {
//This will display to the customer if you have any change left over
}
private void jTextField12ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
public void File(String[] args) throws FileNotFoundException, IOException {
}
//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[]) {
/* 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 jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel16;
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.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField10;
private javax.swing.JTextField jTextField11;
private javax.swing.JTextField jTextField12;
private javax.swing.JTextField jTextField13;
private javax.swing.JTextField jTextField14;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
private javax.swing.JTextField jTextField7;
private javax.swing.JTextField jTextField8;
private javax.swing.JTextField jTextField9;
private java.awt.List list1;
// End of variables declaration
}
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