import java.util.ArrayList;
public class Products {
private int price;
private String productsId;
private ArrayList<Products> products;
public Products() {
}
public Products(int price, String productsId) {
this.price = price;
this.productsId = productsId;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getProductsId() {
return productsId;
}
public void setProductsId(String productsId) {
this.productsId = productsId;
}
public ArrayList<Products> getProducts() {
return products;
}
public void setProducts(ArrayList<Products> products) {
this.products = products;
}
@Override
public String toString() {
return "Products [price=" + price + ", productsId=" + productsId + ", products=" + products + "]";
}
public void searchProduct(Products product) {
for (Products pr : products) {
if (product.productsId.equals(pr.productsId)) {
System.out.println(product.toString());
} else if (!(product.productsId.equals(pr.productsId))) {
System.out.println("No such product!");
}
}
}
public void saveProduct(Products product) {
for (Products pr : products) {
if (product.productsId.equals(pr.productsId)) {
System.out.println("Product with id: " + product.productsId + " already consist!");
} else if (!(product.productsId.equals(pr.productsId))) {
products.add(product);
System.out.println("Product added.");
}
}
}
public void updateProduct(Products product, int price) {
for (Products pr : products) {
if (product.productsId.equals(pr.productsId)) {
pr.setPrice(price);
System.out.println("Product with id: " + product.productsId + " changed pice to: " + price);
}
}
}
public void deleteProduct(Products product) {
for (Products pr : products) {
if (product.productsId.equals(pr.productsId)) {
products.remove(product);
System.out.println("Product with id: " + product.productsId + " delated.");
} else if (!(product.productsId.equals(pr.productsId))) {
System.out.println("No such product!");
}
}
}
public void displayMenu() {
for (Products pr : products) {
System.out.println(pr.toString());
}
}
public void captureProduct(Products product) {
for (Products pr : products) {
if (product.productsId.equals(pr.productsId)) {
products.remove(product);
System.out.println("Product with id: " + product.productsId + " captured.");
} else if (!(product.productsId.equals(pr.productsId))) {
System.out.println("No such product!");
}
}
}
public void exitAplication() {
System.out.println("Exit.");
}
}
public class Main {
public static void main(String[] args) {
Products products = new Products();
products.searchProduct(products);
products.saveProduct(products);
products.updateProduct(products, 23);
products.deleteProduct(products);
products.displayMenu();
products.captureProduct(products);
products.exitAplication();
}
}
Comments
Leave a comment