#Feat - Suche über ID, Name implementiert sowie Lagerbestand senken.
parent
b5fa650d8e
commit
6f15feb5d3
|
|
@ -34,8 +34,8 @@ public class OnlineShop {
|
|||
double net = Double.valueOf(partsOfList[3]);
|
||||
double mwst = Double.valueOf(partsOfList[4]);
|
||||
int stock = Integer.valueOf(partsOfList[5]);
|
||||
Product product = new Product(id,name,weight,net,mwst,stock);
|
||||
lager.add(product);
|
||||
Product prd = new Product(id,name,weight,net,mwst,stock);
|
||||
lager.add(prd);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -47,6 +47,34 @@ public class OnlineShop {
|
|||
return produkt;
|
||||
}
|
||||
|
||||
public Product getProdId(int prodID){
|
||||
for(int i = 0; i < lager.size(); ){
|
||||
Product prod = lager.get(i);
|
||||
if(prod.getProdID() == prodID){
|
||||
return prod;
|
||||
}
|
||||
}
|
||||
return null; //<------ Nichts gefunden. Referenz null
|
||||
}
|
||||
public ArrayList<Product> seachByName(String searchText){
|
||||
ArrayList<Product> result = new ArrayList<>();
|
||||
for(Product prod : lager){
|
||||
if(prod.getName().equalsIgnoreCase(searchText)){
|
||||
result.add(prod);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public boolean reduceStock(Product prod, int quantity){
|
||||
if(prod.getStock() >= quantity){
|
||||
prod.setStock(prod.getStock() - quantity);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static ArrayList<String> readFile(String path) throws FileNotFoundException {
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
Scanner sc = new Scanner(new File(path));
|
||||
|
|
|
|||
Loading…
Reference in New Issue