011-003-002
Constructor Chain: Product Information
Easy
Problem Description
constructor Chain: Product Information
Learning Objective: Initialize progressively with this()
In this problem, you will create a program that reads a product name, uses constructor chaining with this() to progressively initialize default values for price (0 yen) and category (Unclassified), and displays the result to standard output.
Define three constructors in a Product class: a 1-parameter constructor that calls this(name, 0) to chain to the 2-parameter constructor, and a 2-parameter constructor that calls this(name, price, "Unclassified") to chain to the 3-parameter constructor, which ultimately initializes all fields (product name, price, and category).
Input
Line 1: Product name (string)
Output
Product: [name]
Price: 0 yen
Category: Unclassified
Test Cases
※ Output examples follow programming industry standards
Input:
Apple
Expected Output:
Product: Apple Price: 0 yen Category: Unclassified
Input:
Banana
Expected Output:
Product: Banana Price: 0 yen Category: Unclassified
Input:
A
Expected Output:
Product: A Price: 0 yen Category: Unclassified
Input:
Phone
Expected Output:
Product: Phone Price: 0 yen Category: Unclassified
❌ Some tests failed
Your Solution
Current Mode:● My Code
Product.java🔒
Solution.java🔒
2/6 ファイル96B
⚠️警告
- No main method found
9
1
2
3
4
›
⌄
import java.util.Scanner;
class Product {
}
0 B / 5 MB
You have 8 free executions remaining
