015-004-002
Recipe Ingredients
Easy
Problem Description
In this problem, you will create a program that defines an Ingredient base class with Meat and Vegetable subclasses, stores instances in an Ingredient[] array, iterates through them calling the polymorphic methods getType() and getAmount() on each, and displays the results to standard output.
Create an Ingredient base class with Meat and Vegetable subclasses. Store different ingredient types in an Ingredient[] array and iterate through them, calling the polymorphic methods getType() and getAmount() on each instance.
Test Cases
※ Output examples follow programming industry standards
Input:
{Meat(200), Vegetable(150), Meat(100)}Expected Output:
Ingredients: 3 Meat: 200g Vegetable: 150g Meat: 100g
Input:
{Vegetable(100), Vegetable(80)}Expected Output:
Ingredients: 3 Meat: 200g Vegetable: 150g Meat: 100g
Input:
{Meat(50)}Expected Output:
Ingredients: 3 Meat: 200g Vegetable: 150g Meat: 100g
Input:
Expected Output:
Ingredients: 3 Meat: 200g Vegetable: 150g Meat: 100g
❌ Some tests failed
Your Solution
Current Mode:● My Code
Ingredient.java🔒
Meat.java🔒
Vegetable.java🔒
Main.java🔒
4/6 ファイル112B
⚠️警告
- No main method found
9
1
2
›
⌄
class Ingredient {
}
0 B / 5 MB
You have 4 free executions remaining
