-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDAO_Main.java
More file actions
99 lines (90 loc) · 2.79 KB
/
Copy pathDAO_Main.java
File metadata and controls
99 lines (90 loc) · 2.79 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
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
92
93
94
95
96
97
98
99
import java.sql.*;
import java.util.Scanner;
public class DAO_Main {
public static void main(String[] args)
{
try
{
DAO_Factory daoFactory = new DAO_Factory();
daoFactory.activateConnection();
Scanner sc = new Scanner(System.in);
while(true)
{
System.out.print("1) Add books to database.\n2) Add members to database.\n3) Exit.\nSelect an option: ");
int option = sc.nextInt();
if(option==1)
{
System.out.print("Enter the number of books to add: ");
int num = sc.nextInt();
BookDAO bdao = daoFactory.getBookDAO();
for(int i=0;i<num;i++)
{
System.out.print("Book Id: ");
int bid = sc.nextInt();
System.out.print("Book Name: ");
sc.nextLine();
String name = sc.nextLine();
System.out.print("Author: ");
String author = sc.nextLine();
System.out.print("Publisher: ");
String publisher = sc.nextLine();
System.out.print("Book Price: ");
float price = sc.nextFloat();
System.out.print("Edition: ");
sc.nextLine();
String edition = sc.nextLine();
System.out.print("Total Book Count: ");
int totalcount = sc.nextInt();
//Book b = new Book(123456, "Fundamentals of Database Systems", "Ramez Elmasri", "Pearson", (float)171.84, "7th Edition", 24);
Book b = new Book(bid, name, author, publisher, price, edition, totalcount);
bdao.addBook(b);
b = bdao.getBookById(b.getId());
BookCopyDAO bcdao = daoFactory.getBookCopyDAO();
bcdao.addBookCopy(b);
}
}
else if(option==2)
{
System.out.print("Enter the number of members to add: ");
int num = sc.nextInt();
MemberDAO mdao = daoFactory.getMemberDAO();
for(int i=0;i<num;i++)
{
System.out.print("Member Id: ");
int mid = sc.nextInt();
System.out.print("First Name: ");
String fname = sc.next();
System.out.print("Middle Name: ");
char minit = sc.next().charAt(0);
System.out.print("Last Name: ");
String lname = sc.next();
System.out.print("Member Type: ");
String memberType = sc.next();
System.out.print("Address: ");
sc.nextLine();
String addr = sc.nextLine();
System.out.print("Pnone Number: ");
String phoneno = sc.nextLine();
//mdao.addMember(new Member(987123, "Nikhil", 'S', "Sairam", "Student", "Electronics City", "9876543210", 0, 3));
Member m = new Member(mid, fname, minit, lname, memberType, addr, phoneno);
m.setMaxIssuedCount();
mdao.addMember(m);
}
}
else if(option==3)
{
break;
}
else
{
System.out.println("Invalid input.");
}
}
daoFactory.deactivateConnection();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}