Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

CST8116: Introduction to Computer - Programming Final Exam Questions Study Sheet | Answered 100% Updated 2026.

Rating
-
Sold
-
Pages
36
Grade
A+
Uploaded on
27-02-2026
Written in
2025/2026

CST8116: Introduction to Computer - Programming Final Exam Questions Study Sheet | Answered 100% Updated 2026.

Content preview

CST8116: Introduction to Computer - Programming Final Exam Questions Study Sheet
Prepared by: Anas Sadek
Program: Computer Programming, Algonquin College
Date: April 2025



Table of Contents
• Pages 2–4: Long Answer Questions
• Pages 5–16: Long Answers with Detailed Explanations
• Pages 17–37: Multiple Choice Questions (MCQs)


Notes:
• Each long answer includes a detailed explanation for better understanding.
• Long answer solutions are presented on separate pages for clarity.
• MCQ answers are provided immediately after each question for ease of review.




Long Answer Practice Questions (25 Questions)

1 | Page

,1. [Custom Class Construction]
Write a Java class Book with private fields title (String) and pages (int). Include a
default constructor, an overloaded constructor, accessor and mutator methods,
and a method printDetails() that returns a formatted string containing both fields.

2. [Array Processing]
Write a method called printMax() that accepts an array of integers and prints the
maximum value. Assume the array contains at least one value.

3. [Array Processing]
Implement a method countEvenNumbers(int[] values) that prints the number of
even values in the given array.

4. [Varargs and Method Overloading]
Write a class with two overloaded methods sum(). One method takes an array of
integers as a parameter, and the other uses varargs. Both return the total sum.

5. [Memory Map Analysis]
Given the declaration Person p = new Person("Ali");, followed by p = null;, draw
and explain a memory map showing the state of the variable and heap before and
after assigning null.

6. [Encapsulation and Design Flaws]
Review the following class with public fields. Identify the design issues and
rewrite it using proper encapsulation:

public class Item {

public String name;

public int quantity;

}

7. [UML Class Diagram]
Design a UML class diagram for a Student class that includes fields for name, ID
number, and GPA. Include appropriate accessors, mutators, and a method to
display the student’s information.

8. [Method Design]
Create a method that receives two String arguments and returns a new String
that combines them with a hyphen in between (e.g., "first-second").

9. [String Equality]
Explain the difference between using == and .equals() when comparing Strings in
Java. Provide examples where each behaves differently.

10. [Loop Tracing]
Trace the following code and explain the output:
2 | Page

, int total = 0;

for (int i = 1; i <= 5; i++) {

total += i;

}

System.out.println(total);



11. [Object-Oriented Design]
Design a Car class with attributes make, model, and year. Include a constructor,
accessors, mutators, and a display() method. Then write a short main method to
create a Car object and print its data.

12. [Command Line Arguments]
Write a program that accepts two command line arguments: a first name and an
age. Display a greeting using both. Include error handling for missing or invalid
inputs.

13. [Method Behavior]
Write a method reverseArray(int[] arr) that reverses the contents of an array in-
place. Include appropriate loop logic and a test case in main.

14. [Reference Semantics]
Explain what happens when an array is passed to a method in Java. Include an
example showing that the method can modify the original array.

15. [Wrapper Classes and Autoboxing]
Describe what autoboxing and unboxing mean in Java. Provide a code example
where an Integer object is used in a context expecting an int.

16. [Formatting Output]
Write a Java method that prints a person’s name and GPA using
System.out.printf(), showing the GPA with 2 decimal places.

17. [Debugging Logic]
Given a loop that doesn’t terminate as expected, identify and fix the bug:

int i = 10;

while (i >= 0) {

System.out.println(i);

}




3 | Page

, 18. [Nested If Statements]
Write a Java method that accepts a score (0–100) and prints a grade: A for 90+, B
for 80–89, etc., using nested if/else statements.

19. [Switch Case Fall-Through]
Explain how switch-case fall-through works in Java. Write a switch example where
missing a break causes unexpected output.

20. [Scanner and Input Validation]
Write code using Scanner that asks the user to enter a number between 1 and 10.
Keep prompting until the user enters a valid number.

21. [Array of Objects]
Create an array of 3 Person objects, where Person has name and age fields.
Initialize the array, then write a loop that prints each person’s name and age.

22. [Scope of Variables]
Explain what variable scope means in Java. Give an example showing how a
variable declared in a method differs from one declared inside a loop.

23. [Static vs Instance Members]
Describe the difference between static and instance variables/methods. Provide
an example of a static counter used to count how many objects of a class were
created.

24. [Loop Filtering Logic]
Write a method that prints only the odd numbers from a given array using a for
loop and an if-statement.

25. [Design Flaws in a Class]
The following class performs printing in a getter. Identify the design issue and
rewrite it using better practices:

public class Fruit {

private String variety;

public String getVariety() {

System.out.println(variety);

return variety;

}

}



Answers and Detailed Explanations

4 | Page

Document information

Uploaded on
February 27, 2026
Number of pages
36
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

CA$17.74
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
elam17799 Brighton College
View profile
Follow You need to be logged in order to follow users or courses
Sold
22
Member since
1 year
Number of followers
1
Documents
206
Last sold
1 week ago
Explore thousands of course and professor reviews

Explore thousands of course and professor reviews from Canada Universities and Colleges students. Feel free to inbox me for any paper you wish to have.

3.7

3 reviews

5
0
4
2
3
1
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions