






















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
java java java java java java java java java java
Typology: Assignments
1 / 30
This page cannot be seen from the preview
Don't miss anything!























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
P1. Discuss the principles; characteristics and features of object orientated programming.
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.
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:
table, keyboard. It can be physical and logical.
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:
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. 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.
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.