-
Notifications
You must be signed in to change notification settings - Fork 331
/
Publisher_details.java
91 lines (84 loc) · 2.46 KB
/
Publisher_details.java
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import java.util.Scanner;
class Publisher{
String publisher;
Publisher(String det){
this.publisher=det;
}
}
class Book extends Publisher{
String book;
Book(String det,String tex){
super(det);
book=tex;
}
}
class Literature extends Book{
String category;
Literature(String det, String tex){
super(det, tex);
}
void display(){
System.out.println("Publisher :"+publisher);
System.out.println("Book :"+book);
}
}
class Fiction extends Book{
Fiction(String det, String tex){
super(det, tex);
}
void display(){
System.out.println("Publisher :"+publisher);
System.out.println("Book :"+book);
}
}
public class bookDetails{
public static void main(String[] args) {
System.out.print("\nEnter the No. of Literature Books : ");
Scanner sc1 = new Scanner(System.in);
int num = sc1.nextInt();
Literature arr[]=new Literature[num];
System.out.println("\n Enter the Literature Book Details\n");
int x = 0,j=0;
Scanner sc =new Scanner(System.in);
for(int i =0;i<num;i++)
{
x = i +1;
System.out.println("\n"+x+").");
System.out.print("\n Book : ");
String tex =sc.next();
System.out.print("\n Publisher: ");
String det =sc.next();
arr[i]=new Literature(tex,det);
}
System.out.print("\nEnter the No. of Fiction Books : ");
int num1 = sc1.nextInt();
Fiction arr1[]=new Fiction[num1];
System.out.print("\n Enter the Fiction Book Details : \n");
int x1 = 0,j1=0;
for(int i =0;i<num1;i++)
{
x1 = i +1;
System.out.println("\n"+x1+").");
System.out.print("\n Book : ");
String tex =sc.next();
System.out.print("\n Publisher: ");
String det =sc.next();
arr1[i]=new Fiction(tex,det);
}
sc.close();
sc1.close();
System.out.println("\n---Informations of all the Literature Books---");
for(int i=0;i<num;i++){
j=i+1;
System.out.println("\n"+j+").");
arr[i].display();
}
System.out.println("\n---Informations of all the Fiction Books---");
for(int i=0;i<num1;i++){
j1=i+1;
System.out.println("\n"+j1+").");
arr1[i].display();
}
sc1.close();
}
}