018-002-002
Inheritance Basics: Recipe Extension
Easy
Problem Description
inheritance Basics: Recipe Extension
Learning Objective: Add fields to parent class with inheritance and extend functionality
In this problem, you will create a program that implements a Recipe parent class and a SpecialRecipe child class, where each class's getTypeName() method returns "Regular recipe" or "Special recipe" and displays the result to standard output.
Create SpecialRecipe class inheriting from Recipe class. Learn how to add child class unique fields in addition to parent class functionality.
Understanding with Concrete Examples
Example 1: Regular Recipe (Parent Class)
Input: new Recipe("Pasta", 15)
Output: Regular recipe
Example 2: Special Recipe (Child Class)
Input: new SpecialRecipe("Truffle Pasta", 15, "Truffle")
Output: Special recipe
(Explanation: Special pasta using truffle)
Example 3: Special Even if Quick (Boundary)
Input: new SpecialRecipe("Caviar Pasta", 10, "Caviar")
Output: Special recipe
(Explanation: Special recipe with caviar even in 10 minutes)
Requirements
Create Recipe and SpecialRecipe classes with following specifications:
Recipe Class (Parent)
- Fields:
dishName(String type, protected): Dish namecookingTime(int type, protected): Cooking time
- constructor: Receive dishName, cookingTime
- Method:
getTypeName()- Return "Regular recipe"
SpecialRecipe Class (Child)
- Inheritance: Inherit from Recipe class
- Additional Field:
specialIngredient(String type, private): Special ingredient - Constructor: Receive dishName, cookingTime, specialIngredient, initialize parent with super(), set specialIngredient
- Method:
getTypeName()- Return "Special recipe" (override).
Test Cases
※ Output examples follow programming industry standards
Input:
{"recipeType":"Recipe","dishName":"Pasta","cookingTime":15}Expected Output:
Dish: Pasta Time: 15 min === Special Recipe === Dish: Truffle Pasta Time: 30 min Special Ingredient: Black Truffle Difficulty: 4/5
Input:
{"recipeType":"SpecialRecipe","dishName":"Truffle Pasta","cookingTime":15,"specialIngredient":"Truffle"}Expected Output:
Dish: Pasta Time: 15 min === Special Recipe === Dish: Truffle Pasta Time: 30 min Special Ingredient: Black Truffle Difficulty: 4/5
Input:
{"recipeType":"SpecialRecipe","dishName":"Caviar Pasta","cookingTime":10,"specialIngredient":"Caviar"}Expected Output:
Dish: Pasta Time: 15 min === Special Recipe === Dish: Truffle Pasta Time: 30 min Special Ingredient: Black Truffle Difficulty: 4/5
Input:
{"recipeType":"Recipe","dishName":"Salad","cookingTime":5}Expected Output:
Dish: Pasta Time: 15 min === Special Recipe === Dish: Truffle Pasta Time: 30 min Special Ingredient: Black Truffle Difficulty: 4/5
❌ Some tests failed
Your Solution
Current Mode:● My Code
Recipe.java🔒
SpecialRecipe.java🔒
Main.java🔒
3/6 ファイル75B
⚠️警告
- No main method found
9
1
2
›
⌄
class Recipe {
}
0 B / 5 MB
You have 5 free executions remaining
