Baking Information System

CA Exercise 2 – Baking Information System

The objective of this CA exercise is to create an application for storing and retrieving information on
baked goods (e.g. cakes, breads, biscuits, etc.) and the ingredients/components (e.g. flour, eggs, sugar,
etc.) that comprise them. The application should include both hashing and sorting functionality, and
provide a graphical user interface.
The application should allow/support the following:
 The addition of new baked goods to the system. These might be cakes, breads, biscuits, tarts,
pies, etc.
o Baked good name, place/country of origin, textual description, and an image/picture of
the completed baked good (as a URL) are among key data to store.
 The addition of new baking ingredients/components to the system. Examples are flour, eggs,
milk, chocolate, sugar, alcoholic spirits, fruits, nuts, etc. Anything that could be used to make a
baked good could be added as an ingredient/component.
o Name, textual description, and calories (as kcal per 100g/ml) are among key data to
store.
 Ability to create recipes for baked goods that associate ingredients/components with the baked
goods they feature in, and the quantities (in grams or millilitres as appropriate) to use therein.
Note that a given ingredient could be used in various baked goods but in different
amounts/quantities.
 Ability to edit/update/delete baked goods, recipes, and ingredients.
 Ability to search for baked goods (including recipes) and ingredients using some
parameters/options. The search might be: by name, by description keyword, etc. The key thing
is that a search facility is provided with some (minimum of 2) search options.
 Listings of search results (for both baked goods and ingredients) should be appropriately sorted
depending on the chosen search parameters/options. The sorting could be (1) alphabetical by
name or (2) by calories.
o Note that calories would have to be calculated for a baked good comprising various
ingredients of varying quantities and calories e.g. using 50g of dark chocolate when dark
chocolate has 500kcal per 100g => 250kcal is added to the total calories for the baked
good (and so on for all other ingredients in the baked good to arrive at the final calories
count).
o Other sorting options/parameters can also be provided, but alphabetical and calories
sorting are the key ones to implement.
 The system should support some level of interactive “drill down” for additional detail or
navigation/browsing.
o For instance, searching for baked goods containing chocolate should provide a list of any
chocolate-containing baked good. One baked good in the list could then be clicked on to
see more information specifically on that baked good; that detail could include a list of
ingredients in the baked good; clicking on any ingredient opens up details on the
ingredient, including a list of all baked good containing that ingredient; and so on.
1
 The system should support some form of persistence whereby the internal data is saved to a file
on exit, and reloaded for use on the next execution. You could use e.g. binary files, XML files,
plain text files, or anything else that provides an image/snapshot of all internal data.
o There is no need to look to databases or anything like that. A single snapshot/image file
is fine for our purposes.
在这里插入图片描述

import java.io.Serializable;

public class BakedFood implements Serializable {
    private String name;
    private String countryOfOrigin;
    private String description;
    private String imageURL;

    public BakedFood(String name, String countryOfOrigin, String description, String imageURL) {
        this.name = name;
        this.countryOfOrigin = countryOfOrigin;
        this.description = description;
        this.imageURL = imageURL;
        FileManager.foodList.add(this);
        FileManager.foodTable.put(name, this);
    }

    public String getName() {
        return name;
    }

    public String getCountryOfOrigin() {
        return countryOfOrigin;
    }

    public String getDescription() {
        return description;
    }

    public String getImageURL() {
        return imageURL;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setCountryOfOrigin(String countryOfOrigin) {
        this.countryOfOrigin = countryOfOrigin;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setImageURL(String imageURL) {
        this.imageURL = imageURL;
    }
}

import java.io.Serializable;

public class Ingredient implements Serializable {
    private String name;
    private String description;
    private double caloriesPer100g;

    public Ingredient(String name, String description, double caloriesPer100g) {
        this.name = name;
        this.description = description;
        this.caloriesPer100g = caloriesPer100g;
        FileManager.ingredientList.add(this);
        FileManager.ingredientSearchList.add(this);
        FileManager.ingredientTable.put(name, this);
    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public double getCaloriesPer100g() {
        return caloriesPer100g;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setCaloriesPer100g(double caloriesPer100g) {
        this.caloriesPer100g = caloriesPer100g;
    }

    @Override
    public String toString() {
        return "Ingredient{" +
                "name='" + name + '\'' +
                ", description='" + description + '\'' +
                ", caloriesPer100g=" + caloriesPer100g +
                '}';
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值