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 +
                '}';
    }
}

The following is the data that you can add to your input file (as an example). Notice that the first line is going to be a line representing your own hobbies. In my case, it is the Vitaly,table tennis,chess,hacking line. Your goal is to create a class called Student. Every Student will contain a name (String) and an ArrayList<String> storing hobbies. Then, you will add all those students from the file into an ArrayList<Student>, with each Student having a separate name and ArrayList of hobbies. Here is an example file containing students (the first line will always represent yourself). NOTE: eventually, we will have a different file containing all our real names and hobbies so that we could find out with how many people each of us share the same hobby. Vitaly,table tennis,chess,hacking Sean,cooking,guitar,rainbow six Nolan,gym,piano,reading,video games Jack,cooking,swimming,music Ray,piano,video games,volleyball Emily,crochet,drawing,gardening,tuba,violin Hudson,anime,video games,trumpet Matt,piano,Reading,video games,traveling Alex,swimming,video games,saxophone Roman,piano,dancing,art Teddy,chess,lifting,swimming Sarah,baking,reading,singing,theatre Maya,violin,knitting,reading,billiards Amy,art,gaming,guitar,table tennis Daniel,video games,tennis,soccer,biking,trumpet Derek,cooking,flute,gaming,swimming,table tennis Daisey,video games,guitar,cleaning,drawing,animated shows,reading,shopping Lily,flute,ocarina,video games,baking Stella,roller skating,sudoku,watching baseball,harp Sophie,viola,ukulele,piano,video games Step 2. Sort the student list in the ascending order of student names and print them all on the screen After reading the file and storing the data in an ArrayList<Student>, your program should sort the ArrayList<Student> in alphabetical order based on their names and then print the students' data (please see an example below). As you can see, here is the list of all students printed in alphabetical order based on their names and hobbies. You are not going to have yourself printed in this list (as you can see, this list does not have Vitaly). Alex: [swimming, video games, saxophone] Amy: [art, gaming, guitar] Daisey: [video games, guitar, cleaning, drawing, animated shows, reading, shopping] Daniel: [video games, tennis, soccer, biking, trumpet] Derek: [cooking, flute, gaming, swimming] Emily: [crochet, drawing, gardening, tuba, violin] Hudson: [anime, video games, trumpet] Jack: [cooking, swimming, music] Lily: [flute, ocarina, video games, baking] Matt: [piano, Reading, video games, traveling] Maya: [violin, knitting, reading, billiards] Nolan: [gym, piano, reading, video games] Ray: [piano, video games, volleyball] Roman: [piano, dancing, art] Sarah: [baking, reading, singing, theatre] Sean: [cooking, guitar, rainbow six] Sophie: [viola, ukulele, piano, video games] Stella: [roller skating, sudoku, watching baseball, harp] Teddy: [chess, lifting, swimming] Step 3. Find all students who share the same hobby with you and print them all on the screen Finally, your program should print the information related to the students who share the same hobby as you. In my case, it would be the following based on the above-mentioned file. There are 0 students sharing the same hobby called "hacking" with me. There are 1 students (Teddy) sharing the same hobby called "chess" with me. There are 2 students (Amy, Derek) sharing the same hobby called "table tennis" with me.
06-10
The following is the data that you can add to your input file (as an example). Notice that the first line is going to be a line representing your own hobbies. In my case, it is the Vitaly,table tennis,chess,hacking line. Your goal is to create a class called Student. Every Student will contain a name (String) and an ArrayList<String> storing hobbies. Then, you will add all those students from the file into an ArrayList<Student>, with each Student having a separate name and ArrayList of hobbies. Here is an example file containing students (the first line will always represent yourself). NOTE: eventually, we will have a different file containing all our real names and hobbies so that we could find out with how many people each of us share the same hobby. Vitaly,table tennis,chess,hacking Sean,cooking,guitar,rainbow six Nolan,gym,piano,reading,video games Jack,cooking,swimming,music Ray,piano,video games,volleyball Emily,crochet,drawing,gardening,tuba,violin Hudson,anime,video games,trumpet Matt,piano,Reading,video games,traveling Alex,swimming,video games,saxophone Roman,piano,dancing,art Teddy,chess,lifting,swimming Sarah,baking,reading,singing,theatre Maya,violin,knitting,reading,billiards Amy,art,gaming,guitar,table tennis Daniel,video games,tennis,soccer,biking,trumpet Derek,cooking,flute,gaming,swimming,table tennis Daisey,video games,guitar,cleaning,drawing,animated shows,reading,shopping Lily,flute,ocarina,video games,baking Stella,roller skating,sudoku,watching baseball,harp Sophie,viola,ukulele,piano,video games
06-10
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值