011-002-004

Constructor Call: Product Class

Medium

Problem Description

constructor Call: Product class

In this problem, you will create a program that defines a Product class with a constructor, initializes an object with a product name and price, and displays the result to standard output.

Learning Objective

Learn how to call constructors to initialize objects.

Problem

Create a Product class with name and price, initialize via constructor.

Input

Line 1: Product name (string)
Line 2: Price (integer)

Output

Product: [name]
Price: [price]

Test Cases

※ Output examples follow programming industry standards

Input:
Apple
150
Expected Output:
Product: Apple
Price: 150
Input:
Bread
200
Expected Output:
Product: Bread
Price: 200
Input:
Banana
200
Expected Output:
Product: Banana
Price: 200
Input:
Milk
0
Expected Output:
Product: Milk
Price: 0
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
Product.java🔒
Main.java🔒
2/6 ファイル92B
⚠️警告
  • No main method found
import java.util.Scanner;

class Product {
}
0 B / 5 MB

You have 7 free executions remaining