Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: Structure of simple POS system

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Structure of simple POS system

    Hi All,

    I have been studying Java for some time and decided to finally try and make an application. I am going to try and build a basic cash register (Point of Sale) system that connects to a MySQL database which contains the products information (ID, name and price).

    I have a basic idea on how I wish to set this up and just want to check that I'm correct before going ahead.

    1) I intend to make the MySQL queries using JDBC.
    2) I am going to use SWING to develop the GUI. The idea is the person at the cash register enters the product ID into a text box and it add's it to the sale. The GUI will then display a list of current products and a subtotal. When the user then finishes the sale, they press a button and the details are logged in a database.

    The two main things I want to confirm are:

    3) I was going to store the products on the current sale in a 2D array. Is this the best way of doing this?
    4) In the GUI I was going to display the list of products using JTable. I dont want the user on the cash till to be able to edit the contents of the table, its simply to display what has been rung through. Again is this the best way to display this information?

    Thanks for your help,

    Joseph.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Structure of simple POS system

    store the products on the current sale in a 2D array
    No. It will be better if you make a class to hold the data. Parallel/2D arrays can be an update problem.
    A class will get you lots more flexibility. One is the typing of the class object when you call a method to work on the container with the sales data.

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Structure of simple POS system

    Thanks for the suggestion. How would I store the data in a class? Using variables within it? Or by creating a new object for each item and adding each item into an ArrayList?

    Thanks,
    Last edited by jrflynn; July 4th, 2011 at 02:25 PM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Structure of simple POS system

    creating a new object for each item and adding each item into an ArrayList
    I thought there were 2 items. I'm confused why you mentioned the 2 dim array.
    What data type is an "item"?

  5. #5
    Junior Member
    Join Date
    Jul 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Structure of simple POS system

    Sorry, I didn't explain myself properly.

    There can be an unlimited amount of items. Each item would contain: Item ID (int) / Item name (String) / Item price (double).

    My initial thoughts would be to use a 2 dim array, so that each item would have a row, with 3 column to represent the above three items.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Structure of simple POS system

    With a class, you'd put those three items: ID, name and price in one object.
    You could have a constructor that takes all three to build an object.
    unlimited amount of items
    Then you'd want to put the objects in a container like an ArrayList instead of an array.

  7. #7
    Junior Member
    Join Date
    Jul 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Structure of simple POS system

    Ok brilliant. Thanks for the advice.

    With regards to displaying the items in the GUI, I simply want a list of all the items which will get longer as each item is added to the sale. Would using the JTable to display each 'item' object be the best way?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Structure of simple POS system

    Sorry, I don't do much GUI with JTables.

  9. #9
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Structure of simple POS system

    Quote Originally Posted by jrflynn View Post
    With regards to displaying the items in the GUI, I simply want a list of all the items which will get longer as each item is added to the sale. Would using the JTable to display each 'item' object be the best way?
    Yes, a JTable would be a good solution. Each row would be an item and the columns would be ID, name, and price. See How To Use Tables.

  10. #10
    Junior Member
    Join Date
    Jul 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Structure of simple POS system

    Thanks so much for your help. Just want to check that I understand you correctly and have implemented this properly. I have made the following code which works fine. Are there any improvements to my code you would suggest or am I now going down the right track?

    order.java
    PHP Code:
    import java.util.ArrayList;

    public class 
    order {
        
    String orderStatus;
        
    double subtotal;
        
    ArrayList<productproducts = new ArrayList<product>();

        public 
    order() {
            
    orderStatus="local";
        }
        
        public 
    void addProduct(int SKUdouble priceString name) {
            
    products.add(new product(SKUpricename));
            
    subtotal=subtotal+price;
        }
        
        public 
    void removeProduct(product productToRemove) {
            
    subtotal=subtotal-productToRemove.getPrice();
            
    products.remove(productToRemove);
        }
        

    product.java
    PHP Code:
    public class product {
        
    int SKU;
        
    double price;
        
    String name;
        
        public 
    product(int SKUdouble priceString name) {
            
    this.SKU=SKU;
            
    this.price=price;
            
    this.name=name;
        }

        public 
    double getPrice() {
            return 
    price;
        }

    Thanks for your help.

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Structure of simple POS system

    One suggestion: Java naming conventions: Leading letter of name is uppercase for classes and lowercase for variables.

  12. #12
    Member hexwind's Avatar
    Join Date
    May 2011
    Location
    Tunisia
    Posts
    48
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Structure of simple POS system

    Quote Originally Posted by jrflynn View Post
    Sorry, I didn't explain myself properly.

    There can be an unlimited amount of items. Each item would contain: Item ID (int) / Item name (String) / Item price (double).

    My initial thoughts would be to use a 2 dim array, so that each item would have a row, with 3 column to represent the above three items.

    Why would you use collections? The data shall be expired once the program stops running, no?
    Choosing which container to use depends on what you will use them for. If you are gonna access your elements in a random way, you could use an ArrayList but it's slower to insert and remove elements in the middle of the list in which LinkedList is faster. If you want to have unique elements use Sets then. I hope this helps.
    My website : MediDev

  13. #13
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Structure of simple POS system

    Quote Originally Posted by jrflynn View Post
    ... Are there any improvements to my code you would suggest or am I now going down the right track?
    Other than the Java Naming Conventions previously mentioned, it's good practice to make your member variables private, particularly if you provide getters for them - class data should not be open to modification by other classes without the owning class's knowledge/consent. BTW your Product class has a getter for price, but not for name or SKU...

    Your Order class is always created with implicit 'local' status - I expected to see another constructor that could set the status explicitly.

    When you add one numeric variable to another, you can use the short-form '+=' operator, which looks a little tidier (the same goes for subtraction with '-='):
    subtotal += price;   // add price to subtotal
    The removeProduct method takes a Product argument and tries to remove it. This seems reasonable, although it ought to check that Product is actually present before trying to remove it. The addProduct method takes three arguments and creates a Product object from them. This seems unnecessary and means that the Order class has to know about the contents of a Product and how to create one. I don't think an Order needs to know, and shouldn't know what's inside the items it holds. As far as the Order is concerned, a Product is just a box from the warehouse. As it is, if you decide to change the Product class, you'll have to change the Order class too. I recommend just passing a Product to the addProduct method, so it matches the removeProduct method. The Product can be created elsewhere. Typically there would be a complete list of Products held somewhere and one of those would be selected and added to the order.

    There is also a potential problem with the removeProduct method if you're going to create multiple Product objects with the same contents (e.g. for different orders). By default, the ArrayList.remove(Object) method tries to remove the exact object that is passed to it. It looks in the list for the identical object instance, so will only find it if it was obtained from the product list in that specific Order originally. If you wanted to remove a Product with the same contents that you'd got from another Order (or created from scratch), it wouldn't be found, because it would be a different object instance. What you probably want here is for it to remove an object with the same contents, because two Product objects with the same contents surely represent the same product. This is the crucial difference between object identity and object equality. To make sure that the ArrayList will find a Product object with the same contents, you need to give the Product class an equals(..) method, that will return 'true' if the contents of the Product passed in are equal to those of the Product testing it.

    In the real world, each Product would have a unique identifier code, and this would be used to find it in collections. In this scenario, the Product objects would be stored in a Map of some kind, with the unique Product code as a key.
    Last edited by dlorde; July 6th, 2011 at 08:25 AM.

  14. #14
    Junior Member BrowenHarley's Avatar
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Structure of simple POS system

    POS is a one type of hardware operating system they provide the system of external touch terminal. This system provide many product list by rating and give point of hardware equipment and supplies. Point of sale system is a one type of information system it is used to gathering and applying the information in the market. Each pos system is very different to the other system it have also huge productivity of your business.
    Touchscreen mobile provide pos system.

Similar Threads

  1. Data Structure
    By Faha in forum Object Oriented Programming
    Replies: 9
    Last Post: November 10th, 2011, 01:35 AM
  2. Simple Banking System
    By ShadowKing98 in forum Java Theory & Questions
    Replies: 7
    Last Post: April 12th, 2011, 04:26 AM
  3. Replies: 8
    Last Post: December 9th, 2009, 04:45 PM
  4. .xls data structure
    By helloworld922 in forum JDBC & Databases
    Replies: 3
    Last Post: August 20th, 2009, 07:12 PM