0% found this document useful (0 votes)
2 views10 pages

MDCR Java 2025

The document describes two Java programs: one that calculates the area of geometric figures (triangle, rectangle, square) and another that manages employee payroll in a company. The first program consists of classes for different figures and their area calculations, while the second program includes classes for various employee types and their payment methods. Both programs include subquestions with answer groups for completing the code.

Uploaded by

mrl2227000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

MDCR Java 2025

The document describes two Java programs: one that calculates the area of geometric figures (triangle, rectangle, square) and another that manages employee payroll in a company. The first program consists of classes for different figures and their area calculations, while the second program includes classes for various employee types and their payment methods. Both programs include subquestions with answer groups for completing the code.

Uploaded by

mrl2227000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

MDCRJava Final Exam 2025

Q1. Read the following description of a Java program and the program itself, then
answer the subquestion.
[Program Description]
This program calculates the area of a figure and outputs the result. The figure is a
triangle, rectangle, or square, and is defined in the program as a figure object with the
following attributes.
Triangle: Length of three sides
Rectangle: Length of two sides (vertical and horizontal)
Square: Length of one side
This program is comprised of the following five classes.

AreaTest
This class has the method main, and performs the following processes:
(1) It constructs triangles, rectangles, and square objects, and sets them in array
figures.
(2) It obtains the area of each figure and outputs the result. In this case, it is
assumed that numerical values resulting in correct figures are provided.

Figure
This class is an abstract class of figures. It declares the abstract method getArea,
which calculates the area and returns the result.

Triangle
This class is a triangle class. It defines the method toString, which returns an attribute
as a character string; and the method getArea, which calculates the area of a triangle
using Heron’s Formula and returns the result.

Rectangle
This class is a rectangle class. It defines the method toString, which returns an attribute
as a character string; and the method getArea, which calculates the area of a rectangle
and returns the result.

Square
This class is a square class. It defines the method toString, which returns an attribute
as a character string.
The Program 1 execution results are shown here.

Triangle : sides = 2.0, 3.0, 3.0 : area = 2.8284271247461903


Rectangle : height = 5.0, width = 8.0 : area = 40.0
Square : width = 5.0 : area = 25.0
1
MDCRJava Final Exam 2025

Fig. Execution Results

2
MDCRJava Final Exam 2025

[Program 4]

[Program
5]

Subquestion
From the answer groups below, select the correct answers to be inserted in the blanks
through in the above programs. The same answer may be
selected more than once.

Answer group for a, b, and d:


a) abstract b) Figure c) getArea
d) Rectangle e) Square f) super
Answer group for c:

3
MDCRJava Final Exam 2025

a) height b) height * height


c) height * width d) width
e) width * width

Answer group for e:


a) super(height) b) super(height, height)
c) super(width) d) super(width, height)
e) super(width, width) f) this.height = height
g) this.height = width h) this.width = height
i) this.width = width

Q2. Read the following description of a Java program and the program itself, and then
answer the Subquestion.

A Java program consists of the following classes that represent various types of
employees that are employed at a company.

Classes Purpose

Firm This is the executable class which has the main() method. It
creates a Staff of employees and invokes the payday method to
pay them all.

The program output includes information about each employee


and how much each is paid.

Staff The Staff class maintains an array of objects that represent


individual employees of various kinds (staffList). The array is
declared to hold StaffMember references and filled with objects
created from several other classes. These classes are all inherit
from StaffMember class.

The staffList array is filled with polymorphic references.

StaffMember This abstract class represents a generic staff member. It does not
represent a particular type of employee and is not intended to be
instantiated.

It serves as the ancestor of all employee classes and contains


information that applies to all employees. Each employee has a
name, address and phone number, so variables to store these
values are declared in the StaffMember class and are inherited by

4
MDCRJava Final Exam 2025

all subclasses.

Volunteer This class represents a staff member that works as a volunteer.

A volunteer is not compensated monetarily for his or her work.

Employee This class represents an employee that gets paid at a particular


rate each period.

Executive This class represents an executive staff member, who can earn a
bonus in addition to his or her own normal pay rate.

Hourly This class represents an employee that gets paid by the hour.

The payday method of the Staff class scans through the list of employees, printing their
information and invoking their pay methods to determine how much each employee
should be paid. The invocation of the pay method in some of the classes described
above is polymorphic because each class has its own version of the pay method.

The following output shows the execution results of the program.

Name: Sam

Address: 123 Main Line

Phone: 555-0469

Social Security Number: 123-45-6789

Paid: 2923.0

[Program]
public class Firm {

public static void main(String[] args) {

Staff personnel = new Staff();

public class Staff {

5
MDCRJava Final Exam 2025

private StaffMember[] staffList;

public Staff() {

staffList = new StaffMember[3];

staffList[0] = new Executive("Sam", "123 Main Line",

"555-0469", "123-45-6789", 2423.07);

staffList[1] = new Employee("Carla", "456 Off Line",

"555-0101", "987-65-4321", 1246.15);

staffList[2] = new Hourly("Woody", "789 Off Rocker",

"555-0000", "010-20-3040", 10.55);

(( )staffList[0]).awardBonus(500.00);

(( )staffList[2]).addHours(40);

public void payday() {

double amount;

for (int count=0; count < staffList.length; count++)

System.out.println(staffList[count]);

amount = ; // polymorphic

if (amount == 0.0)

System.out.println("Thanks!");

else

System.out.println("Paid: " + amount);

System.out.println("-----------------------------------");

6
MDCRJava Final Exam 2025

abstract public class StaffMember {

protected String name; protected String address; protected String phone;

public StaffMember(String eName,String eAddress, String ePhone)

{ name = eName; address = eAddress; phone = ePhone;

public String toString() {

String result = "Name: " + name + "\n";

result += "Address: " + address + "\n";

result += "Phone: " + phone;

return result;

public abstract double pay();

public class Volunteer extends StaffMember {

public Volunteer(String eName, String eAddress, String ePhone) {

super(eName, eAddress, ePhone);

public double pay() {

return 0.0; }

public class Employee extends StaffMember {

7
MDCRJava Final Exam 2025

protected String socialSecurityNumber;

protected double payRate;

public Employee(String eName, String eAddress, String ePhone,

String socSecNumber, double rate) {

super(eName, eAddress, ePhone);

socialSecurityNumber = socSecNumber;

payRate = rate;

public String toString() {

String result = + "\nSocial Security Number: " +

socialSecurityNumber;

return result;

public double pay() {

return payRate;

public class Executive extends {

private double bonus;

public Executive(String eName, String eAddress, String ePhone,

String socSecNumber, double rate) {

super(eName, eAddress, ePhone, socSecNumber, rate);

8
MDCRJava Final Exam 2025

bonus = 0;

public void awardBonus(double execBonus) {

bonus = execBonus; }

public double pay() {

double payment = super.pay() + bonus;

bonus = 0;

return payment;

public class Hourly extends Employee {

private int hoursWorked;

public Hourly(String eName, String eAddress, String ePhone,

String socSecNumber, double rate) {

hoursWorked = 0;

public void addHours(int moreHours) {

hoursWorked += moreHours }

public double pay() {

double payment = payRate * hoursWorked;

hoursWorked = 0;

return payment;

9
MDCRJava Final Exam 2025

public String toString() {

String result = super.toString();

result += "\nCurrent hours: " + hoursWorked;

return result;

} }

Answer group for A

a) payday() b) personnel c) personnel.payday()

d) personnel.Staff() e) personnel=null f) Staff()

Answer group for B, C and F

a) abstract b) Employee c) Executive d) Hourly

e) Object f) Staff g) StaffMember h) super i) Volunteer

Answer group for D and E

a) payrate+bonus b) payrate+super.bonus

c) staffList[count].name + staffList[count].bonus

d) staffList[count].pay() e) staffList[count].pay(null)

f) staffList[count].toString() g) super.toString()

Answer group for G

a) Employee (eName, eAddress, ePhone, socSecNumber, rate)

b) Executive (eName, eAddress, ePhone, socSecNumber, rate)

c) super() d) super(eNa

10

You might also like