























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Assignment 1: Unit 20 Advanced Programming
Typology: Assignments
Uploaded on 10/06/2021
1 / 31
This page cannot be seen from the preview
Don't miss anything!
























Qualification TEC Level 5 HND Diploma in Computing Unit number and title Unit 20: Advanced Programming Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Do Thi Dieu Linh Student ID BHAF Class BHAF1911-2.2 Assessor name Buy Duy Linh Student declaration I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that making a false declaration is a form of malpractice. Studentās signature Linh Grading grid P1 P2 M1 M2 D1 D
Grade: Assessor Signature: Date: Internal Verifierās Comments: Signature & Date:
āObject-Oriented Programmingāā and āāData Abstractionāā have become very common terms. Unfortunately, few people agree on what they mean. In this assignment I will explain the characteristics of object-oriented programming such as encapsulation, inheritance, polymorphism, ... as well as different class relationships. After that, I will design a class diagram based on a given code scenario. This report consists of two sections:
OOP stands for Object-Oriented Programming. Object-oriented programming is a methodology or paradigm to design a program using classes and objects. OOP focuses on the objects that developers want to manipulate rather than the logic required to manipulate them. This approach to programming is well-suited for programs that are large, complex and actively updated or maintained. An OO program: āa bunch of objects telling each other what to do by send messagesā. Some benefits of OOP: ļ· Better abstractions (modeling information and behavior together). ļ· Better maintainability (more comprehensible, les fragile). ļ· Better reusability (classes as encapsulated components). OOP has many features that make it useable including the followings: ļ· Object ļ· Class ļ· Inheritance ļ· Polymorphism ļ· Abstraction ļ· Encapsulation.
ļ· Bicycle is an object. Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). How to Declare, Create and Initialize an Object in Java A class is a blueprint for Object, you can create an object from a class. Let's take Student class and try to create Java object for it. I will create a simple Student class which has name and college fields. Then, I will write a program to create declare, create and initialize a Student object in Java.
From the above program, the Student object are:
Note that we have used a new keyword to create Student objects. 3) Initializing an Object The new keyword is followed by a call to a constructor, which initializes the new object. For example: From above code will call below constructor in Student class.
A class is a group of objects which have common properties. A class is a kind of mold or template that dictates what objects can and cannot do. An object is called an instance of a class. An object is an instance of exactly one class. An instance of a class belongs to the class. In short, a class is the specification or template of an object. Once a class is defined, we can create as many instances of the class as a program requires. Figure below shows a diagram that we will use throughout the book to represent a class.
The syntax for declaring classes: I will demonstrate how to create Class in Java with an example. Here is a Student class:
Let's write source code by looking into an above class diagram. Step 1 : Let's first create the superclass Employee. Note the usage of abstract keyword in this class definition. This marks the class to be abstract, which means it cannot be instantiated directly. We define a method called calculateSalary () as an abstract method. This way I leave the implementation of this method to the inheritors of the Employee class.
Step 3 : The FullTimeEmployee also has its own implementation of calculateSalary () method. In this case, we just multiply by a constant value of 8 hours. Step 4 : Let's create a AbstractionDemo class to test implementation of Abstraction with below code:
Encapsulation is a process of wrapping of data and methods in a single unit is called encapsulation. In OOP, data and methods operating on that data are combined together to form a single unit, which is referred to as a Class. Real-world example
Output:
The Inheritance is a process of obtaining the data members and methods from one class to another class, plus can have its own is known as inheritance. It is one of the fundamental features of object-oriented programming. Inheritance - relationship between a superclass and its subclasses. ļ· Sub class: Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class. ļ· Super class: Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class. This can be visualized as follows.
In class diagrams such as this, subclasses point up to their superclass. The attributes and behaviors implemented in the superclass are āinheritedā by all the subclasses. The attributes and behaviors implemented in one of the subclasses are unique that subclass. In a sense, the features shared by subclass1 and subclass 2, that might otherwise have been implemented separately in each of the subclasses, can be collected and āraised upā into the single shared superclass. Real-world example