Time remaining 45:00
The BritishInternational School
www.bis.k12.tr
www.thebiscomputing.com
Formal Assessment

Java Programming

IGCSE Computer Science (0478) · Year Group Assessment
Time allowed45 minutes
Total marks50
LanguageJava (BufferedReader)
MaterialsNo IDE / no notes
Instructions.
  • Answer all questions. The marks for each question are shown in brackets.
  • All code must be written in Java, using BufferedReader br for input.
  • Work on your own. Use of an IDE, notes or the internet is not permitted.
  • Press Start Assessment to begin the 45-minute timer.
  • When you finish (or when time is called), press Finish & Save as PDF and choose “Save as PDF” to submit.
A

Multiple Choice

12 marks

Select the one correct answer. (1 mark each)

A1. What does Integer.parseInt(br.readLine()) do? [1]

A2. Output of System.out.println(17 % 5); [1]

A3. Output of System.out.println(17 / 5); [1]

A4. How many elements are in int[] t = {29, 31, 30, 28};? [1]

A5. Which condition is true when num is even? [1]

A6. Inside a loop, what does i++ do? [1]

A7. For a 5-element array, for(int i=0; i<arr.length; i++) visits indexes: [1]

A8. Which keyword prevents a value from being changed? [1]

A9. To check a balance is enough to withdraw an amount, the condition is: [1]

A10. Which loop is guaranteed to run at least once? [1]

A11. What is printed? int x=4; if(x>2 && x<10) ... "yes" ... else ... "no" [1]

A12. Which statement keeps a running total? [1]

B

True or False

6 marks

Decide whether each statement is true or false. (1 mark each)

B1. Integer.parseInt("12.5") works and gives 12. [1]
B2. if (x = 5) correctly compares x with 5 in Java. [1]
B3. In a do...while loop, the body runs before the condition is checked. [1]
B4. An array of size 6 has valid indexes 0 to 5. [1]
B5. total = total + arr[i]; is an example of totalling. [1]
B6. The operator && means OR. [1]
C

Predict the Output

8 marks

State exactly what each program prints. (2 marks each)

C1. [2]

int sum = 0;
for (int i = 1; i <= 4; i++) {
    sum = sum + i;
}
System.out.println(sum);

C2. [2]

int[] a = {3, 7, 2, 9, 5};
System.out.println(a[1] + a[3]);

C3. [2]

int count = 0;
int[] nums = {12, 5, 18, 3, 20};
for (int i = 0; i < nums.length; i++) {
    if (nums[i] > 10) {
        count++;
    }
}
System.out.println(count);

C4. [2]

int n = 3;
for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
        System.out.print(j);
    }
    System.out.println();
}
D

Find the Error

8 marks

Each snippet has a mistake. State the error and the correction. (2 marks each)

D1. [2]

if (denominator = 0) {
    System.out.println("Division by zero is not allowed.");
}

D2. [2]

for (int i = 1; i = rows; i +) {
    System.out.println(i);
}

D3. [2]

int[] sales = {95, 120, 85};
for (int i = 1; i <= sales.length; i++) {
    System.out.println(sales[i]);
}

D4. [2]

int i = 1;
do {
    System.out.println(i);
    i++;
} while (i = 5);
E

Programming

16 marks

Write complete Java programs using BufferedReader br for input. (8 marks each)

E1. Discount Calculation System. Read a purchase amount, then apply a discount:
• amount ≥ 5000 → 20% discount;
• amount 2000–4999 → 10% discount;
• otherwise → no discount.
Print the final amount the customer must pay. [8]

E2. Daily Temperature Tracker. Read the temperatures for 7 days into an array, then display the highest temperature and the average temperature for the week. [8]