Untitled
unknown
plain_text
2 years ago
3.3 kB
3
Indexable
Never
package com.mycompany.quiz2; public class Product { private String productName; private int productQuantity; private double productPrice; public Product(String productName,int productQuantity,double productPrice) { this.productName =productName; this.productQuantity = productQuantity; this.productPrice = productPrice; } public String getProductName() { return productName; } } [21:41, 06/04/2023] Danish Uni: */ package com.mycompany.quiz2; import java.util.Scanner; /** * * @author HP */ public class Store { private String StoreName; private String Storelocation; private int nbProduct = -1; private Product[] ProductList = new Product[100]; Scanner sc = new Scanner(System.in); public Store(String storeName, String storeLocation) { this.StoreName = storeName; this.Storelocation = storeLocation; [21:41, 06/04/2023] Danish Uni: } public String getStoreName() { return StoreName; } public void addProduct() { String name; int quantity; double price; if(nbProduct == 99) { System.out.println("array overflow"); } else { nbProduct++; System.out.println("input product name"); name = sc.nextLine(); System.out.println("input product quantiy"); quantity = sc.nextInt(); System.out.println("input product price"); price = sc.nextDouble(); ProductList[nbProduct] = new Product(name,quantity,price); } } public void addProductToList(Product p) { if(nbProduct==99) { System.out.println("array oveerflow"); } else { nbProduct++; ProductList[nbProduct] = p; } } public boolean searchproduct(String name) { boolean found = false; for(int i = 0; i<nbProduct;i++) { if(name == ProductList[i].getProductName()) { found = true; } } return found; } public void displayAll() { for(int i = 0;i <=nbProduct;i++) { System.out.println(ProductList[i].getProductName()); } } } */ package com.mycompany.quiz2; /** * * @author HP */ public class Application { public static void main(String[] args) { // String name; // int quantity; // float price; Product p = new Product("Shell",4,5.5); Product p1 = new Product("helix",4,5.5); Product p2 = new Product("motorolaa",4,5.5); Product p3 = new Product("Apple",4,5.5); Product p4 = new Product("Orange",4,5.5); Store s1 = new Store("Metro","Stargate"); Store s2 = new Store("Lucky One","Stargate"); s1.addProductToList(p); s1.addProductToList(p1); s1.addProductToList(p2); // s1.addProduct(p3); s2.addProductToList(p3); s2.addProductToList(p4); System.out.println(s2.searchproduct("pple")); } }