Class Basics: Product Information Class
Problem Description
class Basics: Product Information class
In this problem, you will create a program that defines a Product class with instance fields, a constructor, and a display method, reads product name and price from standard input, and prints the formatted product information to standard output.
Learning Objective: Understand basic class structure (fields, constructor, methods) and role of this keyword
Create a Product class to manage product information. Define name (String) and price (int) as instance fields, initialize them in a constructor using this to distinguish instance variables from parameters, and implement a method that prints the product details in the required format.
Input
Line 1: Product name (string)
Line 2: Price (integer)
Output
Product Information:
Name: [name]
Price: [price]yen
```java
**Key Point**: A class is a blueprint that combines "data (fields)" and "behavior (methods)" together. Use the `this` keyword to distinguish instance variables from constructor parameters.
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up