MDCR Java 2025
MDCR Java 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.
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.
3
MDCRJava Final Exam 2025
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.
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.
4
MDCRJava Final Exam 2025
all subclasses.
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.
Name: Sam
Phone: 555-0469
Paid: 2923.0
[Program]
public class Firm {
5
MDCRJava Final Exam 2025
public Staff() {
(( )staffList[0]).awardBonus(500.00);
(( )staffList[2]).addHours(40);
double amount;
System.out.println(staffList[count]);
amount = ; // polymorphic
if (amount == 0.0)
System.out.println("Thanks!");
else
System.out.println("-----------------------------------");
6
MDCRJava Final Exam 2025
return result;
return 0.0; }
7
MDCRJava Final Exam 2025
socialSecurityNumber = socSecNumber;
payRate = rate;
socialSecurityNumber;
return result;
return payRate;
8
MDCRJava Final Exam 2025
bonus = 0;
bonus = execBonus; }
bonus = 0;
return payment;
hoursWorked = 0;
hoursWorked += moreHours }
hoursWorked = 0;
return payment;
9
MDCRJava Final Exam 2025
return result;
} }
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()
c) super() d) super(eNa
10