015-003-002

Setter Method: Product Class

Easy

Problem Description

Setter method: Product class

In this problem, you will create a program that modifies private fields (name and price) of a Product class through setter methods, and displays the product information before and after the change to standard output.

Learning Objective: Understand how to safely modify private fields using setter methods

Create a Product class and learn to modify fields through setter methods. Setters can also perform validation.

Input

Line 1: Product name (string)
Line 2: Initial price (integer)
Line 3: New price (integer)

Output

Before: [product name] - [initial price] yen
After: [product name] - [new price] yen

Test Cases

※ Output examples follow programming industry standards

Normal case
Input:
Laptop
100000
90000
Expected Output:
Before: Laptop - 100000 yen
After: Laptop - 90000 yen
Boundary case
Input:
Book
1500
0
Expected Output:
Before: Book - 1500 yen
After: Book - 0 yen

Your Solution

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

class Product {
}
0 B / 5 MB

You have 10 free executions remaining