Skip to content
/ OOT Public

Creating a GUI with Java for a textile shop point of sale

Notifications You must be signed in to change notification settings

tanoojoy/OOT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OOT Assignment

Database Class

Use the database class name in any other file to be able to call its methods. Example:

database.fetch_item_ids(); //returns an array of all itemIDs
database.get_item_price_by_id(itemID); //returns the price of the item with ID "itemID"
database.insert_item(item_name, cost_price, selling_price); //creates an item with the arguments as attributes 

fetch_item_ids()

  • Arguments: None
  • Returns: String array of item IDs of all items

get_item_price_by_id(String itemID)

  • Arguments: String itemID of 1 item
  • Returns: double value of the price of that item

fetch_transport_methods()

  • Arguments: None
  • Returns: String array of names of all transport methods

insert_item(String item_name, double cost_price, double selling_price)

Creates 1 item in your database.

  • Arguments: Item name, Item cost price, Item selling price
  • Returns: Nothing

get_transport_charge(String name)

Fetches the price of 1 transport method. Searches for transport name and returns its price.

  • Arguments: Transport Name (String)
  • Returns: Transport price (double)

update_item(String item_name, double cost_price, double selling_price)

Updates 1 item in your database. The item name is searched in the database and the prices are modified.

  • Arguments: Item name, Item cost price, Item selling price
  • Returns: Nothing

delete_item(String item_name)

Deletes 1 item in your database which has the item name.

  • Arguments: Item name, Item cost price, Item selling price
  • Returns: Nothing

create_order(Customer customer, Invoice invoice)

Creates an a customer, an invoice for the customer, and the invoice's orders, in that exact order.

  • Arguments: Customer object, Invoice object
  • Returns: Nothing


Creating a checkout (Step-by-step)

Your salesperson frame will be the frame where a customer object will be created. Pretty straightforward ad explained below.

1. Create a customer object:

String first_name =  "Tanoo";
String last_name = "Joy";
String contactDetails = "62763526";
String email = "tanoo@joy.com";
String address = "Trianon";
String transportPreference = "DHL";

//new customer object
Customer customer1 = new Customer(first_name, last_name, contact_details, email, address, transportPreference);

This customer object can now be used like this:

String name = customer1.first_name + " " +customer1.last_name;
System.out.println(name); //outputs "Tanoo Joy"


2. Create Order object(s)

  • buying 2 shirts = 1 order
  • buying 2 shirts, 3 hoodies = 2 orders

The salesperson frame is also where a list or orders will be created. Include in Salesperson frame class variables:

private List<Order> order_list = new ArrayList<>();

Create a orders:

//this can be in your ActionListener
//fetch data from your GUI
int item_id;
int quantity;
double unitPrice;
double totalPrice;
String backorderstatus;

Order order1 = new Order(item_id, quantity, unitPrice, totalPrice, backorderstatus); 
order_list.add(order1); //added order 1 to order_list

//everytime the button is clicked, a new order is created and added to "order_list"

//Another actionlistener for your checkout button executes this:
new Checkout(customer1, order_list);
//this takes the customer object and their order list

All of the above happen before payment is done. After a payment method is chosen, and a checkout is confirmed, an invoice can now be created with the customer and their orders.

3. Create invoice with the order(s) and customer above

//new invoice object
Invoice invoice1 = new Invoice();


for (Order order : order_list) {   //for every "order" in "order_list"
    invoice.AddOrder(order);  //add that order to the invoice
}

String transportPreference = customer1.transportPreference; //from customer object
invoice.AddTransportPreference(transportPreference) //added Transport Name to invoice

double transport_charge = database.get_transport_charge(transportPreference); //from database class
invoice.AddTransportCharge(transport_charge); //added Transport charge to invoice

//the invoice, orders and the customer are now ready to be inserted in the database:
database.create_order(invoice1, customer1);

//done


Full example code

String first_name =  "Tanoo";
String last_name = "Joy";
String contactDetails = "62763526";
String email = "tanoo@joy.com";
String address = "Trianon";
String transportPreference = "DHL";

//new customer object
Customer customer1 = new Customer(first_name, last_name, contact_details, email, address, transportPreference);

int item_id;
int quantity;
double unitPrice;
double totalPrice;
String backorderstatus;

//new order objects
Order order1 = new Order(item_id, quantity, unitPrice, totalPrice, backorderstatus);  //shirts

Order order2 = new Order(item_id, quantity, unitPrice, totalPrice, backorderstatus);  //hoodies

//new invoice object
Invoice invoice1 = new Invoice();

//add the 2 orders
invoice1.AddOrder(order1); //added shirts to invoice
invoice.AddOrder(order2);  //added hoodies to invoice
//the invoice object now CONTAINS the 2 order objects

String transportPreference = customer1.transportPreference; //from customer object
invoice.AddTransportPreference(transportPreference) //added Transport Name to invoice

double transport_charge = database.get_transport_charge(transportPreference); //from database class
invoice.AddTransportCharge(transport_charge); //added Transport charge to invoice

//the invoice, orders and the customer are now ready to be inserted in the database:
database.create_order(invoice1, customer1);

//done

About

Creating a GUI with Java for a textile shop point of sale

Resources

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •