011-001-008
Constructor Definition: Book Class
Hard
Problem Description
constructor Definition: Book class
In this problem, you will create a program that defines a constructor for a Book class, initializes an object with book information (title, author, and price) read from standard input, and displays the information to standard output via a showInfo() method.
Learning Objective: Define constructors to initialize objects at creation time
Create a book class and initialize it with a constructor.
Input
Line 1: Book title (string)
Line 2: Author name (string)
Line 3: Price (integer)
Output
Book Info:
Title: [title]
Author: [author name]
Price: [price] yen
Specifications
- Create Book class
- Fields: String title, String author, int price
- Constructor: Book(String title, String author, int price)
- Method: showInfo() to display information
Examples
Example 1
Input:
Java Programming
John Smith
3500
Output:
Book Info:
Title: Java Programming
Author: John Smith
Price: 3500 yen
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