Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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

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 classs 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 Javas 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 Javas 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:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students explore these related Databases questions