Create a class named 'Book' with a title, author, and number of pages, and provide methods to set and get these data. Next, in your main function, create a new 'Book' instance and set the title and author as inputted from user input and set the number of pages to 100. Finally, print the book details in the following format: 'Title:
Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingClasses and objectsClasses and members
Defining classes
Creating a book class and displaying book details
Report a typo
Sample Input 1:
To Kill a Mockingbird
Harper LeeSample Output 1:
Title: To Kill a Mockingbird, Author: Harper Lee, Pages: 100Sample Input 2:
1984
George OrwellSample Output 2:
Title: 1984, Author: George Orwell, Pages: 100Write a program in Java 25
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String title = sc.nextLine();
String author = sc.nextLine();
Book book = new Book();
// Set the details of the book
// Implement here
// Print the details of the book
// Implement here
}
}
class Book {
private String title;
private String author;
private int pages;
// Getters and setters
// Implement here
}
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.