Developing POS (Point Of Sales) System using Java

Sr.Other Projects
1Airline Ticketing Campaign Application (NON-WEB)
2Build and Deployment of Java EE Web Application (Airline Ticket Reservation)

Create 3D Animation and Video In 3 Clicks...know more

Learn PIANO from Home...know more

Learn SPANISH from Home...know more

§  Business Requirements
Develop POS (Point Of Sales) system which will be used by Shop Operator and will support below  functionality for Phase - 1,
  1. Based on the Item purchased by Customer, the Operator can select that item from the Item list displayed on the Terminal screen
  2. For each Customer, the system will keep record of all items per transaction and finally persist the transaction information to external file for future use.
  3. Display Total sell amount at any point of time
§  Requirements Analysis
  1. After authorized Operator starts the system, she will be displayed with all available Item Numbers and Description, 
  2. Based on the Items presented by Customer, the Operator will record each item to the system
  3. System will record each transaction which should contains following information (TransactionId, Date[ddmmyyyy], Time[HH:min:sec], OperatorId, MachineId, CustomerId,  ItemId, ItemPriceAmount)
  4. Persist all transactions to external file : alltransactions.csv
  5. Reporting function to display total sale information 
  6. Maintain Item information in external file : itemmaster.csv
  • File Specifications
    • alltransactions.csv
      • TransactionId : (T1)
      • Date[ddmmyyyy] : (20120721) 
      • Time[HH:min:sec] : (17:21:45)
      • OperatorId : (A007)
      • MachineId : (M1)
      • CustomerId : (C1)
      • ItemId : (I1) 
      • ItemPriceAmount : (250)
      • ItemPriceCurrency : (JPY)
    • itemmaster.csv
      • ItemId : (I1)
      • ItemDescription : (Milk)
      • ItemPriceAmount : (250)
      • ItemPriceCurrency : (JPY)
TODO : Add authentication, add logging and auditing, add Internationalization to display UI based on the system language (For Japanese system display UI in Japanese Language, Similarly for other languages)

§  Domain Model


§  Implementation in Java
  • Project Structure
  • Source code
[itemmaster.csv]
i1,Milk,250,jpy
i2,Bread,170,jpy
i3,Water,100,jpy



[POSApp.java]

import java.util.HashMap;
import java.util.Iterator;
import model.Item;
import controller.ItemManager;
import controller.ShoppingCart;

public class POSApp {

 public static void main(String[] args) {
  //Load list of available item list for Operator's reference
  ItemManager itemManager = new ItemManager();
  HashMap<String, Item> itemMap = itemManager.getAllItems();

  Iterator<String> iterator = itemMap.keySet().iterator();

  System.out.println("-----List of Available Items------[Item#, Description, Price, Currency]");

  while (iterator.hasNext()) {
   Item item = itemMap.get(iterator.next()); 
   System.out.println(item.printStatus());
  }

  System.out.println("-------------------------------");

  ShoppingCart cart = new ShoppingCart();
  cart.start();
  cart.checkOut();

  System.out.println("Thank you for using POS, Have a nice day !!! ");
 }
}

[ItemManager.java]

package controller;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Scanner;
import model.Item;
import model.Price;

public class ItemManager {

 /**
  * Method to return all available Item information after reading from underlying data source, such as file.
  * @return Map of Items in key/value pair, where key is itemId and value is other item details
  */
 public HashMap<String, Item> getAllItems() {
 
  HashMap<String, Item> itemMap = new HashMap<String, Item>();
 
  //create file object from the external file
  File itemFile = new File("itemmaster.csv");
 
  //When reading a file it is necessary to catch Exception, 
  //such as FileNotFoundException by using try-catch block.
  try {
   //Use Scanner to read external file : itemmaster.csv
   Scanner scanner = new Scanner(itemFile);
  
   //continue the loop till the end of file
   while (scanner.hasNext()) {
   
    //Read record from the external file line by line
    String fileRecord = scanner.nextLine();

    //split the record based on the comma (,) delimiter
    //comma delimiter to split the string record 
    //into separate string and set to array String[]

    String[] fileRecordSplit = fileRecord.split(",");  
   
    //Populate item object from the split record read from the file
    Item item = new Item();
    item.setId(fileRecordSplit[0]);
    item.setDescription(fileRecordSplit[1]);
   
    //create price object to be set later into item object
    Price price = new Price();
    price.setAmount(Double.parseDouble(fileRecordSplit[2]));
    price.setCurrency(fileRecordSplit[3]);

    item.setPrice(price);
   
    itemMap.put(item.getId(), item); //key is ItemId and Value is entire item Object
   }
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

  return itemMap;
 }
}


[ShoppingCart.java]
package controller;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;
import model.Customer;
import model.Item;
import model.Machine;
import model.Operator;
import model.Transaction;
import dao.ShoppingCartDao;

public class ShoppingCart {

 ShoppingCartDao cartDao = new ShoppingCartDao();

 /**
  * Method to start Shopping process
  */
 public void start() {
 
  int choice = 0;
 
  Scanner scanner  = new Scanner(System.in);
 
  do {
   System.out.println("Enter [1 = Add, 2 = Delete, 0 = Exit]");
   choice = scanner.nextInt();
  
   switch(choice) {
    case 1 : 
     add();
     break;
    case 2 :
     Scanner sc = new Scanner(System.in);
     System.out.println("Enter Item id to be removed = ");
     String itemId = sc.next();
     delete(itemId);
     break;
    case 0 :
     break;
    default:
    System.out.println("Invalid choice.");

   }
  } while (choice != 0);
 }

 //DAO = Data Access object
 //csv = Comma Separate Value
 public void add() {
  //TODO: do validation if any
  cartDao.create();
 }

 /**
  * Method to prepare final transaction details and print the receipt on the screen
  */
 public void checkOut() {
  //TODO: do validation if any
  ArrayList<String> itemIds = cartDao.read();
 
  //Create details of each item based on the item id
  ArrayList<Item> purchaseditems = cartDao.loadItemDetails(itemIds);

  double total = 0;
 
  System.out.println("++++++ List of items purchased ++++++");
 
  for (Item item : purchaseditems) {
    total = total + item.getPrice().getAmount();
    System.out.println(item.printStatus());
  }

  System.out.println("-----------------------------------");
  System.out.println("Total amount : " + total);
  System.out.println("+++++++++++++++++++++++++++++++++++");
 
  //record the transaction to external persistent file
  recordTransaction(purchaseditems);
 }

 //method to persist transaction details to external file for further usage
 private void recordTransaction(ArrayList<Item> purchaseditems) {
  //create Transaction
  Transaction transaction = new Transaction();
  transaction.setId("T-788"); //TODO: write a method to generate unique Id for each transaction
 
  SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
  transaction.setDate(dateFormat.format(new Date()));
 
  Operator operator = new Operator();
  operator.setId("O-005");
  transaction.setOperator(operator);
 
  Machine machine = new Machine();
  machine.setId("M-101");
  transaction.setMachine(machine);
 
  //create and set customer
  Customer customer = new Customer();
  customer.setId("C-101"); //TODO: write a method to generate unique Customer Id for each customer transaction  
  transaction.setCustomer(customer); 

  //Convert from ArrayList of item to the Array of item objects
  Item[] items = purchaseditems.toArray(new Item[purchaseditems.size()]);
  transaction.setItems(items);
 
  //save transaction to external file
   try {
             FileWriter writer = new FileWriter("alltransaction.csv", true); //set true for append mode
             BufferedWriter bufferedWriter =new BufferedWriter(writer);
             
             for (Item item : items) {             
              bufferedWriter.write(transaction.getId());
              bufferedWriter.write(",");
              bufferedWriter.write(transaction.getDate());
              bufferedWriter.write(",");
              bufferedWriter.write(transaction.getOperator().getId());
              bufferedWriter.write(",");
              bufferedWriter.write(transaction.getMachine().getId());
              bufferedWriter.write(",");
              bufferedWriter.write(transaction.getCustomer().getId());
              bufferedWriter.write(",");
              bufferedWriter.write(item.getId());
              bufferedWriter.write(",");
              //convert double to string before writing to file              
              bufferedWriter.write(String.valueOf(item.getPrice().getAmount())); 
              bufferedWriter.write("\n");
             }
             
             bufferedWriter.flush();
             bufferedWriter.close();
             writer.close();
         } catch (IOException e) {
             e.printStackTrace();
         }
 }

 public void delete(String itemId) {
  //TODO: do validation if any
  cartDao.delete(itemId);
 }
}


[ShoppingCartDao.java]
package dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import model.Item;
import controller.ItemManager;

public class ShoppingCartDao {
 //CRUD , Create, Read, Update, Delete
 //Data Source

 //Load items to in memory storage using ArrayList
 static ArrayList<String> itemIdList = new ArrayList<String>();

 /**
  * Add item id to itemIdList ArrayList
  */
 public void create() {
  Scanner scanner = new Scanner(System.in);
  String itemId = "0";
 
  do {
   //Prompt to Operator !!!
   System.out.println("Enter ItemId, [0 = Exit] : ");
   itemId = scanner.next();
   //do not add itemId as 0 (zero)
   if (!itemId.equals("0")) {
    itemIdList.add(itemId);
   }
  
  } while (!itemId.equals("0"));
 }

 /**
  * Return list of Item ids of the items purchased by customers
  * @return array list of item ids
  */
 public ArrayList<String> read() {
  return itemIdList;
 }

 /**
  * TODO : Implement this method if necessary
  */
 public void update() {
 }

 /**
  * Delete item id from the itemIdList 
  * @param itemid the id to be removed from the list
  */
 public void delete(String itemid) {
  itemIdList.remove(itemid);
 }

 /**
  * Method to create item objects based on list of item Ids
  * @param itemIds ids of the item to be populated with all necessary details such as Description, Price 
  * @return items with details 
  */
 public ArrayList<Item> loadItemDetails(ArrayList<String> itemIds) {
 
  ArrayList<Item> purchasedItemList = new ArrayList<Item>();
 
  //read all the available item map
  ItemManager itemManager = new ItemManager();
  HashMap<String,Item> allItems = itemManager.getAllItems();
 
  for (int i = 0; i < itemIds.size(); i++) {
   purchasedItemList.add(allItems.get(itemIds.get(i)));
  }
  return purchasedItemList;
 }
}


[Customer.java]
package model;

public class Customer {
 private String id;

 public String getId() {
  return id;
 }

 public void setId(String id) {
  this.id = id;
 }
}

[Item.java]
package model;

public class Item {

 private Price price;
 private String id;
 private String description;

 public Price getPrice() {
  return price;
 }
 public void setPrice(Price price) {
  this.price = price;
 }
 public String getId() {
  return id;
 }
 public void setId(String id) {
  this.id = id;
 }
 public String getDescription() {
  return description;
 }
 public void setDescription(String description) {
  this.description = description;
 }

 /**
  * Method to return current state of this Object instance 
  * (can be also achieved by overriding toString() method of Object class) 
  * @return current state of this object properties
  */
 public String printStatus() {
  return  id + ","
    description + "," +
    price.getAmount() + ","
    price.getCurrency()
    ;
 }
}

[Machine.java]
package model;

public class Machine {
 private String id;
 private String model;
 private String vendor;

 public String getId() {
  return id;
 }
 public void setId(String id) {
  this.id = id;
 }
 public String getModel() {
  return model;
 }
 public void setModel(String model) {
  this.model = model;
 }
 public String getVendor() {
  return vendor;
 }
 public void setVendor(String vendor) {
  this.vendor = vendor;
 }
}

[Operator.java]
package model;

public class Operator {
 private String id;

 public String getId() {
  return id;
 }

 public void setId(String id) {
  this.id = id;
 }
}

[Price.java]
package model;

public class Price {

 private double amount;
 private String currency;// JPY, USD

 public double getAmount() {
  return amount;
 }
 public void setAmount(double amount) {
  this.amount = amount;
 }
 public String getCurrency() {
  return currency;
 }
 public void setCurrency(String currency) {
  this.currency = currency;
 }

}

[Transaction.java]
package model;

public class Transaction {

 private String id;
 private Operator operator;
 private Machine machine;
 private Customer customer;
 private String date;
 private Item[] items;

 public String getDate() {
  return date;
 }
 public void setDate(String date) {
  this.date = date;
 }
 public Item[] getItems() {
  return items;
 }
 public void setItems(Item[] items) {
  this.items = items;
 }
 public String getId() {
  return id;
 }
 public void setId(String id) {
  this.id = id;
 }
 public Operator getOperator() {
  return operator;
 }
 public void setOperator(Operator operator) {
  this.operator = operator;
 }
 public Machine getMachine() {
  return machine;
 }
 public void setMachine(Machine machine) {
  this.machine = machine;
 }
 public Customer getCustomer() {
  return customer;
 }
 public void setCustomer(Customer customer) {
  this.customer = customer;
 }
}
================================================

  • Finally, run POSApp application and provide values as shown in green colour below, it will also generate alltransactions.csv file.


Output

-----List of Available Items------[Item#, Description, Price, Currency]
i3,Water,100.0,jpy
i2,Bread,170.0,jpy
i1,Milk,250.0,jpy
-------------------------------
Enter [1 = Add, 2 = Delete, 0 = Exit]
1
Enter ItemId, [0 = Exit] : 
i2
Enter ItemId, [0 = Exit] : 
i3
Enter ItemId, [0 = Exit] : 
i2
Enter ItemId, [0 = Exit] : 
i1
Enter ItemId, [0 = Exit] : 
0
Enter [1 = Add, 2 = Delete, 0 = Exit]
0
++++++ List of items purchased ++++++
i2,Bread,170.0,jpy
i3,Water,100.0,jpy
i2,Bread,170.0,jpy
i1,Milk,250.0,jpy
-----------------------------------
Total amount : 690.0
+++++++++++++++++++++++++++++++++++
Thank you for using POS, Have a nice day !!!

================================================
For Source Download Please check link at top of this blog.
================================================

63 comments :

  1. I am very thankful to all your team for sharing such inspirational information about POS System.

    ReplyDelete
  2. Some POS system are referred to as Retail Management System which I think is much better.
    POS System

    ReplyDelete
  3. When i am running these source code ,this is not printing water,bread and price and currencies like stuffs .What is the problem??Thank you in advance.

    ReplyDelete
  4. Please check project structure section at top, the itemmaster.csv file might be missing. Please copy error details.

    ReplyDelete
  5. I am very thankful to all your team for sharing such inspirational information about point of sale system.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Exception in thread "main" java.lang.NullPointerException
    at Controller.ShoppingCart.checkOut(ShoppingCart.java:75)
    at POSApp.main(POSApp.java:27)

    I'm getting this error. why is this?

    ReplyDelete
  8. Exception in thread "main" java.lang.NullPointerException
    at Controller.ShoppingCart.checkOut(ShoppingCart.java:75)
    at POSApp.main(POSApp.java:27)

    I'm getting this error. why is this?

    ReplyDelete
    Replies
    1. Please create itemmaster.csv under POS project, with following contents,

      i1,Milk,250,jpy
      i2,Bread,170,jpy
      i3,Water,100,jpy

      Please refer to top of this post.

      Delete
  9. getting this error had create itemmaster.csv

    Exception in thread "main" java.lang.NullPointerException
    at controller.ShoppingCart.checkOut(ShoppingCart.java:75)
    at pos1.POSApp.main(POSApp.java:31)

    ReplyDelete
  10. Please download source and import it into Eclipse and retry. (For download link please check at the top of this blog.)

    ReplyDelete
  11. thanks it works perfectly don`t know what was the problem when I was copying the code

    ReplyDelete
  12. thanks.this is very nice article.your information is very usefully for pos pos system

    ReplyDelete
  13. Nice information and easy to use thanks for sharing this post.

    Pos Solutions

    ReplyDelete
  14. Great article thanks for sharing this useful information. Point of sale

    ReplyDelete
  15. Thanks for sharing about pos software...keep sharing...

    ReplyDelete
  16. It is great post it shares lot of information...thank you.
    point of sale software for Retail Billing, Inventory & Accounting Management, Free Download Marg POS System software, 6 Lakh+ MARG users, 500+ Sales/Support centers, Stocks, Accounts, Vat/e-Return and TDS, India.

    ReplyDelete
  17. This is the Great article about your gift registry system. Sale System For Retail Its pretty interesting.Thanks for this wonderful post...

    ReplyDelete
  18. Thanks for sharing such a nice article. epos i love your useful post for us. your idea is mind blowing that's why i would like to appreciate your work.

    ReplyDelete
  19. Thanks for sharing the Java Code for developing POS system. This will help students for doing new in their Java field. I really appreciate your work.

    Extra Insights

    ReplyDelete
  20. very Interesting and useful information. EPOS System Uk you have shared and keep sharing the blogs....

    ReplyDelete
  21. This blog on Epos Software will make us more EPOS SOFTWARE Uk aware of its benefits, usage and how its working for every business..

    ReplyDelete
  22. The Most company are like this epos software. Epos System it is easy way to keep the customer information.

    ReplyDelete
  23. I am very thankful to all your team pos system for sharing such inspirational information about bar EPOS system.

    ReplyDelete
  24. Thank full , EPOS Systems UK he was new Way to help to us to get the business running sucessfull.

    ReplyDelete
  25. Wonderful post, pos system for retail thankful to all your team for sharing such best information about POS systems.

    ReplyDelete
  26. Its really a great post, thanks for sharing, More useful Small or any business epos system system and its to good for business.

    ReplyDelete
  27. Thanks a lot for that information to share. epos system That was a really Interesting post and I would really like to know more and more.

    ReplyDelete
  28. Thanks for review, it was excellent and very informative. Please Visit:

    pharmacy software
    retail systems
    pos cash register

    ReplyDelete
  29. Thanks for sharing a nice post. epos systems It's been really informative and helped me a lot. Keep posting more posts.

    ReplyDelete
  30. Hello I am so happy with your blog site,Thanks for sharing the article. Please Visit:

    pos cash register
    cafe pos systems
    retail systems

    ReplyDelete
  31. The depth of articles can easily be felt of this blog. Very precise and straight to the mark. I understood easily the matter of fact which the author of this blog wanted to deliver through his thoughts. Looking for more.ระบบ POS

    ReplyDelete
  32. I know the desktop Best Point of Sale which can be operate through web and exe at a time, simple faster and dynamic.

    ReplyDelete
  33. Hi,

    Thanks for sharing a very interesting article about Developing POS (Point Of Sales) System using Java. This is very useful information for online blog review readers. Keep it up such a nice posting like this.

    From,
    Prabhu,
    POS Billing Software

    ReplyDelete
  34. point of sale systems for small business

    Keep up with latest updates on EPOS system point of sale, with iOS and Android support coming soon. Restaurants, coffee shops, bars, retail, street food

    ReplyDelete
  35. Thanks for giving important information
    Looking for to buy POS check it out @
    Bridge POS

    ReplyDelete
  36. Your post is extremely helpful. epos system I will keep following. Thank you for sharing this information.

    ReplyDelete
  37. Thanks a lot for that information. epos software That was a really Intresting post and I would really like to know more.

    ReplyDelete
  38. I really appreciate your effort of writing such a informative post and sharing with us. Keep up the good work.

    ReplyDelete
  39. Thank you for Sharing this great post, epos software I'll follow you from now so i can read all of your posts.

    ReplyDelete
  40. What IDE did you use I'm Netbean but still nothings working please help

    ReplyDelete
  41. Thanks for your great information.Keep updating more information from your blog.I will be waiting for your next post. retail management software | retail management software | restaurant management system

    ReplyDelete
  42. Nice blog, very interesting to read
    I have bookmarked this article page as i received good information from this.

    Best POS Software in India | POS Software for Retail Stores in Hyderabad

    cloud based erp software in

    hyderabad
    | cloud erp

    software

    ReplyDelete
  43. Intelepos is offering a simple but effective Epos System for Takeaway to manage your entire business smoothly. It will help you to learn about the customers’ requirements and preferences. Our Epos has the following features:
    Real-time order tracking
    Daily, weekly, and monthly sales report
    Manage your staff
    Epos system for takeaway
    Epos system and Software for takeaway

    ReplyDelete
  44. This is great blog keep it up. epos market I read all your article and I really like it.Thanks for sharing.

    ReplyDelete
  45. This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works http://home2bis.com/sales-course/

    ReplyDelete
  46. Its good to be here, very nice post, the content is amazing, keep posting friend it will be very helpful for everyone, Thanks for sharing. I really liked it.
    Thanks And Regards POS Systems For Coffee Shops.

    ReplyDelete
  47. Great post I really appreciate this post it seems that there's a lot of interesting on this site I will bookmark your page for more new updates on your site. keep it up.
    Retail Management System

    ReplyDelete
  48. Hi, I get this error when running the application "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1" any idea how to fix it?

    ReplyDelete
  49. Thanks for sharing such beautiful information with us.
    I hope you will share some more info about point of sale systems. Please Keep Sharing!

    Point Of Sale Software

    ReplyDelete
  50. Certification is the basement of any Salesforce professional's skill. It is the best way to represent your level of skill and areas of expertise to current employer. Salesforce training in Chennai

    ReplyDelete
  51. Don’t get too caught up on manning your exhibition booth or constantly looking for someone to pitch your ideas. Give your throat and ankles a rest. And most importantly, stay hydrated and nourished! Take shifts and rotate between your team. event management and free online registration software

    ReplyDelete
  52. Amazing article!
    Payment Processing, Cloud Merchant System, Cloud POS, & Business Management Software

    • No contract. No monthly fees.
    • Unique systems to fit your industry needs
    • Retail & Restaurant Options
    • Online Store
    • Ticketing & Services Option
    • Personalized Customer Support
    • With No Contracts
    Completely customizable technology with customer relationship & Inventory Management.

    ReplyDelete
  53. The point of sale system or POS system is where the customer makes the payments against the goods or services offered by the company. Growing adoption for contactless payments and the propagation of Near Field Communication (NFC) devices in the industrial environment, has led to a roll in the adoption of integrated POS terminals.https://www.valuemarketresearch.com/report/point-of-sale-pos-system-market

    ReplyDelete
  54. Retail is a tough market. Successful retail businesses are able to closely monitor inventory, adapt to their profit and loss to keep high margin merchandise in stock and keep their employees running off a good system that allows them to sell goods but also track their respective performance. Sky does all of the above.

    Our Retail POS are designed to address the challenges of Small & Independent Aspirants, Retailers and large multi-store Retail Chains. Their sector specific orientation, built using latest technologies, assure retailers 'a visible improvement' in customer engagement, by helping them source the right product at right price at the right time.

    ReplyDelete
  55. Retail POS Software in UAE, Single Lisence Software in UAE, Cashiers Software in UAE
    https://gccgamers.com/retail-pos-software.html
    Retail Software in UAE, Safe Shopping Multiple Payment Options Express Delivery GCC Gamers Moneyback Guarantee.
    1634611551066-10

    ReplyDelete
  56. epos till system for a restaurant in the UKEPOS software, Electronic Point of Sale systems

    epos system for retail shopA retail EPOS system, or Electronic Point-of-Sale system

    ReplyDelete
  57. Hi there!

    I had a very nice experience in your blog, actually I found this post explanatory and informative, keep sharing the best content

    regards

    Salvatore from Visite as Cataratas do Iguaçu em Foz do Iguaçu, Paraná - Brasil.

    Thanks and take care

    ReplyDelete
  58. This comment has been removed by the author.

    ReplyDelete
  59. Those who work in the retail industry are aware of the importance of employing sound business methods. There are a lot of things that need to be done in order to keep your retail shop chain, whether it be an offline or an online one, on the right track in order to ensure the success of your company. Your company can improve its efficiency, provide a better experience for its customers, and simplify its operations with effective Retail Management Software.

    ReplyDelete
  60. Great post! Thanks. Looking for the best ERP system? Click on this link!

    ReplyDelete