コード例 #1
0
  public static void printInput(Product[] objectArray) throws IOException {

    System.out.println("The input data from the file is: \n");
    for (Product item : objectArray) {
      System.out.println(item.getName() + " " + item.getPrice());
    }
  } // (optional) - displays what was read from the input file
コード例 #2
0
  // add product to database using a product object
  public boolean addProductEntry(Product product, String server_name) {
    boolean success = true;

    this.product_list.add(product); // add product to database
    addStoredLocation(product.getName(), server_name); // update stored locations of product

    return success;
  }
コード例 #3
0
  // retrieve stored list of products from products file
  public Product[] getStoredProducts() {
    Product[] products = (Product[]) readFile(getProductFileName());

    // print names of products being returned
    for (Product product : products) {
      System.out.println("getStoredProducts: Returned " + product.getName());
    }

    return products;
  }
コード例 #4
0
  // retrieve product from database
  public Product getProductEntry(String name) {
    Product product = null;

    for (Product entry : getProducts()) {
      if (entry != null && entry.getName().equals(name)) {
        product = entry;
        break;
      }
    }

    return product;
  }
コード例 #5
0
  // remove product from database
  public boolean deleteProduct(String name) {
    boolean success = true;

    Iterator<Product> products = this.product_list.iterator();
    while (products.hasNext()) {
      Product entry = products.next();
      if (entry.getName().equals(name)) {
        success = this.product_list.remove(entry);
        removeStoredLocation(name); // remove product entry
        break;
      }
    }

    return success;
  }