Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Ettah P BANDA R202891C

Whycliff Banda R202894C

Brandon ngoma R209893H

Panganai nyarugwe R2024548P

Panashe zigarwi R209629R

Brian zanje R203005T

Question 1

package customerdetail;

import java.util.Scanner;

public class customerdetail{

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

// Capture customer details

System.out.print("Enter customer name: ");

String customerName = scanner.nextLine();


System.out.print("Enter customer ID: ");

String customerId = scanner.nextLine();

System.out.print("Enter previous meter reading: ");

int previousReading = scanner.nextInt();

System.out.print("Enter current meter reading: ");

int currentReading = scanner.nextInt();

import java.util.Scanner;

public class BillCalculation {

// Calculate bill

int unitsConsumed = currentReading - previousReading;

double billAmount = calculateBill(unitsConsumed);

// Display bill

System.out.println("\nElectricity Bill");

System.out.println("Customer Name: " + customerName);

System.out.println("Customer ID: " + customerId);

System.out.println("Units Consumed: " + unitsConsumed);

System.out.println("Bill Amount: $" + billAmount);

scanner.close();

Question 2

Using aggregation
package customer;

public class Customer {

private String name;

private String address;

private double unitsConsumed;

public Customer(String name, String address, double unitsConsumed) {

this.name = name;

this.address = address;

this.unitsConsumed = unitsConsumed;

public String getName() {

return name;

public String getAddress() {

return address;

public double getUnitsConsumed() {

return unitsConsumed;

*/

package customer;

import customer.Customer;
/**

* @author PC

*/

public class Bill {

public class BillCalculator {

private static final double UNIT_RATE = 0.10; // Rate per unit consumed

public double calculateBill(Customer customer) {

double unitsConsumed = customer.getUnitsConsumed();

double billAmount = unitsConsumed * UNIT_RATE;

return billAmount;

package customer;

/**

* @author PC

*/

import customer.Customer;

import customer.bill;

import customer.bill.BillCalculator;

public class Main {


public static void main(String[] args) {

// Create a customer object

Customer customer = new Customer("John Doe", "123 Main St", 100.5);

// Calculate the bill for the customer

double billAmount = Bill.calculateBill(customer);

// Display the bill amount

System.out.println("Customer: " + customer.getName());

System.out.println("Address: " + customer.getAddress());

System.out.println("Units consumed: " + customer.getUnitsConsumed());

System.out.println("Bill amount: $" + billAmount);

You might also like