WorksheetsPROF. BUCALING'S FINAL EXAM - Fundamentals of Programming
Total questions: 50
Worksheet time: 30mins
You're organizing a birthday party and need to store the ages of 5 guests. Your friend suggests creating variables: guest1Age, guest2Age, guest3Age, guest4Age, guest5Age. What's the MAIN problem with this approach when you suddenly have 50 guests?
A) It uses too much memory
B) You'd need to write 50 separate variable declarations
C) The ages won't be stored properly
D) It's impossible to do calculations
You're building a library system. Books are stored in a shelf where the first book is at position 0, second at position 1, and so on. If a shelf has 10 books, what happens when someone asks for the book at position 10?
A) Returns the last book
B) Returns the first book
C) Returns null
D) System crashes with an error
A teacher wants to check if a student's name exists in a class list of 30 students. What information do you need to access ALL student names efficiently?
The first student's name only
The array name and a loop counter
The last index number
The teacher's permission
You're creating a seating chart for a movie theater. Each row has seats, and there are multiple rows. What type of storage structure represents this BEST?
A restaurant has a reservation system. If they declare String[] reservations = new String[20]; but only 15 people make reservations, what can you say about the array?
It will automatically shrink to size 15
It stays size 20 with 5 empty slots
It will cause an error
It will delete the last 5 reservations
You're tracking daily temperatures for a week. You store them as int[] temps = {32, 30, 28, 35, 33, 31, 29};. How do you find out how many days of data you have WITHOUT counting manually?
temps.size()
temps.length
temps.count()
temps.length()
A game developer stores player scores in an array. To display the third player's score, which index should they access?
A) 3
B) 2
C) 1
D) 0
You're making a contact list app. Users can add contacts, but after declaring String[] contacts = new String[100];, a user wants to add a 101st contact. What's true?
The array automatically expands
The last contact gets overwritten
You need to create a new larger array
The 101st contact goes to index 100
A chess board is 8x8. How would you properly declare an array to represent all squares?
int chess = new int[8,8];
int[][] chess = new int[8][8];
int[] chess = new int[64];
int chess[8][8];
You store exam scores: int[] scores = {85, 90, 78, 92, 88};. To calculate the class average, you need to add all scores and divide by what value?
A) 5
B) 4
C) scores.length
D) scores.size
A parking lot has 3 floors, each floor has 20 spots. You declare int[][] parking = new int[3][20];. To mark the 5th spot on the 2nd floor as occupied, what's the correct way?
parking[2][5] = 1;
parking[1][4] = 1;
parking[5][2] = 1;
parking[2][4] = 1;
You're storing student grades in double[] grades = new double[25];. A student asks to check their grade, and you accidentally access grades[25]. What happens?
Returns 0
Returns the last grade
Array-index-out-of-bounds error
Returns null
A store inventory system tracks items in different categories. Category A has 10 items, Category B has 15 items, Category C has 8 items. What's the most efficient declaration?
Three separate arrays of different sizes
One multidimensional array with equal dimensions
One long array with 33 items
Different arrays for each category
You initialize String[] names = {"Ana", "Ben", "Cat"}; and later try names[1] = "Bob"; What happens?
Error because arrays are immutable
"Ben" changes to "Bob" successfully
Both "Ben" and "Bob" are stored
The array rejects the change
A fitness app tracks workouts for 7 days. Each day has 3 metrics (duration, calories, distance). How many total values can be stored in int[][] fitness = new int[7][3];?
7
10
21
3
You're designing a banking system. A bank account has a balance, account number, and can perform deposits/withdrawals. What programming concept represents "performing deposits"?
State
Behavior
Identity
Class
A car manufacturing company needs to produce 1000 cars with the same specifications but different colors and serial numbers. What should they create FIRST?
1000 separate car designs
A blueprint (class) for the car
Individual car objects
A method to paint cars
You create a Student class with a method calculateGPA(). You want to use this method for 50 different students. What's the MAIN advantage?
Each student has unique GPA
You write the calculation logic only once
Students can share grades
The method runs faster
A social media app has a "Like" button. Every user can like posts. The action of clicking "Like" is a method that increases a counter. What makes this method useful across millions of users?
It's predefined in Java
Each user has a different like button
Reusability - same method for all users
It's synchronized
You're creating a Calculator class. You want a method to add two numbers and give you the result. What should you replace void with if the method is: void add(int a, int b)?
static
int
A food delivery app has restaurants. Each restaurant has a name, address, rating, and can accept orders. What represents the "identity" of a restaurant?
The name of the restaurant
The address
The unique reference that distinguishes it from others
The rating
You write a method: public void printReceipt(String item, double price). When calling this method, what are "Burger" and 5.99?
Parameters
Arguments
Variables
Objects
A hospital system has a Patient class. Creating a new patient record means you need to:
Modify the Patient class
Create an instance of the Patient class
Use a predefined method
Declare a new class
You create a method to check if a student passed: public boolean isPassed(int score). It should return true if score >= 75, false otherwise. What keyword must be inside this method?
void
return
static
break
A gaming company uses the same playSound() method for all sound effects. One day they fix a bug in this method. What happens?
Only new sounds are fixed
All sound effects are fixed everywhere
They need to fix each sound separately
Nothing changes
You have a Rectangle class with length and width values. These values represent the:
Area of the rectangle
Perimeter of the rectangle
Dimensions of the rectangle
Diagonal of the rectangle
A pizza ordering system has a method orderPizza(String size, String topping, int quantity). You call it as orderPizza("Large", "Pepperoni", 2);. What does String size represent?
A) Argument
B) Parameter
C) Object
D) Return value
You need to use Math.sqrt() to calculate square roots in your program. This method is:
User-defined
Predefined
Custom-made
Invalid
A login system checks usernames. The method is public void checkUser(String username). Users complain they don't know if login succeeded. What's wrong?
A) Missing parameters
B) Method doesn't return anything useful
C) Wrong data type
D) Needs more arguments
You're building a school system with classes for Teacher, Student, and Classroom. Each class represents a:
Method
Object
Template for creating objects
Instance
A chat application stores messages. Creating messages as String msg1 = "Hello"; and String msg2 = "Hello"; means:
You're building a text editor. Users type long documents that need constant editing (adding, removing, replacing text). What should you use?
String
StringBuffer
StringBuilder
char[]
An e-commerce site shows product reviews. One review says "This product is bad" and you want to change "bad" to "good". You need to replace characters at specific positions. What method does this?
concat()
replace()
substring()
split()
A messenger app shows typing indicators by adding dots: "Typing" → "Typing." → "Typing.." → "Typing...". What StringBuilder method efficiently adds these dots?
insert()
append()
concat()
add()
You create: String s1 = "Java"; and String s2 = new String("Java");. What's the difference?
No difference, both are identical
s1 reuses existing literal, s2 creates a new object
s2 is faster
s1 creates two objects
A password validator needs to check if a password meets requirements by examining each character. What method gets the character at a specific position?
getChar()
charAt()
characterAt()
get()
A social media username must be unique. The system needs to reverse the username for a special display feature. If the username is stored in a StringBuilder, what method reverses it?
reverse()
backwards()
flip()
invert()
You're creating a URL shortener. The original URL is https://example.com/very/long/path and you only need /very/long/path. What extracts this portion?
split()
substring()
replace()
charAt()
A text message app has a character limit. Before sending, you need to count characters in the message. What method does this?
size()
length()
count()
capacity()
You're building a search feature. When storing millions of search queries, you want to save memory by reusing identical strings. How should you create these strings?
Always use new String()
Use String literals
Use StringBuilder for each
Use char arrays
You created a program to calculate student grades. Teachers run it as java GradeCalc 85 90 78. What stores these three numbers?
Three separate int variables
The args array in main method
A Scanner object
System.in
A calculator program runs as java Calculator 15 7. You want to add these numbers, but args[0] + args[1] gives “157” instead of 22. Why?
Wrong operator
args stores everything as String
Calculator is broken
Need to use Scanner
An ATM system has a function to calculate interest. The formula never changes: same input always produces same output. What should the Deterministic property be?
FALSE
TRUE
MAYBE
NULL
You run: java Program Hello 123 World 456. What is args.length?
A) 3
B) 4
C) 5
D) 8
A company needs a custom function to calculate employee bonuses. They can't find this in Java's built-in methods. What should they create?
Predefined Function
User Defined Function
System Function
Static Method
Your program runs as java Test 42.5. To convert this to a decimal number for calculations, what should you use?
Integer.parseInt()
Float.parseFloat()
Double.parseDouble()
String.toDouble()
A temperature converter accepts Celsius from command line: java TempConverter 25. Inside the program, args[0] is:
int 25
double 25.0
String "25"
You create a function calculateTax that must process data from a database source. The function MUST execute on that source server, not locally. What pushdown option?
ALLOWED
NEVER
REQUIRED
OPTIONAL
A function name in your program is public void 123Start(). What's wrong?
Nothing, it's valid
Function names can't start with numbers
Missing return type
void is incorrect
You run a quiz program: java Quiz 10 20 30 40. To access the third number, what's the correct code?
args[3]
args[2]
args.get(3)
args.get(2)
