Assignment 1: Unit 20 Advanced Programming, Assignments of Advanced Data Analysis

Assignment 1: Unit 20 Advanced Programming

Typology: Assignments

2020/2021

Uploaded on 10/06/2021

unknown user
unknown user šŸ‡»šŸ‡³

1 / 31

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 1 FRONT SHEET
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 BHAF190198
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 D2
~ 1 ~
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f

Partial preview of the text

Download Assignment 1: Unit 20 Advanced Programming and more Assignments Advanced Data Analysis in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

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

ā’ Summative Feedback: ā’ Resubmission Feedback:

Grade: Assessor Signature: Date: Internal Verifier’s Comments: Signature & Date:

Table of Contents

  • I. Introduction............................................................................................................................
  • II. The characteristics of the object-orientated paradigm..........................................................
      1. Object.................................................................................................................................
      1. Class.................................................................................................................................
      1. Abstraction.......................................................................................................................
      1. Encapsulation...................................................................................................................
      1. Inheritance........................................................................................................................
      1. Polymorphism..................................................................................................................
  • III. The various class relationships..........................................................................................
  • IV. Design UML class diagrams..............................................................................................
      1. What is UML class diagram?...........................................................................................
      1. Design class diagram.......................................................................................................
  • V. Conclusion..........................................................................................................................
  • VI. References..........................................................................................................................

I. Introduction

ā€˜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:

  1. The characteristic of the object-oriented paradigm as well as the various class relationships.
  2. Design a UML class diagrams.

II. The characteristics of the object-

orientated paradigm

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.

2. 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:

  1. The second example, consider an ATM Machine; All are performing operations on the ATM machine like cash withdrawal, money transfer, retrieve mini statement… etc. but we cannot know internal details about ATM. Implement with example. For example : Employee, Contractor, and Fulltime Employee Example In this example, we create an abstract Employee class and this class contains the abstract mathSalary () method. Let the subclasses extend the Employee class and implement the CalculSalary () method. Let's create Contractor and FullTimeEmployee classes as we know that the salary structure for a contractor and full-time employees are different so let these classes to override and implement a calculateSalary () method.

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:

4. Encapsulation

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

  1. Capsule , it is wrapped with different medicines. In a capsule, all medicine is encapsulated inside a capsule.
  1. To better put it in a simple way, Let’s say I have 2 Cars - A Ford GT & A Chevrolet Camaro. Let’s say my Ford GT & Camaro are having Petrol Engines. I can change my cars color, lights, Visual Appearances etc.… but cannot switch it to Diesel and It would not work if I were to use diesel for these cars. Implement with example Consider below Person class diagram, the id and nam e parameters should not be accessed directly outside Person class - achieved by private declaration. I will create a Person class to demonstrate the use of encapsulation in Java.

Output:

5. Inheritance

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

  1. Real-life examples of inheritance are children and parents, all of a father's property is inherited by his son.