Package Controller

Class StaffController

java.lang.Object
Controller.StaffController

public class StaffController extends Object

StaffController Class

The StaffController class provides methods for managing and retrieving utility bills.

This class contains methods for viewing all bills, viewing bills for a specific user, and calculating the total price of all bills.

Usage Example:

 
 // Test viewAllBills
 ArrayList allBills = viewAllBills();
 printBills(allBills, "All Bills:");

 // Test viewUserBills
 String usernameToView = "hakeem_doe"; // Replace with actual username
 ArrayList userBills = viewUserBills(usernameToView);
 printBills(userBills, "Bills for User " + usernameToView + ":");

 // Test calculateTotalPrice
 double totalPrice = calculateTotalPrice();
 System.out.println("Total Price for All Bills: " + totalPrice);
 
 
See Also:
  • Field Details

    • writtenBills

      private static WrittenBills writtenBills

      Static WrittenBills Object

      The static WrittenBills object is used to manage and store utility bills in the application.

      This object is instantiated as a static member of the StaffController class and serves as a central repository for utility bills. It provides methods to add, retrieve, and manage utility bills.

      Usage Example:

       
       private static WrittenBills writtenBills = new WrittenBills();
       
       
      See Also:
  • Constructor Details

    • StaffController

      public StaffController()
  • Method Details

    • main

      public static void main(String[] args)

      Main Method for Testing

      The main method of the StaffController class is used for testing various functionalities of the class.

      It demonstrates how to use the following methods for testing purposes:

      The testing examples show how to retrieve and display utility bills for all users and a specific user. The calculated total price is also displayed.

      Usage Example:

       
       public static void main(String[] args) {
           // Test viewAllBills
           ArrayList allBills = viewAllBills();
           printBills(allBills, "All Bills:");
      
           // Test viewUserBills
           String usernameToView = "hakeem_doe"; // Replace with actual username
           ArrayList userBills = viewUserBills(usernameToView);
           printBills(userBills, "Bills for User " + usernameToView + ":");
      
           // Test calculateTotalPrice
           double totalPrice = calculateTotalPrice();
           System.out.println("Total Price for All Bills: " + totalPrice);
       }
       
       
      Parameters:
      args - The command-line arguments (not used in this method).
      See Also:
    • viewAllBills

      public static ArrayList<UtilityBill> viewAllBills()

      View All Utility Bills

      Retrieves a list of all utility bills stored in the application.

      This method accesses the WrittenBills object to retrieve a list of all utility bills. It provides a convenient way to view and access all bills stored in the application.

      Usage Example:

       
       ArrayList allBills = viewAllBills();
       
       
      Returns:
      An ArrayList of UtilityBill objects representing all the utility bills.
      See Also:
    • viewUserBills

      public static ArrayList<UtilityBill> viewUserBills(String username)

      View Utility Bills for a User

      Retrieves a list of utility bills for a specific user.

      This method takes a username as a parameter and retrieves a list of utility bills associated with that user from the WrittenBills object. It creates a new ArrayList to store the user's bills and populates it with the matching utility bills.

      Usage Example:

       
       String usernameToView = "hakeem_doe"; // Replace with the actual username
       ArrayList userBills = viewUserBills(usernameToView);
       
       
      Parameters:
      username - The username of the user for whom the bills are to be retrieved.
      Returns:
      An ArrayList of UtilityBill objects representing the utility bills for the specified user.
      See Also:
    • calculateTotalPrice

      public static double calculateTotalPrice()

      Calculate Total Price of Utility Bills

      Calculates the total price of all utility bills stored in the application.

      This method iterates through the list of utility bills stored in the WrittenBills object and calculates the total price by summing the prices of all the bills. It provides a way to determine the overall cost of all utility bills in the system.

      Usage Example:

       
       double totalPrice = calculateTotalPrice();
       System.out.println("Total Price for All Bills: " + totalPrice);
       
       
      Returns:
      The total price of all utility bills as a double value.
      See Also:
    • printBills

      public static void printBills(ArrayList<UtilityBill> bills, String title)

      Print Utility Bills

      Prints a list of utility bills to the console with a specified title.

      This method takes a list of utility bills and a title as parameters, and it prints the bills to the console in a formatted manner. Each bill's details, such as ID, username, utility type, meter measurement, price, and date, are displayed.

      Usage Example:

       
       ArrayList allBills = viewAllBills(); // Retrieve the list of bills
       printBills(allBills, "All Bills:"); // Print the list with a title
       
       
      Parameters:
      bills - The ArrayList of UtilityBill objects to be printed.
      title - The title to be displayed before the list of bills.
      See Also: