-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
44 lines (36 loc) · 1.32 KB
/
Book.java
File metadata and controls
44 lines (36 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.*;
public class Book {
String title;
String author;
float price;
Book() {
this("The Forest of Enchantments", "Chitra Banerjee Divakaruni", 36900f);
}
Book(String title, String author, float price) {
this.title = title;
this.author = author;
this.price = price;
}
Book(String title, String author) {
this(title, author, 0.0f);
System.out.println("Title: " + this.title);
System.out.println("Author: " + this.author);
System.out.println("Price: " + this.price);
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter title of Book: ");
String title = sc.nextLine();
System.out.print("Enter author of Book: ");
String author = sc.nextLine();
System.out.print("Enter the price of the book: ");
float price = sc.nextFloat();
sc.close();
System.out.println("Details of Book with 1st Parameterized constructor:");
Book book1 = new Book(title, author);
System.out.println("Details of Book with 2nd Parameterized constructor:");
Book book2 = new Book(title, author, price);
System.out.println("Details of Book with default constructor:");
Book book3 = new Book();
}
}