Download Object Oriented Programming and more High school final essays Computer science in PDF only on Docsity! Acknowledgement I would like to thank my parents and friends who supported to complete this project within the allocated time. I would also like to thank Mr. Asanka Dinesh our lecturers for giving us their support to complete the project successfully. This assignment helped me to get a good knowledge about object oriented programming and C# language. Designing a system using object oriented programming concepts was a good experience for me. Shashin Nishad Object Oriented Programming Using Net Page 1 Table of Contents 1 Task 01......................................................................................................................11 1.1 Executive Summary...........................................................................................11 1.2 Characteristic and principles of object oriented programming (OOP) and reasons for the selection of OOP concepts to develop the system...........................12 1.2.1 Abstraction..................................................................................................12 1.2.2 Polymorphism.............................................................................................13 1.2.3 Inheritance...................................................................................................15 1.2.4 Encapsulation..............................................................................................17 1.3 Why OOP for this system?.................................................................................19 2 Task 2........................................................................................................................20 2.1 Identify the classes from the scenario and list all the attributes and methods of each class you have identified using UML notation................................................20 2.1.1 Class Abstraction.........................................................................................20 2.1.2 Identified classes from the scenario............................................................21 2.1.3 Classes of Sarasavi Library Management System......................................24 3 Task 03......................................................................................................................26 3.1 Use Case Diagram..............................................................................................26 3.2 Sequence Diagram..............................................................................................27 3.3 ER diagram.........................................................................................................28 ..................................................................................................................................28 ..................................................................................................................................28 3.4 Class Diagram....................................................................................................29 4 Task 04......................................................................................................................33 4.1 Implementation...................................................................................................33 4.1.1 Login Page...................................................................................................33 4.1.2 Change the password Page..........................................................................35 Shashin Nishad Object Oriented Programming Using Net Page 2 Table 4- Test Case 3....................................................................................................81 Table 5- Test Case 4....................................................................................................86 Table 6- Test Case 5....................................................................................................95 Table 7- Test Case 6....................................................................................................98 Table 8- Test Case 7..................................................................................................101 Table 9- Test Case 8..................................................................................................103 Table Of Figures Figure 1- Use Case Diagram.......................................................................................26 Figure 2 - Sequence Diagram......................................................................................27 Figure 3- ER diagram..................................................................................................28 Figure 4- Class Diagram..............................................................................................29 Figure 5 - Association..................................................................................................30 Figure 6- Composition.................................................................................................31 Figure 7- Generalization...............................................................................................32 Figure 8.......................................................................................................................33 Figure 9.......................................................................................................................34 Figure 10.....................................................................................................................35 Figure 11.....................................................................................................................36 Figure 12.....................................................................................................................37 Figure 13.....................................................................................................................38 Figure 14.....................................................................................................................39 Shashin Nishad Object Oriented Programming Using Net Page 5 Figure 15.....................................................................................................................40 Figure 16.....................................................................................................................41 Figure 17.....................................................................................................................42 Figure 18.....................................................................................................................43 Figure 19.....................................................................................................................44 Figure 20.....................................................................................................................45 Figure 21.....................................................................................................................46 Figure 22.....................................................................................................................47 Figure 23.....................................................................................................................48 Figure 24.....................................................................................................................48 Figure 25.....................................................................................................................49 Figure 26.....................................................................................................................49 Figure 27.....................................................................................................................50 Figure 28.....................................................................................................................50 Figure 29.....................................................................................................................50 Figure 30.....................................................................................................................51 Figure 31.....................................................................................................................51 Figure 32.....................................................................................................................51 Figure 33.....................................................................................................................52 Figure 34.....................................................................................................................52 Figure 35.....................................................................................................................53 Figure 36.....................................................................................................................54 Figure 37.....................................................................................................................55 Shashin Nishad Object Oriented Programming Using Net Page 6 Figure 38.....................................................................................................................55 Figure 39.....................................................................................................................56 Figure 40.....................................................................................................................57 Figure 41.....................................................................................................................58 Figure 42.....................................................................................................................59 Figure 43.....................................................................................................................60 Figure 44.....................................................................................................................61 Figure 45- Login Form................................................................................................62 Figure 46- User Registration Tab................................................................................62 Figure 47- Book Registration Tab...............................................................................63 Figure 48- Book Issue Tab..........................................................................................63 Figure 49- Return Book Tab.......................................................................................64 Figure 50- Inquiries Tab..............................................................................................64 Figure 51 -Help Tab....................................................................................................65 Figure 52.....................................................................................................................66 Figure 53.....................................................................................................................67 Figure 54.....................................................................................................................68 Figure 55.....................................................................................................................68 Figure 56.....................................................................................................................69 Figure 57.....................................................................................................................69 Figure 58......................................................................................................................72 Figure 59......................................................................................................................73 Figure 60.....................................................................................................................73 Shashin Nishad Object Oriented Programming Using Net Page 7 Figure 107..................................................................................................................109 Figure 108..................................................................................................................110 Figure 109.................................................................................................................111 Figure 110- Feedback Form......................................................................................114 Figure 111- Feedback Form......................................................................................115 Figure 112.................................................................................................................120 Figure 113.................................................................................................................121 Figure 114.................................................................................................................121 Figure 115.................................................................................................................125 Figure 116.................................................................................................................125 Figure 117.................................................................................................................126 Figure 118.................................................................................................................127 Figure 119.................................................................................................................128 Figure 120.................................................................................................................129 Figure 121.................................................................................................................130 Figure 122.................................................................................................................130 Figure 123.................................................................................................................131 Figure 124- Filled Feedback Form.............................................................................135 Figure 125- Filled Feedback Form.............................................................................136 Figure 126- Question Form........................................................................................137 Figure 127- Question Form........................................................................................138 Shashin Nishad Object Oriented Programming Using Net Page 10 1 Task 01 1.1 Executive Summary Sarasavi is a popular fully stocked library with a collection of nearly 500 books. These books are available for loan as well as for reference by “Registered Members”, for free of charge. However, “Registered Visitors” cannot borrow any book instead they can only refer a book. The functions of the Sarasavi library are, Loan Process, Return Process, Reservation process, Inquiry Process, Book Registration Process and User Registration process. Currently they are planning to expand their services by introducing an automated system to manage their daily processes. Best Solutions Developers have been invited by the Sarasavi Library to fulfill the task of creating a suitable computerized system to make their needs easy. This contains all the details about the proposed solution and its features. Requirements Identified Managing the heavy load of paperwork Manually searching available books Inappropriate data storing methods Vague books and users registry Solution evaluated for Sarasavi Library Shashin Nishad Object Oriented Programming Using Net Page 11 A simple library management system developed using C#.NET language will be implemented to support the needs of the library. This computerized system will help to register users, register books, issue books, return books and search available books easily. 1.2 Characteristic and principles of object oriented programming (OOP) and reasons for the selection of OOP concepts to develop the system Programming languages such as C does not support Object Oriented Programming (OOP). C# is an OOP language. Reusability is a key aspect of OOP. There are different concepts related to object orientation. OOP is mainly based on objects. An object is referred as an instance of a class. It consists of attributes and behaviors/methods. Abstraction, encapsulation, inheritance and polymorphism are pillar concepts of OOP. 1.2.1 Abstraction “Data Abstraction is the act of representing the essential feature without including the background detail” (Ashu Kumar, 2004, p.6). In this process only the relevant data of an object is chosen while the irrelevant characteristics are removed to reduce complexity and increase efficiency (Rouse, 2013). Abstraction is important when creating flexible and reliable systems. Before designing the system abstraction will be followed. Real Life Example Have you ever thought about the snaps u take or the moment you capture with your camera? If you have ever thought then that is what data abstraction is all about, you snap you smile but you never know how light passes through the camera and how the optics is converted into digital media. (Ashu Kumar, 2004) Shashin Nishad Object Oriented Programming Using Net Page 12 Printing string: Hi C++ 1.2.3 Inheritance “Inheritance is a process of inheriting (linking) the data from one class to another class instead of creating it again.” (Ashu Kumar, 2004, p.8) Existing class is called as the super class or parent class and the new class is known as subclass. The variables and methods of the parent class can be reused in the sub class. This method can be used in the system when developing the program. It helps to minimize the code which needs to be written. Real Life Example The children inheriting their parents’ genes and grow according to their parents’ genes and their own properties which they learn throughout their growth. (Ashu Kumar, 2004) Code Example Consider a base class Shape and its derived class Square: using System; namespace Inheritance { class Shape { public void setWidth(int w) { width = w; } Shashin Nishad Object Oriented Programming Using Net Page 15 public void setHeight(int h) { height = h; } protected int width; protected int height; } // Derived class class Square: Shape { public int getArea() { return (width * height); } } class SquareTester { static void Main(string[] args) { Square Squ = new Square(); Squ.setWidth(10); Squ.setHeight(10); // Print the area of the object. Console.WriteLine("Total area: {0}", Squ.getArea()); Console.ReadKey(); } } } Shashin Nishad Object Oriented Programming Using Net Page 16 When the above code is compiled and executed, it produces the following result: Total area: 100 1.2.4 Encapsulation “Wrapping up of data and function into a single unit is called as Data Encapsulation.” (Ashu Kumar, 2004, p.9) This concept is also known as data hiding. The ability of the object to hide its data from the code that is outside the object is called data hiding (Gaddis, 2011). By this method data can be protected without being corrupted. Real Life Example The cement and sand are bind with its function to support the building taking the form of a pillar. (Ashu Kumar, 2004) Code Example using System; namespace Encapsulation { class Square { private double length; //member variables private double width; public void Acceptdetails() { Console.WriteLine("Enter Length: "); length = Convert.ToDouble(Console.ReadLine()); Shashin Nishad Object Oriented Programming Using Net Page 17 2 Task 2 2.1 Identify the classes from the scenario and list all the attributes and methods of each class you have identified using UML notation. 2.1.1 Class Abstraction Before designing the class diagram all the candidate classes were listed in order to select the eligible abstract classes for the diagram. The list of candidate classes- Member Visitor Books User Loans Reservation From the above list the selected classes were Member, user, visitor, books and loans. Member class represents all the details of Registered members therefore it was selected. User class represents user details and its methods. Visitor class represents all the details of Registered visitors therefore it was selected. Loan class is for storing all the details of loans made by members/visitors. Since member and visitor classes had similar attributes and methods they were designed to be inherited from one class called ‘Person’. The ‘Person’ class acts as the parent class to the member and visitor classes and these classes will inherit all the attributes and methods of the ‘Person’ class. ‘Reservation’ class was not selected because the issue dates, return dates and loan details are already depicted by the ‘Loans’ class and there is no need of duplicating data. Shashin Nishad Object Oriented Programming Using Net Page 20 2.1.2 Identified classes from the scenario User User class represents all the attributes of a user and its behaviors. The attributes of this class are assigned with ‘private’ access modifier. username- This variable is used to store the username of a user. It has been declared with the ‘String’ data type. password- The password of a user is stored in this variable. ‘String’ data type has been used for this attribute. This class is used when a user logins to the system. This is done by the method login (). It checks whether user inputs the correct username and password and gives access to the system. With the method changePassword () a user can change his/her existing password. All the methods of this class are private and their return type is void. Member Member class represents all the attributes and behaviors of a Registered Member. All the attributes are assigned with ‘private’ access modifier. memberID- Represents member ID. It is used to identify each registered member uniquely. It has been declared with the ‘String’ data type. memberName- Represents the name of the member. ‘String’ data type has been used for this attribute. memberAddress- Represents the address of the member. Data type ‘String’ has been used for this attribute. memberGender- Represents the gender of the member. Data type ‘String’ has been used for this attribute. Shashin Nishad Object Oriented Programming Using Net Page 21 memberNIC- Represents the NIC number of the member. Data type ‘String’ has been used for this attribute. memberStatus- Represents the amount of books he/she has borrowed. Data type ‘int’ has been used for this attribute Visitor Visitor class represents all the attributes and behaviors of a Registered Visitor. All the attributes are assigned with ‘private’ access modifier. The attributes are: visitorID- Represents member ID. It is used to identify each registered visitor uniquely. It has been declared with the ‘String’ data type. visitorName- Represents the name of the visitor. ‘String’ data type has been used for this attribute. visitorAddress- Represents the address of the visitor. Data type ‘String’ has been used for this attribute. visitorGender- Represents the gender of the visitor. Data type ‘String’ has been used for this attribute. visitorNIC- Represents the NIC number of the visitor. Data type ‘String’ has been used for this attribute. visitorStatus- Represents the amount of books he/she is referring. Data type ‘int’ has been used for this attribute Shashin Nishad Object Oriented Programming Using Net Page 22 Shashin Nishad Object Oriented Programming Using Net Page 25 3 Task 03 3.1 Use Case Diagram Figure 1- Use Case Diagram Shashin Nishad Object Oriented Programming Using Net Page 26 3.2 Sequence Diagram Figure 2 - Sequence Diagram Shashin Nishad Object Oriented Programming Using Net Page 27 Association Association is a link which shows two classes are connected. The attributes and methods of each class are independent. Figure 5 - Association In the system developed for Sarasavi Library association has been used for the User class and Loans class. The relationship can be clearly seen in the above mentioned class diagram. It has a one-to-many relationship. Shashin Nishad Object Oriented Programming Using Net Page 30 Composition Composition is similar to aggregation. In composition the relationship is shown by a solid diamond. In a composition relationship the objects are named as the parent object and child object. The parent object should exist in order for the existence of the child object. Composition is used in the system for Member, Visitor, Books and Loans classes. Figure 6- Composition The Loans class exists because of the Person class or Books class because without a person or books there will not be a loan process. If person or books is Deleted loan has to be deleted too. In composition child object depends on parent object. Shashin Nishad Object Oriented Programming Using Net Page 31 Generalization Generalization is based on parent (base) class and child (derived) class. The attributes and methods of the base class can be extracted to the derived classes. Figure 7- Generalization Shashin Nishad Object Oriented Programming Using Net Page 32 4.1.2 Change the password Page Figure 10 Shashin Nishad Object Oriented Programming Using Net Page 35 Figure 11 Shashin Nishad Object Oriented Programming Using Net Page 36 4.1.3 Main Menu Page Figure 12 Shashin Nishad Object Oriented Programming Using Net Page 37 Figure 15 Shashin Nishad Object Oriented Programming Using Net Page 40 Figure 16 Shashin Nishad Object Oriented Programming Using Net Page 41 Figure 17 Shashin Nishad Object Oriented Programming Using Net Page 42 Figure 20 Shashin Nishad Object Oriented Programming Using Net Page 45 Figure 21 Shashin Nishad Object Oriented Programming Using Net Page 46 Figure 22 Shashin Nishad Object Oriented Programming Using Net Page 47 If a user accidently leaves the password field or username field empty the user will be asked to enter username or password. Figure 27 If a user leaves both password field and username field empty the user will be asked to enter username and password. Figure 28 If password or username is wrong the user will be asked to re-enter username and password Figure 29 Shashin Nishad Object Oriented Programming Using Net Page 50 If user moves the cursor over the specific Button or Text box, then tool tips will be displayed. Figure 30 Figure 31 User cannot enter more than 6 characters in Password Field. Figure 32 Shashin Nishad Object Oriented Programming Using Net Page 51 The main form consists of tabs. Each tab has a title. Figure 33 When the user submits a record and then Save Button will be displayed. Figure 34 Shashin Nishad Object Oriented Programming Using Net Page 52 Figure 37 Control structures are used when submitting data on the User Registration. For example when click Submit button without filling one or many or all fields then an error message will be displayed and if you click member radio button or visitor radio button and click submit button and then display a relevant ID number for each button you clicked. Figure 38 Shashin Nishad Object Oriented Programming Using Net Page 55 Control structures are used when submitting data on the Book Registration. For example when click Submit button without filling one or many or all fields then an error message will be displayed and if you click any item of the combo box and click submit button and then display a relevant ID number for each item you clicked. Figure 39 Shashin Nishad Object Oriented Programming Using Net Page 56 Control structures are used when saving data to the database. For example adding books details when Save button is clicked objects of the relevant class are created. Then using if else statements data has been passed to the database. Figure 40 Shashin Nishad Object Oriented Programming Using Net Page 57 Programs can be easily tested by the use of an IDE. With the debugger applications can be tested many times before releasing the end product to the market. This helps the developers in creating test cases and documenting them. The debugging tool also helps to identify logical errors. An IDE provides a compiler to translate the program code to machine language. It makes the job of a programmer very easy because the compiler translates the code to machine code within a short period of time. Therefore it saves time. IDEs allow the developers to develop user friendly programs. IDEs provide various options in the GUI builder. For example Visual Studio 2010 IDE provides a toolbox which includes controllers, menus and containers. The user interfaces can be made user friendly and attractive by using these options. For the creation of forms for the Sarasavi Library management System labels, textboxes, combo boxes, buttons, panels, tab control, data grid and menu items have been used. For example:- Figure 43 Shashin Nishad Object Oriented Programming Using Net Page 60 Figure 44 Shashin Nishad Object Oriented Programming Using Net Page 61 6.2 Windows forms of the Sarasavi Library Management System 6.2.1 Login Form Figure 45- Login Form 6.2.2 User Registration Tab Figure 46- User Registration Tab Shashin Nishad Object Oriented Programming Using Net Page 62 6.2.7 Help Tab Figure 51 -Help Tab Shashin Nishad Object Oriented Programming Using Net Page 65 This function continues the connection of database when dropped. Figure 52 Below function auto generate ID and it avoid mistakes of manually generating IDs. Shashin Nishad Object Oriented Programming Using Net Page 66 Figure 53 This command changes the status of loan and the User Shashin Nishad Object Oriented Programming Using Net Page 67 7 Task 07 and Task 08 7.1 Test Plan Sarasavi Library Management System 7.1.1 Introduction As soon as the creation of the system is completed it will be going through a testing process. Testing is done in order to make sure the system is built according to the correct design and to check whether user requirements are met. 7.1.2 Elements to be tested Login authentication Change Password User Registration Book Registration Issue Books Process Return Book Process Inquire Process Logout 7.1.3 Types of testing done Unit testing System testing User acceptance testing Black box testing White box testing Shashin Nishad Object Oriented Programming Using Net Page 70 7.1.4 Testing schedule Date Tested area Testing type 29.02.2016 Adding members, visitors and books User acceptance (Black box testing) 29.02.2016 Updating data Unit testing White box testing 29.02.2016 Login authentication User acceptance testing System testing Black box testing 29.02.2016 Viewing data User acceptance testing Black box testing Table 1- Testing Schedule 7.1.5 Hardware and software requirements To test the database a PC is used. It is connected to the main server. The PC is installed with Microsoft SQL Server 2014 and Visual Studio 2010. Testing is done by the developer and a librarian. 7.1.6 Testing approach The testing of the automated system and database are done according to different test cases. Test cases are generated according to the elements which are going to be tested. Shashin Nishad Object Oriented Programming Using Net Page 71 7.2 Test Cases Test no. Name of the test Type of test Date Duration Tester No. of test cases 1. Login authentication User acceptance (Black box testing) 29.02.2016 10 mins Librarian 6 Table 2- Test Case 1 Test case: 1.1 Inputs the correct username and password Expected output: The user gets access to the system. Actual output: Figure 58 Shashin Nishad Object Oriented Programming Using Net Page 72 Test case: 1.6 Inputs the correct password and leaves username field empty. Expected output: Display an error message and ask the user to input the username. Actual output: Figure 63 Shashin Nishad Object Oriented Programming Using Net Page 75 Test no. Name of the test Type of test Date Duration Tester No. of test cases 2. User Registration User acceptance (Black box testing) 29.02.2016 5 mins Librarian 4 Table 3- Test Case 2 Test case: 2.1 Inputs member details and click Submit button. Expected output: Save Button and User ID will be appeared. Actual output: Figure 64 Shashin Nishad Object Oriented Programming Using Net Page 76 Figure 65 Shashin Nishad Object Oriented Programming Using Net Page 77 Test case: 2.4 Save Visitor details to the database. Expected output: The user gets a message saying the data was saved. Actual output: Figure 69 Shashin Nishad Object Oriented Programming Using Net Page 80 Test no. Name of the test Type of test Date Duration Tester No. of test cases 3. Book Registration User acceptance (Black box testing) 29.02.2016 5 mins Librarian 4 Table 4- Test Case 3 Test case: 3.1 Inputs Book (Borrowable) details and click Submit button. Expected output: Save Button and Book ID will be appeared. Actual output: Figure 70 Shashin Nishad Object Oriented Programming Using Net Page 81 Figure 71 Shashin Nishad Object Oriented Programming Using Net Page 82 Test case: 3.4 Save Book details to the database. Expected output: The user gets a message saying the data was saved. Actual output: Figure 75 Shashin Nishad Object Oriented Programming Using Net Page 85 Test no. Name of the test Type of test Date Duration Tester No. of test cases 4. Books Issue Process User acceptance (Black box testing) 29.02.2016 10 mins Librarian 8 Table 5- Test Case 4 Test case: 4.1 Input details (Member ID, Book ID, whether is Borrowable) and click Submit button. Expected output: If the book is borrowable and if ‘Copies’ are not equal to ‘Issued’ and if ‘Status’ is less than 5 and then the Loan No, Member Name, Book Title, Issued Date, Return Date and Save Button will be appeared. Copies - No of copies for each book Issued - No of copies issued for now Status – The amount of books can be taken at a time (number of loans) Shashin Nishad Object Oriented Programming Using Net Page 86 Actual output: Figure 76 Figure 77 Shashin Nishad Object Oriented Programming Using Net Page 87 Input details (Member ID, Book ID, whether is Borrowable) and click Submit button. Expected output: If the book is borrowable and if ‘Copies’ = ‘Issued’ (Check availability) and then the error message will be displayed. Copies - No of copies for each book Issued - No of copies issued for now Actual output: Figure 81 Figure 82 Test case: 4.5 Shashin Nishad Object Oriented Programming Using Net Page 90 Input details (Member ID, Book ID, whether is Borrowable) and click Submit button. Expected output: If the book is a reference one and then an error message will be displayed. Actual output: Figure 83 Figure 84 Test case: 4.6 Shashin Nishad Object Oriented Programming Using Net Page 91 Input details (Member ID, Book ID, whether is Reference) and click Submit button. Expected output: Member name, Title, Issue Date, Return Date will be displayed. Actual output: Figure 85 Figure 86 Test case: 4.7 Shashin Nishad Object Oriented Programming Using Net Page 92 the test test test cases 5. Return Book Process User acceptance (Black box testing) 29.02.2016 10 mins Librarian 2 Table 6- Test Case 5 Test case: 5.1 Input a valid Loan No. and click Submit Button. Expected output: Book ID, Member ID and Save Button Will be displayed. Actual output: Figure 91 Shashin Nishad Object Oriented Programming Using Net Page 95 Figure 92 Shashin Nishad Object Oriented Programming Using Net Page 96 Test case: 5.2 Input an invalid Loan No. and click Submit Button Expected output: An error message will be displayed. Actual output: Figure 93 Shashin Nishad Object Oriented Programming Using Net Page 97