Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Pillars of Object Orientation A) The four pillars of OOP are: 1. Abstraction

ID: 3903437 • Letter: 1

Question

1) Pillars of Object Orientation

A) The four pillars of OOP are: 1. Abstraction 2. Encapsulation 3. Inheritance 4. Polymorphism

Explain each of these core ideas:

B) Explain the “Is A” relationship and what it allows us to do in our code, and give an example: ?

2) Applied OOP Principles

public class MyClass {

private String firstName;

private String lastName;

private int idNumber;

private double balance;

public MyClass() {

this.firstName = "";

this.lastName = "";

this.idNumber = -1;

this.balance = 0.0; }

public MyClass(String firstName, String lastName, int id) {

this.firstName = firstName;

this.lastName = lastName;

this.idNumber = id;

this.balance = 0.0; }

public void makeDeposit(int id, double amount) {

if(this.confirm(id)) {

this.balance += amount; } }

public void withdraw(int id, double amount) {

if(this.confirm(id)) {

if(amount > this.balance)

System.out.println("Not enough in account");

else this.balance -= amount; } }

private boolean confirm(int id) {

if(this.idNumber == id)

return true;

else { System.out.println("INVALID"); return false; } } }

A) Describe what this class represents and what it does: [3]

B) What methods make up the class’s public interface? [3]

C) If a programmer wanted to inherit from this class and make a more specialized version, what problems might the programmer face and how could they be corrected? [4]?

3) Inheritance & Polymorphism

A) Describe and contrast the three visibility modifiers: [3]

B) Examine a real world (non-code) example of Polymorphism, explain how the polymorphism is expressed: [3] C) Given this abstract base class: [4] public class Shape { protected int x; protected int y; public Shape(int x, int y) { this.x = x; this.y = y; } public abstract double CalculateArea(); } ?

4) Arrays

A) Referring to problem 3C - Exploit Java’s support of inheritance and polymorphism to create a single array of size int NumberOfShapes that can contain any number of Squares and Rectangles:

B) Given two variables: int xSize and ySize and the knowledge that these variables have been given valid integer input… give a code snipet to create a 2D integer array called MultTable and fill it with a multiplication table: ?

5) Static Methods and Properties

A) Explain what the static keyword does when used with a method in a class and give an example of a static method from Java’s own libraries:

B) Given this class snippet: public class Student { private String firstName; // first name private String lastName; // last name private String email; // email address private int catalogYear; //catalog year for student entrollment // construct a new student with given fields public Student(String first, String last, String email, int section) { this.first = first; this.last = last; this.email = email; this.section = section; } The school would like to add a unique identifier to every student as each record object is created. Modify the class properties and constructor to achieve this. Show the result below:

Explanation / Answer

Please Note: As per Chegg Answering Guidelines, I have answered the first question. Please Post Separate for Separate Questions.

Answer)
Q1) Pillars of Object Orientation

A) The four pillars of OOP are: 1. Abstraction 2. Encapsulation 3. Inheritance 4. Polymorphism

Explain each of these core ideas:

B) Explain the “Is A” relationship and what it allows us to do in our code, and give an example: ?
Answer)

A) The four pillars of OOP are: 1. Abstraction 2. Encapsulation 3. Inheritance 4. Polymorphism

1. Abstraction
Abstraction is the concept in OOPS where we can hide the complex and unnecessary things from the user and the user does not need to understand and think about the complexity which is implemented but we can implement more logic on the top of what is there in the abstract class. Thus Abstraction hides the internal implementation and does just the behavior it is supposed to do.

2. Encapsulation
Encapsulation is the principle of identifying a public interface to a software component that is relied upon by other programmers while treating the remaining internal implementation details as private. The above principle is about hiding the implementation details which as hidden or encapsulated and thus objects are not allowed to view the implementation of others. Thus the above principle is about Encapsulation.

3. Inheritance
Inheritance is a IS-A relationship where there is a parent child relationship among classes. Here in inheritance on object from the child gets all the properties and behavior of the parent object by extending the parent class. We can re-use the methods and fields of the parent class in the child class by inheritance.

4. Polymorphism
Polymorphism is 2 types known as Method Overloading and Method Overriding. Method Overloading is the behavior when in the same class it has multiple methods having the same name but just differing in the number of arguments and changing the data type. Thus methods can be reused and different method with the same name can be called using arguments.
Method Overriding is the scenario where there is a parent class and a child class. The child class inherits the parent class. When there is a method in the parent class which is also implemented by the child class by keeping the method name, parameters same, then this is a method overriding. Method Overriding is run-time polymorphism.

B) Inheritance is a IS-A relationship where there is a parent child relationship among classes. Here in inheritance on object from the child gets all the properties and behavior of the parent object by extending the parent class. We can reuse the methods and fields of the parent class in the child class by inheritance.
In Java, polymorphism is there in 2 types known as Method Overloading and Method Overriding. Method Overloading is the behaviour when in the same class it has multiple methods hacing the same name but just differing in the number of agrguments and changing the data type. Thus methods can be reused and differint method with the same name can be called using arguments.
Method Overriding is the scenario where there is a parent class and a child class. The child class inherits the parent class. When there is a method in the parent class which is also implemented by the child class by keeping the method name, parameters same, then this is a method overriding. Method Overriding is run-time polymorphism.

Example of Java code inheritance:
class SchoolEmployee{
int salary=2000;
}

public class Teacher extends SchoolEmployee{
int bonus=1000;
public static void main(String args[]){
Teacher p=new Teacher();
System.out.println("Teacher salary: "+p.salary);
System.out.println("Employee bonus: "+p.bonus);
}
}

Output:
Teacher salary: 2000
Employee bonus: 1000

Here the variable declared and set in the class SchoolEmployee is accessible in the child class Teacher as Teacher inherits the class SchoolEmployee. Thus the output is accessible and fine.