For by preventing users from setting the internal data

For thisproject, I must develop some classes. The UML diagram of it included in thefile UML.png.

Aswe can see, there we have ten classes:1.       Main.java2.       FileUtils.java3.       User.java4.       AccessRights.

Best services for writing your paper according to Trustpilot

Premium Partner
From $18.00 per page
4,8 / 5
4,80
Writers Experience
4,80
Delivery
4,90
Support
4,70
Price
Recommended Service
From $13.90 per page
4,6 / 5
4,70
Writers Experience
4,70
Delivery
4,60
Support
4,60
Price
From $20.00 per page
4,5 / 5
4,80
Writers Experience
4,50
Delivery
4,40
Support
4,10
Price
* All Partners were chosen among 50+ writing services by our Customer Satisfaction Team

java(enumeration)5.       PurchaseOrder.java6.

       PurchaseRequisition.java7.       Item.java8.       Supplier.java9.

       DailyItemWiseSales.java10.   TSB.javaSo, what is Object-oriented programming (OOP)? Itis a programming paradigm based on the concept of objects. Objects may containdata, in the form of fields, often known as attributes. Also, they may contain code,in the form of procedures, often known as methods. A feature of objects is thatan object’s procedures can access and often modify the data fields of theobject with which they are associated.

In OOP, computer programs are designedby making them out of objects that interact with one another.So, everyclass of my program describes some object, like User, Item, Supplier, etc. Onlytwo classes are used for providing only methods. They are Main.java and FileUtils.java.The first of them is used for interacting with a user with the help ofTerminal. The second is used for writing and reading information from files.

There are 4main principles of OOP.1.       Encapsulation: Itmeans that the internal representation of an object is generally hidden fromview outside of the definition of the object.

Typically, only the object’s ownmethods can directly work with its fields.Encapsulationis the hiding of data implementation by restricting access to accessors andmutators.Anaccessor is a method that is used to ask an object about itself. In OOP, theseare usually in the form of properties, which have a get method, which is anaccessor method. However, accessor methods are not restricted to properties andcan be any public method that gives information about the state of the object.AMutator is a public method that is used to modify the state of an object whilehiding the implementation of exactly how the data gets modified. It’s the setmethod that lets the caller modify the member data behind the scenes.Hidingthe internals of the object protects its integrity by preventing users fromsetting the internal data of the component into an invalid or inconsistentstate.

This type of data protection and implementation protection is calledEncapsulation.A benefitof encapsulation is that it can reduce system complexity.Javaprovides a number of access modifiers to set access levels for classes,variables, methods, and constructors. The four access levels are ?·        Visible to the package, the default. No modifiers areneeded.·        Visible to the class only (private).·        Visible to the world (public).

·        Visible to the package and all subclasses (protected).All classesof my project, that describes objects, all variables are private. So they maybe accessed only with the help of methods of this class. So, we cannot changeany field of object of classes for Item, Supplier, Purchase Requisition,Purchase Order, Daily Item-Wise Sales, or User from TBS class, which containsthis objects. In Purchase Order class, for example, I have next private fields: /**     * List ofitems     */    private ArrayList itemCodes;        /**     * Quantityof items     */    private HashMap quantity;        /**     * Date     */    private String dateRequired;        /**     * ID ofPurchase Order     */    private String id;        /**     * SalesManager, who adds this Purchase Order     */    private User salesManager; It ispossible to change their value only with the help of special method of thisclasses, they are called mutators (for example/**     * Setter     * @paramcode      */    public void setCode(String code) {        this.code= code;    } method inItem class). For getting values from private variables there are specialmethods, which are called accessors (for example /**     * Getter     * @return      */    public ArrayList getItems() {        return items;    } which givesaccess to the Items list from class, that represents Daily Item-Wise Sales). Also, there are some private methods,like /**     * Addsusers from file to list     * @throwsIOException      */    private void addUsersFromFile() throws IOException {        for (String s :FileUtils.

readFile(“Users.txt”)) {           String values = s.split(“,”);           users.add(new User(values0, values1,AccessRights.valueOf(values2)));        }    } in TSB.javaclass. So we can use this method only in this class.

With the help ofencapsulation, I protect object’s variables from unauthorized changes,which may crash the program.2.       Abstraction Dataabstraction and encapsulation are closely tied together, because a simpledefinition of data abstraction is the development of classes, objects, types interms of their interfaces and functionality, instead of their implementationdetails. Abstraction denotes a model, a view, or some other focusedrepresentation for an actual item.”Anabstraction denotes the essential characteristics of an object that distinguishit from all other kinds of object and thus provide crisply defined conceptualboundaries, relative to the perspective of the viewer.” — G.

BoochIn short,data abstraction is nothing more than the implementation of an object thatcontains the same essential properties and actions we can find in the originalobject we are representing.In myproject, there is no abstraction because we don’t have any standard interface forobjects.3.       Inheritance Inheritanceis a way to reuse code of existing objects, or to establish a subtype from anexisting object, or both, depending upon programming language support. Inclassical inheritance where objects are defined by classes, classes can inheritattributes and behavior from pre-existing classes called base classes,superclasses, parent classes or ancestor classes.

The resulting classes areknown as derived classes, subclasses or child classes. The relationships of classesthrough inheritance gives rise to a hierarchy.Subclassesand Superclasses A subclass is a modular, derivative class that inherits one ormore properties from another class (called the superclass). The propertiescommonly include class data variables, properties, and methods or functions.The superclass establishes a common interface and foundational functionality,which specialized subclasses can inherit, modify, and supplement. The softwareinherited by a subclass is considered reused in the subclass.

In some cases, asubclass may customize or redefine a method inherited from the superclass. Asuperclass method which can be redefined in this way is called a virtualmethod.So, there arenot any similar classes in my project, that is why I did not use inheritance.

It is possible to create parent class like Document.java for PurchaseOrder.javaand PurchaseRequisition.java classes, they have similar fields and methods, butthis is different documents and we don’t need to incorporate them.

But allclasses in Java are inherited from Object class. So, I can say, that I useinheritance, but it is invisible.4.       Polymorphism Polymorphismmeans one name, many forms. Polymorphism manifests itself by having multiplemethods all with the same name, but slightly different functionality.

Thereare 2 basic types of polymorphism. Overriding also called run-timepolymorphism. For method overloading, the compiler determines which method willbe executed, and this decision is made when the code gets compiled.Overloading, which is referred to as compile-time polymorphism. The method willbe used for method overriding is determined at runtime based on the dynamictype of an object.

If you cangrasp these four principles, OOP can be much of a breeze for you. It might takemore than one read, I encourage you to practically try it.Polymorphismis closely connected with inheritance. We are able to Override methods of the parentclass.

As all classes in Java are inherited from Object class, that is why wecan override Object’s methods. In my project, I override toString() method.This method returns a string representation of the object.

In general, thetoString method returns a string that “textually represents” thisobject. The result should be a concise but informative representation that iseasy for a person to read. It is recommended that all subclasses override thismethod.ThetoString method for class Object returns a string consisting of the name of theclass of which the object is an instance, the at-sign character `@’, and the unsignedhexadecimal representation of the hash code of the object.

In other words, thismethod returns a string equal to the value of:  getClass().getName() + ‘@’ +Integer.toHexString(hashCode()) But we needa more convenient string representation of the object. For example, in PurchaseOrder class toString() method is overridden in a next way.

    @Override    public String toString() {        StringitemsIDs = “”;        Stringtotal = “”;        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 +””+ purchaseManager.

getLogin() + “” +itemsIDs + “” + total;    } So, the string, which represents the object of thisclass 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 Purchasemanager, who has added this order. Then there are IDs of items, which areneeded and the quantity of every item.