Object-Oriented Programming Principles and Design: Assignment 1 - Prof. Ho Nguyen Phu Bao, Assignments of Programming Languages

java java java java java java java java java java

Typology: Assignments

2020/2021

Uploaded on 04/21/2021

NguyenTatTrung123
NguyenTatTrung123 🇻🇳

4.5

(4)

4 documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 1
Qualification BTEC HND Diploma in Computing and Systems Development
Unit number and title Unit 19: Object Oriented Programing
Assignment due Assignment submitted 17/4/2021
Learner’s name Nguyen Tat Trung Assessor name Nguyen Tuan Dang
Learner declaration:
I certify that the work submitted for this assignment is my own and research sources are fully acknowledged.
Learner signature Date
Grading grid
P1 P2 M1 M2 D1 D2
Assignment title Assignment 1: OOP principles, features and design.
In this assignment, you will have opportunities to provide evidence against the following criteria.
Indicate the page numbers where the evidence can be found.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download Object-Oriented Programming Principles and Design: Assignment 1 - Prof. Ho Nguyen Phu Bao and more Assignments Programming Languages in PDF only on Docsity!

ASSIGNMENT 1

Qualification BTEC HND Diploma in Computing and Systems Development Unit number and title Unit 19: Object Oriented Programing Assignment due Assignment submitted 17/4/ Learner’s name Nguyen Tat Trung Assessor name Nguyen Tuan Dang Learner declaration: I certify that the work submitted for this assignment is my own and research sources are fully acknowledged. Learner signature Date Grading grid P1 P2 M1 M2 D1 D Assignment title Assignment 1: OOP principles, features and design. In this assignment, you will have opportunities to provide evidence against the following criteria. Indicate the page numbers where the evidence can be found.

Assessment criteria Expected evidence Task no. Assessor’s Feedback

LO1. Understand the principles of object oriented programming.

P1. Discuss the principles; characteristics and features of object orientated programming.

  • Object/Class,
  • Abstraction,
  • Encapsulation,
  • Inheritance,
  • Polymorphism,
  • Abstract classes,
  • Interfaces 1

LO2. Be able to design object oriented programming solutions.

P2. Identify the objects and data and file structures required to implement a given design. Design an object orientated programming solution for a given problem.

  • Use-case diagrams
  • Class diagrams
  • Pseudo-codes
  • Activity Diagrams.
  • Judgments for features have been included/excluded and why certain features have been used over others (where applicable) 2 Assessment criteria Expected Evidence Feedback
  • Task 1. Explain the principles and features of OOP and that show how OOP is good for code re-use.
    • Object
    • Class.
    • Inheritance
    • Polymorphism
    • Abstraction
    • Encapsulation
  • Task 2. Problem analysis for the scenario above
    • Use-case diagrams for the most important features
    • Class diagrams for all objects identified as well as class relationships
    • Pseudo-code for the algorithms for the main functionalities(3 flowcharts for most complex functions)
  • References

Task 1. Explain the principles and features of OOP and that show how

OOP is good for code re-use.

Object-oriented programming is a methodology or paradigm to design a program using classes and objects. It simplifies software development and maintenance by providing some:

Object. Any entity that has state and behavior is known as an object. For example, a chair, pen,

table, keyboard. It can be physical and logical.

Class. Collection of objects is called class. It is a logical entity. A class can also be defined as

blueprint from which you can create an individual object. Class doesn’t consume any space. To give you an idea about classes and behaviors of real world cat And to define them in our program. First we need to create 2 objects of the class

As you can see in the above diagram, there are many common states and behaviors (common code) between Album and Movie. When implementing this class diagram into code, are you going to write (or copy & paste) the entire code for Movie? If you do, you are repeating yourself. How can you avoid code duplication? This is where we use inheritance. Inheritance is a mechanism in which one object acquires all the states and behaviors of a parent object. Inheritance uses a parent-child relationship (IS-A relationship). So what exactly is inherited? Visibility/access modifiers impact what gets inherited from one class to another. In Java, as a rule of thumb we make instance variables private and instance method public In this case, we can safely say that the following are inherited:

  1. Public instance methods
  2. Private instance variables (private instance variables can be accessed only through public getter and setter methods) Types of inheritance in Java There are 5 types of inheritance in Java. They are single, multilevel, hierarchical, multiple and hybrid. Class allows single, multilevel, and hierarchical inheritances. Interface allows multiple and hybrid inheritances

Polymorphism. If one task is performed in different ways, it is known as polymorphism. For example:

to convince the customer differently, to draw something. In java, we used method overloading and method overriding to achieve polymorphism. In this example, we are creating two classes Bike and Splendor. Splendor class extends Bike class and overrides its run() method. We are calling the run method by the reference variable of Parent class. Since it refers to the subclass object and subclass method overrides the Parent class method, the subclass method is invoked at runtime. Since method invocation is determined by the JVM not compiler, it is known as runtime polymorphism.

You can observe that except abstract methods the Employee class is same as normal class in Java. The class is now abstract, but it still has three fields, seven methods, and one constructor. Now you can try to instantiate the Employee class in the following way

Encapsulation. Binding (or wrapping) code and data together into a single unit are known as

encapsulation. It’s just like a capsule that contains a mix of several medicines, and is a technique that helps keep instance variables protected. This can be achieved by using private access modifiers that can’t be accessed by anything outside the class. In order to access private states safely, we have to provide public getter and setter methods. (In Java, these methods should follow JavaBeans naming standards.) Let’s say there is a record shop that sells music albums of different artists and a stock keeper who manages them. If you look at figure above, the StockKeeper class can access the Album class’s states directly as Album class’s states are set to public. What if the stock keeper creates an album and sets states to negative values? This can be done intentionally or unintentionally by a stock keeper. To illustrate, let’s see a sample Java program that explains the above diagram and statement.

Main class:

Output: The album’s price and number of copies can’t be negative values. How can we avoid this situation? This is where we use encapsulation. In this scenario, we can block the stock keeper from assigning negative values. If they attempt to assign negative values for the album’s price and number of copies, we’ll assign them as 0.0 and 0.

StockKeeper class

Main class: Output: With encapsulation, we’ve blocked our stock keeper from assigning negative values, meaning we have control over the data. Apart from these concepts, there are some other terms which are used in object-oriented design Coupling. Coupling refers to the knowledge or information or dependency of another class. It arises when classes are aware of each other. If a class has the details information of another class, there is strong coupling. In Java, we use private, protected, and public modifiers to display the visibility level of a class, method, and field. You can use interfaces for the weaker coupling because there is no concrete implementation. Cohesion. Cohesion refers to the level of a component which performs a single well-defined task. A single well-defined task is done by a highly cohesion method. The weakly cohesion method will split the task into separate parts. The java.io package is a highly cohesion package because it has I/O related classes and interface. However, the java.util package is a weakly cohesive package because it has unrelated classes and interfaces.

  • lecEmail: Lecturer email
  • lecAddress: Lecturer address
  • lecDept: Lecturer department (e.g., Computing, Business, etc) This application will need to provide following functionalities via a menu
  1. Manage students
  2. Manage lecturers
  3. Exit When user selects 3, the program will exit When user selects 1, the program will display submenu for managing students:
  4. Add new student
  5. View all students
  6. Search students
  7. Delete students
  8. Update student
  9. Back to main menu When user selects 2, the program will display submenu for managing lecturers:
  10. Add new lecturer
  11. View all lecturers
  12. Search lecturers
  13. Delete lecturers
  14. Update lecturer
  15. Back to main menu For the submenu:

When user chooses 1, program will prompt user to input student’s/lecturer’s information (specified previously). After that, program will validate the input data and if they are all valid, program will add a new student/lecturer to the current list of students/lecturers. Program should inform to the user corresponding messages. When user chooses 2, the program will list all the students/lecturers to the screen, each student/lecturer in a row and student’s/lecturer’s data fields are separated by ‘|’. When user chooses 3, the program will ask user to input student’s/lecturer’s name to search for, the user can just type part of the name in order to search for complete student/lecturer information. When user chooses 4, program will ask user to input student/lecturer id to delete the student/lecturer with the specified id if it exists, otherwise, it will display a message to inform users that the student/lecturer with such id doesn’t exist. When user chooses 5, program will first ask user to input student/lecturer id to update, once inserted and a student/lecturer with the inserted id exists, it will display current data for each field of the student/lecturer and user can type in new data to update or just press enter to keep the current data for the field. When user chooses 6, program will back to the main menu. After analyzed problem, I need to produce a full design for the requirements given.