Commit 40fa0432 authored by Eskil Helgesen Schjølberg's avatar Eskil Helgesen Schjølberg
Browse files

Innlevering

parent 3d9d95ab
# bakeri
System for bakeri
\ No newline at end of file
System for bakeri. Ble et stykke unna ferdig, så er ikke klar for kjøring.
\ No newline at end of file
package system;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class Controller {
private List<Ingrediens> inventoryList = new ArrayList<>();
private List<Recipe> recipeList = new ArrayList<>();
public void registerNewIng(String name, int inventoryGrams) {
//Feilhaandtering
Ingrediens ingrediens = new Ingrediens(name, inventoryGrams);
inventoryList.add(ingrediens);
}
public void registerNewRec(String name, String productType, List<Ingrediens> ingrediensList) {
//Feilhaandtering
Recipe recipe = new Recipe(name, productType, ingrediensList);
recipeList.add(recipe);
}
public void updateInventory(int ingID, int gramsAdded) {
inventoryList.get(ingID-1).addGrams(gramsAdded);
}
public List<Recipe> getAllRecByType(String type) {
List<Recipe> recipeListByType = new ArrayList<>();
for (Recipe recipe : recipeList) {
if (recipe.getProductType().equalsIgnoreCase(type)) {
recipeListByType.add(recipe);
}
}
recipeListByType.sort(new RecipeSorter());
return recipeListByType;
}
public class RecipeSorter implements Comparator<Recipe> {
@Override
public int compare(Recipe o1, Recipe o2) {
String a = o2.getName();
String b = o1.getName();
return a.compareTo(b);
}
}
/*
public boolean produceNumberOfProducts(int rec_id) {
//Rakk ikke
}
public boolean removeAmountOfIng(int amount, int rec_id){
//Rakk ikke
}
*/
}
package system;
public class Ingrediens {
private static int ing_id_generator = 0;
int ingID;
String name;
int inventoryGrams;
public Ingrediens(String name, int inventoryGrams) {
ing_id_generator ++;
this.ingID = ing_id_generator;
this.name = name;
this.inventoryGrams = inventoryGrams;
}
public int getIngID() {
return ingID;
}
public String getName() {
return name;
}
public int getInventoryGrams() {
return inventoryGrams;
}
public void addGrams(int gramsAdded) {
inventoryGrams = inventoryGrams + gramsAdded;
}
}
\ No newline at end of file
package system;
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
public class Recipe {
private static int rec_id_generator = 0;
int recipeID;
String name;
SimpleDateFormat date;
String productType;
private List<Ingrediens> ingrediensList;
public Recipe(String name, String productType, List<Ingrediens> ingrediensList ){
rec_id_generator++;
recipeID = rec_id_generator;
//date
this.name = name;
this.productType = productType;
this.ingrediensList = ingrediensList;
}
public SimpleDateFormat getDate() {
return date;
}
public List<Ingrediens> getIngrediensList() {
return ingrediensList;
}
public String getName() {
return name;
}
public String getProductType() {
return productType;
}
public int getRecipeID() {
return recipeID;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment