LinkedList中从一个类到另一个类的特定元素

时间:2017-05-08 06:48:27

标签: java linked-list

我有这个包含所有这些成分的当前课程,我试图将其添加到另一个链接列表中,但我正在努力。

import java.util.*;
public class Kitchen {
    public static final Category CRUST = new Category("crust", 1, 1);
    public static final Category SAUCE = new Category("sauce", 1, 1);
    public static final Category TOPPING = new Category("topping", 2, 3);
    private Category[] categories = { CRUST, SAUCE, TOPPING };
    private LinkedList<Ingredient> ingredients = new LinkedList<Ingredient>();

    public Kitchen() {
        ingredients.add (new Ingredient("Thin", 3.00, CRUST));
        ingredients.add (new Ingredient("Thick", 3.50, CRUST));
        ingredients.add (new Ingredient("Tomato", 1.00, SAUCE));
        ingredients.add (new Ingredient("Barbeque", 1.00, SAUCE));
        ingredients.add (new Ingredient("Capsicum", 0.50, TOPPING));
        ingredients.add (new Ingredient("Olives", 1.50, TOPPING));
        ingredients.add (new Ingredient("Jalapenos", 1.00, TOPPING));
        ingredients.add (new Ingredient("Beef", 2.75, TOPPING));
        ingredients.add (new Ingredient("Pepperoni", 2.50, TOPPING));
    }

这是包含所有成分的类,这是我试图复制一些成分的类。

import java.util.*;
import java.text.*;

public class Pizza {
    private LinkedList<Ingredient> ingredients = new LinkedList<Ingredient>();
    private int sold;

    public void add(){  
        ...
        ...
            if (...);
                ingredients.add(...);
        ...
    }

我应该如何将来自Kitchen的SPECIFIC成分添加到Pizza中的成分中(不仅仅是克隆整个东西:))?我尝试过添加配料本身,但这似乎不起作用。 (inredients.add(成分))

0 个答案:

没有答案