-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP8_Book.java
66 lines (61 loc) · 1.92 KB
/
P8_Book.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
import java.util.*;
class BookDetails{
String title;
int id;
float UnitPrice,TotalPrice;
int Quantity;
int i;
Scanner sc = new Scanner(System.in);
int ReadNumber(){
int a;
System.out.print("Number Of Books : ");
a = sc.nextInt();
return a;
}
int n = ReadNumber();
BookDetails B[] = new BookDetails[n];
void Read(){
for(i = 0;i<n;i++){
B[i] = new BookDetails();
System.out.print("Title : ");
B[i].title = sc.next();
System.out.print("Book ID : ");
B[i].id = sc.nextInt();
System.out.print("Unit Price : ");
B[i].UnitPrice = sc.nextFloat();
System.out.print("Quantity : ");
B[i].Quantity = sc.nextInt();
}
}
void TotPrice(){
TotalPrice = UnitPrice* Quantity;
}
void Display(){
for(i= 0;i<n;i++){
B[i].TotPrice();
System.out.println("\n| "+B[i].title+"|\t"+B[i].id+"|\t"+B[i].UnitPrice+"|\t"+B[i].Quantity+"|\t"+B[i].TotalPrice+"|");
}
}
}
public class Book{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BookDetails book = new BookDetails();
int ch;
book.ReadNumber();
System.out.println("---------------| BOOK DETAILS |-------------");
do{
System.out.println("Enter \n1.Read\n2.Display\n3.Exit\n");
System.out.print("Your Choice : ");
ch = sc.nextInt();
switch(ch)
{
case 1 : book.Read();break;
case 2 : System.out.print("| Title\t|\tID\t|\tUnit Price\t|\tQuantity\t|\tTotalPrice|"); book.Display();break;
case 3 : System.out.print("THANK YOOOUUUUUU");break;
default : System.out.print("Invalid Choice..");break;
}
}while(ch != 3);
sc.close();
}
}