Вы находитесь на странице: 1из 25

INDIVIDUAL ASSIGNMENT

TECHNOLOGY PARK MALAYSIA

CT042-3-1-OODJ
OBJECT ORIENTED DEVELOPMENT WITH JAVA

UC2F1708IT(NC)

NAME: ABDURRAOUF FATHI ALI SAWEHLI


TP042816

HAND OUT DATE: 25th SEPTEMBER 2017

HAND IN DATE: 4th December 2017

WEIGHTAGE: 50%

INSTRUCTIONS TO CANDIDATES:

1 Submit your assignment at the administrative counter


2 Late submission will be awarded zero (0) unless Extenuating Circumstances (EC) are
upheld.
3 Cases of plagiarism will be penalized.
4 The assignment should be bound in an appropriate style (comb bound or stapled).

5 Where the assignment should be submitted in both hardcopy and softcopy, the
softcopy of the written assignment and source code (where appropriate) should be on
a CD in an envelope / CD cover and attached to the hardcopy.
6 You must obtain 50% overall to pass this module
Contents
1. Introduction:.......................................................................................................................................... 3
2. System Design: ......................................................................................................................................... 4
3. System Implementation: ........................................................................................................................... 8
4. Results and Assumptions: ....................................................................................................................... 14
5. Conclusion: ............................................................................................................................................. 24
7. References:.......................................................................................................................................... 25

2
1. Introduction:

Programming languages have become an essential skill for all people whether they are
specialized in IT or not. Hens, plenty of programming languages have been released over the time
and one of the most powerful programming language for all the time is java.

Java is a programming language and platform that was released in 1995 by Sun
Microsyste. Many application and websites will not be able to work in your hardware or software
environment where your program runs except you have installed Java on it. Moreover, Java is
considered as fast, secure and object-oriented programming language that widely used in Desktop
Applications, Web Applications, Enterprise Applications, Mobile, Embedded System, Smart Card,
Robotics and Games and according to Java introducer, 3 billion devices are running java in
nowadays. (javatpoint.com, 2017)

One type of java application is a Standalone Applications which is known as a desktop


application or windows-based application. In this assignment, a desktop application was required
to be implanted to accomplish java module. This application is basically for TRISYSLOGICS
SDN BHD (TSB) which is one of the wholesalers in Kuala Lumpur involved in selling of the daily
groceries, fresh produce and fresh foods to numerous retailers of Malaysia. As their business is
growing, an automated Order Management System is needed to maintain the work process
effectively. As a result, Java application which applies the OOP techniques needs to be developed
to achieve the following functionalities:

1. Login access
2. User Registration
3. Item Entry
4. Supplier Entry
5. Daily Item-wise Sales Entry
6. Create a Purchase Requisition (PR)
7. Display Requisition
8. Generate Purchase Order (PO)
9. List of Purchaser Orders.

3
2. System Design:
2.1 Activity Diagram:

4
5
2.2 Class Diagram:

6
2.2 Use Case Diagram:

7
3. System Implementation:

Object-oriented programming (OOP) is a programming style based on the concept of


objects that hold data which is known as attributes. Moreover, objects might have act code, which
is known as methods. Object's methods can access and alter the data of the object with which they
are related. In OOP, applications are developed by making them out of objects that collaborate
with each other. (Eckel, 2014).

Therefore, every class of my program describes some object, like User, Item, Supplier, etc
and only two classes are used for providing methods. They are Main.java and FileUtils.java. The
first one is used for interacting with a user with the help of Terminal. The second is used for writing
and reading information from files.

There are 4 principles of OOP which been applied in this assignment.

1. Class and Object:

Classes and objects are the basics of any OOP program. A java class can be described as a
template that defines the behavior that the object of its kind support or a collection of objects. An
object can be as Suppliers in our assignment (human) who have a state and behavior. If we consider
a Supplier, then its state is – name and ID, and the behavior is supply item, further, the object states
is stored in filed and the behavior is shown as methods.

Moreover, every class has a constructor as each time we create an object, the constructor will
be invoked to initialize it. The constructor must be same with the class name and the compiler will
build a default constructor for the class if we do not write it and classes can have more than one
constructor. Following is one example of applying the class concept.

8
public class Supplier {

private String code;


private String name;
private String itemID;

public Supplier(String code, String name, String itemID) {


this.code = code;
this.name = name;
this.itemID = itemID;
}

public String getCode() {


return code;
}

public void setCode(String code) {


this.code = code;
}

public boolean supplyItem(String itemID) {


return this.itemID.equals(itemID);
}

Here is an example of creating an object of Supplier class and data will be save in the Array List:

for (Supplier supplier : suppliers) {


if (supplier.getCode().equals(code)) {
return false;
}
}
suppliers.add(new Supplier(code, name, itemID));
return true;
}

2. Encapsulation:

Encapsulation is an instrument of covering the data (variables) and code acting on the data
(methods) together as one part and it is known also as data hiding. In this principle, all fields of a
class are secreted from other classes, and they can be retrieved only through the methods of their
existing class. Encapsulation can be achieved by declaring all the class variables as private and
then provide public setter and getter methods to alter and view the variables values (Eckel, 2014).

To add on that, hiding the internals of the object protects its integrity by avoiding users
from setting the internal data of the component into an illegal or unpredictable state and it can
reduce system complexity. There are four of access modifiers to set access levels for classes,
variables, methods, and constructors.

9
1. Visible to the package, the default. No modifiers are needed.

2. Visible to the class only (private).

3. Visible to the world (public).

4. Visible to the package and all subclasses (protected).

All classes of my project, that describes objects and all variables are private, so they can
be accessed only with the help of methods of this class and we cannot change any field of object
of all classes such as Item, Supplier etc. For example, in Purchase Order class, I have these next
private fields:

// List of items

private ArrayList<String> itemCodes;

// Date

private String dateRequired;

// ID of Purchase Order

private String id;

// Sales Manager, who adds this Purchase Order

private User salesManager;

It is possible to change their value only with the help of special method of this classes, they are
called Mutators.

// Setter

public void setCode(String code) {


this.code = code;
}

For getting values from private variables there are special methods, which are called Accessors.

// Getter

public ArrayList<Item> getItems() {


return items;
}

Also, there are some private methods, like in TSB.java class.

10
// Adds users from file to list
private void addUsersFromFile() throws IOException {
for (String s : FileUtils.readFile("Users.txt")) {
String[] values = s.split(",");
users.add(new User(values[0], values[1], AccessRights.valueOf(values[2])));
}
}

Finally, with the help of encapsulation, I protect object’s variables from unauthorized
changes, which may crash the program.

3. Inheritance:

Inheritance is the procedure when one class obtains the fields (data members) and methods
of another class. The goal of inheritance is to offer the reusability of our code so that a class can
write the unique features only and rest of the shared properties and functionalities can be extended
from another class. When we deal with Inheritance, there are two concepts which are Child Class
that extends the structures of another class and Parent Class that whose properties and
functionalities are inherited.

Consequently, all classes in my program are inherited from Object class so, the inheritance
is being used but it is invisible. However, it is possible to create parent class like Document.java
for PurchaseOrder.java and PurchaseRequisition.java classes as they have similar fields and
methods, but this is different documents and we don’t need to incorporate them.

4. Polymorphism

Polymorphism is the capability of the variable, function and object to take various forms.
polymorphism in OOP happens when a parent class reference is used to mention to a child class
object. There are 2 types of polymorphism which are Overriding and known as run-time
polymorphism as the compiler determines which method will be executed when the code is
compiled. Overloading, which is known as compile-time polymorphism as the method will be used
for method overriding is determined at runtime based on the dynamic type of an object.
(javatpoint.com, 2017)

11
Polymorphism is closely connected with inheritance as we are able to Override methods of
the parent class. Moreover, all classes in Java are inherited from Object class, that is why we can
override Object’s methods.

In my project, I override toString() method which returns a string representation of the


object. In general, the toString method returns a string that "textually represents" this object. The
result should be a concise but informative representation that is easy for a person to read. So, we
need a more convenient string representation of the object. For example, in Purchase Order class
toString() method is overridden in a next way.

@Override
public String toString() {
String itemsIDs = "";
String total = "";
for (String item : itemCodes) {
itemsIDs += item + ",";
total += quantity.get(item) + ",";
}
itemsIDs = itemsIDs.substring(0, itemsIDs.length() - 1);
total = total.substring(0, total.length() - 1);
return dateRequired + "\n" + purchaseManager.getLogin() + "\n" + itemsIDs + "\n" + total;
}

So, the string, which represents the object of this class in a next way. The first element is
the date when this Order is needed. The next, which is after the symbol of the new line, is login of
Purchase manager, who has added this order. Then there are IDs of items, which are needed and
the quantity of every item.

5. Array List:

In this project, all data is stored in Array List which supports dynamic arrays that can grow
and extend as required. In the first of creating the array list, we need to initial its size and if the
size is exceeded, the collection is enlarged automatically and if we delete any data from the array
list, the collection is also shrunk automatically. Yet, once the program is started, some methods
were added to get the array list form file as required so we can modify it in each time we run the

12
program. Following is one example of creating an array list for item that its elements got form
Item class to initialize them.

private ArrayList<Item> items;


Apart from that, Array list defines some method that allow to add, remove etc. and they
are applied in the assignment to implement the required function such as add supplier to the list:

suppliers.add(new Supplier(code, name, itemID));

6. HashMap:

HashMap class uses a hashtable to implement the Map interface which allows our basic
operations to stay constant. It is important to use like this feature in our project as it is its values
based on the key and only unique elements can be added on it, further, it can have one null key
and multiple null values and it maintains no order. Therefore, HashMap is used in this
assignment for storing the quantity of every item. It saves objects by keys, so, the key is item and
value is quantity and we are able to get the quantity of item using it as the key.

private HashMap<String, Integer> quantity;

13
4. Results and Assumptions:

Basically, the application has three different access rights which are Admin, Sales
Managers (SM) and Purchase Manager (PM). Each one of them has its own menu and functions.
The application flow begins from Purchase Requisition (PR) by Sales Managers which contains
the item-code, quantity needed and the required date. Then, Purchase Manager (PM) generates a
Purchase Order (PO) which is an authorised document used by organisations for placing orders
with their suppliers for procurement of goods.

1. Admin menu:

On first start of program there is one default user with administrator access rights. It has
login “admin” and password “admin”. When you will login with these parameters you have the
next menu:

14
When program is started, users, items and suppliers are read from the files and added to the lists.

When option 1 is selected which is user registration, you are required to enter user’s login ID,
password and choose the access rights by entering the number 1, 2 or 3. Lastly, the user is added
to the list and list of users is rewritten to the file.

When option 2 is selected which is item entry, you need to enter all the required data to add new
item, however, you must add supplier of this item firstly to complete this process and Item id must
be unique. Yet, if the process has not finished correctly, no such supplier message will be shown.

When option 3 is selected which is delete item, the list of items is shown and you must enter the
index (starts from 1) of item for deleting.

15
When option 4 is selected which is save item, the list of items is written to the file. Yet, old items
list is deleted from the file and current list is added. Lastly, the main menu will be shown again.

When option 5 is selected which is edit item, the list of items is shown. You must enter the index
(starts from 1) of item for editing and enter new values for this item. But firstly, the supplier for
new item id must be added if it has not added yet and Item id must be unique.

When option 6 is selected which is add supplier, you need to enter all data which is asked for
adding supplier and Supplier id must be unique.

Option 7 which is delete supplier, option 8 which is save supplier and option 9 which is edit
supplier are totally same with item part.

16
When option 10 is selected which is Add Daily Item-wise Sales Entry. All items are shown one
by one and quantity of every item is asked. Also, you must enter date that when it will be asked.

When option 11 is selected which is Delete Daily Item-wise Sales Entry, the list of Daily Item-
wise Sales is shown, and you must enter the index (starts from 1) of Daily Item-wise Sales for
deleting.

When option 12 is selected which is Save Daily Item-wise Sales Entry, the list of Daily Item-wise
Sales is shown. After entering the index of Daily Item-wise Sales, it is written to the file. Yet, the
file is saved in “Daily” folder and the date are file name. Finally, the menu will be shown again.

17
When option 13 is selected which is Edit Daily Item-wise Sales Entry, the list of Daily Item-wise
Sales is shown. You must enter the index (starts from 1) of Daily Item-wise Sales for editing and
enter new values for this Daily Item-wise Sales. However, date must be unique.

When option 14 is selected which is Add Purchase Requisition, all items are shown one by one.
And quantity of every item is asked. Also, you must enter date of purchase requisition and its
unique id.

When option 15 is selected which is Delete Purchase Requisition, the list of purchase requisition
is shown, and you must enter the index (starts from 1) of purchase requisition for deleting then the
menu will be shown again.

18
When option 16 is selected which is Save Purchase Requisition, the list of purchase requisition is
shown. After entering the index of purchase requisition, it is written to the file and the id of
purchase requisition is the file name.

When option 17 is selected which is Edit Purchase Requisition, the list of purchase requisition is
shown and you must enter the index (starts from 1) of purchase requisition for editing and enter
new values for this purchase requisition and the ID must be unique.

When option 18 is selected which is Display Requisition, the list of purchase requisition is shown.

19
When option 20 is selected which is List of Purchase Order, The list of purchase orders with their
IDs are shown.

When option 20 is selected which is List of Items, the list of items is shown.

When option 20 is selected which is List of suppliers, the list of suppliers is shown.

When option 22 is selected which is adding purchase order, there must be purchase requisition in
the list and the list of purchase requisition is shown. After entering the number of purchase
requisition, this purchase requisition is shown. You will be asked for editing purchase requisition
or make purchase order from it without editing. When you select first, you will be asked for id of
purchase order, quantity of each element from the requisition and date. If you select second one,
you will be asked only for id.

20
When option 23 is selected which is Delete Purchase Order, the list of purchase orders is shown.
You must enter the index (starts from 1) of purchase order for deleting and then the menu will be
shown again.

When option 24 is selected which is Save Purchase Order, the list of purchase orders is shown.
After entering the index of purchase order, it is written to the file and the ID is file name.

21
When option 25 is selected which is Edit Purchase Order, the list of purchase orders is shown, and
you must enter the index (starts from 1) of purchase order for editing and enter new values for this
purchase order.

When option 26 is selected which is log out, you will see new menu for choosing login or exit
from the program.

Finally, accounts with no admin access rights will show their own menu of functions, yet Admin
account has the biggest menu.

22
2. Purchase Manager menu:
All functions are same with those that explained earlier in the admin menu.

3. Sales Manager menu:

All functions are same with those that explained earlier in the admin menu.

23
5. Conclusion:

To sum up, without any doubt java is a powerful programming language that all
programmers should know and learn as it is really involved in all platforms development from
desktop to mobile phone. Either small programs or enterprise ones, java can be the efficient
language that you can build your programs by.

In this assignment, we were required to develop an order management system for


TRISYSLOGICS SDN BHD (TSB) to automate the work process by applying the OOP techniques
that we learned during the semester to achieve some functionalities. In addition of that, a report
that reflects the program design such as Class Diagram, Use Case Diagram and Activity Diagram
is needed as well as highlighting the implantation details that applies the Object-oriented
programming concepts. Explanation and justification of the design and the code’s implementation
that demonstrated the object-oriented programming concepts incorporated into the solution is
provided.

However, Java language is not easy to be learnt in a short time and it requires many hard
work to understand its concepts. After all the effort, I could manage to accomplish this assignment
in its due data, and leaning this module and completing this assignment is just a one step that needs
to be improved and expanded in the near future.

24
7. References:

Eckel, B. (2014). Thinking in java. Upper Saddle River, N.Y: Prentice hall.
www.javatpoint.com. (2017). Java Tutorial | Learn Java - javatpoint. [online] Available at:
https://www.javatpoint.com/java-tutorial [Accessed 3 Dec. 2017].
Udemy. (2017). Complete Java Masterclass | Udemy. [online] Available at:
https://www.udemy.com/java-the-complete-java-developer-course/learn/v4/overview [Accessed
3 Dec. 2017].
Abdullaheid.net. (2017). Java basics. [online] Available at: http://abdullaheid.net/ [Accessed 3
Dec. 2017].
Deitel, P. and Deitel, H. (2015). Java how to program. Boston: Pearson. [online] Available at:
https://www.google.com/search?rlz=1C1CHZL_enMY767MY767&ei=8gokWrC7F4GDvQTZt6
CgDg&q=how+to+program+in+java+deitel+pdf+download&oq=how+to+prohram+in+java++p
df&gs_l=psy-
ab.1.3.0i19k1j0i13i30i19k1l2j0i8i13i30i19k1l3.5460.7198.0.11171.5.3.2.0.0.0.113.299.2j1.3.0...
.0...1c.1.64.psy-ab..0.2.117....0.OnYIQLH4Ijw [Accessed 3 Dec. 2017].
Thenewboston.com. (2017). Java Tutorial. [online] Available at:
https://thenewboston.com/videos.php?cat=31 [Accessed 3 Dec. 2017].
www.tutorialspoint.com. (2017). javatutorial. [online] Available at:
http://www.tutorialspoint.com/ [Accessed 3 Dec. 2017].
<ohamed Essa. (2017). JAVA programming basics. [online] Available at:
http://muhammedessa.com/portfolio-
item/%D8%A7%D8%B3%D8%A7%D8%B3%D9%8A%D8%A7%D8%AA-
%D8%A8%D8%B1%D9%85%D8%AC%D8%A9-%D8%AC%D8%A7%D9%81%D8%A7-
java-programming/ [Accessed 3 Dec. 2017].

25

Вам также может понравиться