-
Notifications
You must be signed in to change notification settings - Fork 2
/
readme.txt
55 lines (32 loc) · 2.36 KB
/
readme.txt
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
In today's workshop we worked with a simple problem, which looked like:
We need to build a "Digital Phonebook" using Java. It should be a console application. No GUI needed. What we need is to insert new phone-book entries containing a person's Name, Email-ID, Contact number & Address. We will also like to update any entry and delete, show a list of entries, search, etc...
Our approach to solve the problem:
Let's think something like MVC (Model-View-Controller) architecture for beginners. We may assume following simplified concepts:
Model: A class containing code related to (a) Database table(s), with necessary mechanism to build database query and execute them.
Controller: A class which accepts user provided query, decides what to do, which model & view class to load...
View: A class which renders output and presents it to user.
User Interface:
Our solution has a command-line interface. You should write "insert" and hit enter, then type all the information (separated by spaces) required to insert a new entry in a single line. say, if I run the program and type in console:
insert
Shafiul 01557420420 [email protected] Dhaka
Then a new phone-book entry with following information will be stored in Database:
Name: Shafiul
Contact number: 01557420420
Email: [email protected]
Address: Dhaka
The program will run in an infinite loop until user types "quit" and hits enter. For update, you may type "update" and hit enter, and in the following line specify which entry to update with what etc.
Download:
Here you’ll find the code written using Netbeans. If you’re using Netbeans, you may simply “Open” a project and specify the folder of the downloaded code.
The code assumes you’ve a database named “digital_phonebook” with a table named “phonebook” - create a database named "digital_phonebook". Then, you can execute following SQL to create the table:
--
-- Table structure for table `phonebook`
--
CREATE TABLE IF NOT EXISTS `phonebook` (
`name` varchar(100) NOT NULL,
`contact` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`address` varchar(100) NOT NULL
) ;
The code has comments enough to increase understandability. This solution does nothing but shows how to write managable code from the very beginning, before a projct grows large enough to maintain. :)
Take care,
Shafiul Azam