Description
☕ Java Week 3 Graded Programming Assignment Solutions
Versions: v1_t12024, v2_t12025 —
Complete executable Java code implementations covering Inheritance, Polymorphism, and Encapsulation with Banking/Geometric models.
This downloadable bundle provides the complete, required Java code implementations for the three Graded Programming Assignments (GrPA) in Week 3. The solutions focus on implementing correct OOP structures to satisfy polymorphism, method overriding, and constructor chaining requirements.
GrPA 1: Inheritance and Polymorphism (Person/Employee/ContactEmployee)
This assignment focuses on constructor chaining and method overriding:
- Inheritance Structure: Implement
Employee(inheritsPerson) andContactEmployee(inheritsEmployee). - Constructor Chaining: The
Employeeconstructor must call thePersonconstructor usingsuper()to initialize inherited fields (name,aadharno). - Calculated Field: The
ContactEmployeeconstructor must calculate thesalarybased oncontactHour * hourlyPaybefore callingsuper()to pass the salary to theEmployeesuperclass constructor. - Method Overriding: The
Employee.print()method must overridePerson.print()and callsuper.print()to include inherited details before printing thesalary.
GrPA 2: Runtime Polymorphism and instanceof (Shape/Rectangle/Cube)
This assignment demonstrates dynamic method dispatch and runtime type checking:
- Method Overriding: Implement
area()andvolume()methods inRectangleandCubesubclasses, overriding the default implementations in theShapeclass. - Constructors: Implement constructors for
Rectangle(w,h) andCube(a) to initialize private dimensions. - Polymorphic Caller: Implement the static method
FClass.caller(Shape s)to demonstrate runtime behavior:- If
sis aRectangle(checked usinginstanceof), print the result ofs.area(). - If
sis aCube, print the result ofs.volume().
- If
GrPA 3: Encapsulation and Banking Logic (BankAccount)
This assignment focuses on controlled data access and method structure:
- Final/Private Fields: Define the
finalminimum balance and implement aprivatemethodcheckMinBalance(amount)to enforce the minimum balance rule before any withdrawal. - Encapsulated Withdrawal: The public
withdraw(int amt)method must callcheckMinBalance(). It only proceeds withbalance -= amtif the check returns true; otherwise, it prints “Transaction failed”.

Reviews
There are no reviews yet.