This method must:
- Return how many even numbers exist from 1 to
n(inclusive) - Return
0ifnis less than 1
The code contains a wrong edge-case return value, an off-by-one error in the loop bound, and an assignment used instead of a comparison. Fix all of them.
public static int countEvens(int n) {}This method must:
- Return the largest value in the array
- Return
Integer.MIN_VALUEif the array is null or empty
Fix the two null/empty checks and the loop bound error.
public static int findMax(int[] arr) {}This method must return a category string based on the age:
| Age Range | Category |
|---|---|
| Outside 0–120 | "Invalid" |
| 0 – 12 | "Child" |
| 13 – 17 | "Teen" |
| 18 – 64 | "Adult" |
| 65 – 120 | "Senior" |
Fill in the blank conditions and ensure the ranges do not overlap.
public static String classifyAge(int age) {}Complete the method body so that it:
- Returns the number of uppercase letters (
A–Z) in the string - Returns
0for a null or empty string
No starter code is provided — write the full method body.
public static int countUpperCase(String s) {}Please answer these in answers.txt. Do not remove the comments and do not change the format.
You have just started at a small dev agency in Cape Town. A junior colleague is frustrated because their setup "just uses Notepad" and they keep losing track of errors until they try to run the code. Your team lead asks you to send that colleague a quick written explanation of what an IDE is and why the whole team uses one instead of a plain text editor.
Write that explanation. Cover what an IDE is, two or three specific features that make it valuable day-to-day, and name at least two IDEs a Java developer might use.
You are working alone on a small project. You have been making changes for three days without committing. You accidentally delete a file that contained two days of work and cannot undo it. A senior developer looks at your repository and says: "This is why we commit regularly."
Explain to a friend who has never used Git how version control would have prevented this disaster. Your explanation should touch on what version control is and why it exists, what a commit is and why you make them often, and the role of a remote repository (like GitHub) as a backup.
Your team is a group of four students working on a shared Java project. One person compiles with javac from the terminal, another uses an IDE button, a third downloaded a library JAR manually and placed it in a random folder, and nobody can run each other's code without fixing paths first.
Write a short internal team note making the case for adopting Maven. Cover what a build tool is and what problem it solves, how Maven manages dependencies so nobody downloads JARs manually, and the three Maven commands the team would use most — with a one-line explanation of each.
A classmate is looking at a Student class and sees this:
public Student() { ... }
public Student(String name, int age) { ... }They ask: "Why is there a method with the same name as the class? And why are there two of them — isn't that just duplicate code?"
Explain constructors to your classmate. Cover what a constructor does and how it differs from a regular method, the difference between a default and a parameterised constructor, and give one reason why you would define your own instead of relying on the default.
Your team is building a library management system. A teammate suggests tracking everything with three parallel arrays at the top of the program — one for book titles, one for authors, and one for availability status.
Using this library system as your example throughout, explain OOP and argue why it is a better approach than parallel arrays. Your answer should cover what OOP is and the core idea behind it, what a class is and how it acts as a blueprint (using a Book class as your example), and the difference between a class and an object/instance — with a concrete example.