Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 KB | None | 0 0
  1. package application;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class LCD implements TotalSumPrinter, ExitOptionImplement{
  6.  
  7.     private Receipt receipt;
  8.     private BarcodesScanner barcodesScanner;
  9.     private static final String ERROR_MESSAGE = "Invalid bar-code";
  10.     private static final String PRODUCT_IS_NOT_FOUND_MESSAGE = "Product not found";
  11.     private static final String EXIT = "exit";
  12.  
  13.     public LCD(){
  14.         barcodesScanner = new BarcodesScanner();
  15.         receipt = new Receipt();
  16.     }
  17.  
  18.     public BarcodesScanner getBarcodesScanner() {
  19.         return barcodesScanner;
  20.     }
  21.  
  22.     public Receipt getReceipt() {
  23.         return receipt;
  24.     }
  25.  
  26.     public void searchingProduct(String barcode){
  27.         barcodesScanner.oprtionalInputs(barcode);
  28.         if(barcodesScanner.getIsBarcodeEmpty()){
  29.             displayErrorMessage();
  30.             barcodesScanner.setIsBarcodeEmpty(false);
  31.         }else if(productIsNotFound(barcodesScanner.getProduct())){
  32.             displayProductIsNotFoundMessage();
  33.         }
  34.         else{
  35.             displayNameAndPriceOfProduct(barcodesScanner.getProduct());
  36.             receipt.addProductToList(barcodesScanner.getProduct());
  37.         }
  38.     }
  39.  
  40.     public void window(){
  41.         System.out.println("Write the barcode of a product");
  42.         String barcode = "";
  43.         Scanner sc = new Scanner(System.in);
  44.  
  45.         while(true){
  46.             barcode = sc.nextLine();
  47.             if(barcode.equalsIgnoreCase(EXIT)){
  48.                 break;
  49.             }
  50.             searchingProduct(barcode);
  51.         }
  52.         receipt.countTotalSum();
  53.         printTotalSum();
  54.     }
  55.     private boolean productIsNotFound(Product product) {
  56.         return product == null;
  57.     }
  58.  
  59.     private void displayNameAndPriceOfProduct(Product product){
  60.         System.out.println(product.getName() + " " + product.getPrice());
  61.     }
  62.  
  63.     private void displayProductIsNotFoundMessage(){
  64.         System.out.println(PRODUCT_IS_NOT_FOUND_MESSAGE);
  65.     }
  66.  
  67.     private void displayErrorMessage(){
  68.         System.out.println(ERROR_MESSAGE);
  69.     }
  70.  
  71.     @Override
  72.     public void printTotalSum(){
  73.         System.out.println("============||LCD||============" +
  74.                 "\n******************************"+
  75.                 "\nTotal sum: " + receipt.getTotalSum() + "              *"+
  76.                 "\n******************************" +
  77.                 "\n===============================\n\n");
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement