Level 6 — Programming — Nov/Dec 2024 — Practical

Level 6 • November/December 2024 • Practical assessment

Work through each question before checking the answer. These revision answers are prepared for learners; they are not an official marking scheme.

Question 1

Task1: Create the student-fee calculator for annual feesKSh90000 using the five scholarship/loan bands.

Answer

Band Scholarship Loan
1 15000 22000
2 25000 25000
3 35000 27000
4 45000 29000
5 55000 31000

Save as StudentFees.java.

import java.util.Scanner;
public class StudentFees {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Admission number: "); String admission = in.nextLine();
        System.out.print("Name: "); String name = in.nextLine();
        int band;
        while (true) {
            System.out.print("Band (1-5): ");
            try { band = Integer.parseInt(in.nextLine()); }
            catch (NumberFormatException ex) { continue; }
            if (band >= 1 && band <= 5) break;
        }
        int[] scholarship = {15000, 25000, 35000, 45000, 55000};
        int[] loan = {22000, 25000, 27000, 29000, 31000};
        int award = scholarship[band - 1] + loan[band - 1];
        int student = 90000 - award;
        System.out.printf("Admission: %s%nName: %s%nBand: %d%n", admission, name, band);
        System.out.printf("Scholarship: %d%nLoan: %d%nGovernment total: %d%nStudent fees: %d%n",
            scholarship[band - 1], loan[band - 1], award, student);
    }
}
Step-by-step calculation

  1. Example band3: scholarship35000 and loan27000.
  2. Government-funded total =35000+27000=62000.
  3. Student balance =90000−62000=KSh28000.

These are the exercise’s supplied amounts, not a statement of current government funding policy.

Question 2

Task2: Create water billing with readings, units, litres, standing charge150 and rate15 per unit.

Answer

Save as WaterBill.java.

import java.util.Scanner;
public class WaterBill {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Customer ID: "); String id = in.nextLine();
        System.out.print("Previous reading: "); double previous = in.nextDouble();
        System.out.print("Current reading: "); double current = in.nextDouble();
        if (!Double.isFinite(previous) || !Double.isFinite(current) ||
            previous < 0 || current < previous) {
            System.out.println("Invalid meter readings"); return;
        }
        double units = current - previous;
        double litres = units * 1000;
        double standingCharge = 150;
        double bill = standingCharge + units * 15;
        System.out.printf("ID: %s%nPrevious: %.2f%nCurrent: %.2f%n", id, previous, current);
        System.out.printf("Units: %.2f%nLitres: %.2f%nStanding charge: %.2f%nTotal: %.2f%n",
            units, litres, standingCharge, bill);
    }
}
Step-by-step calculation

  1. Illustration: previous120, current132.
  2. Units=132−120=12; litres=12×1000=12000.
  3. Usage charge=12×15=180; total=150+180=KSh330.
Case Expected
Equal readings Zero usage; billKSh150
Current below previous Reject; do not produce a negative bill
12 units 12000litres and billKSh330