0% found this document useful (0 votes)
0 views

Program 16

The document outlines a Boiler Monitoring System implemented in C#. It includes a Boiler class that checks temperature, pressure, and water level against predefined thresholds, raising alerts when limits are exceeded. The program allows user input for these parameters and subscribes to alerts to display warning messages.

Uploaded by

krishgenshin4444
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Program 16

The document outlines a Boiler Monitoring System implemented in C#. It includes a Boiler class that checks temperature, pressure, and water level against predefined thresholds, raising alerts when limits are exceeded. The program allows user input for these parameters and subscribes to alerts to display warning messages.

Uploaded by

krishgenshin4444
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

namespace BoilerMonitoringSystem
{
// Event arguments to pass alert details
public class AlertEventArgs : EventArgs
{
public string Message { get; }
public AlertEventArgs(string message) => Message = message;
}

// Boiler class with event handling


public class Boiler
{
// Thresholds
private const int MAX_TEMP = 100; // Maximum temperature in °C
private const int MAX_PRESSURE = 200; // Maximum pressure in PSI
private const int MAX_WATER_LEVEL = 80; // Maximum water level percentage

// Event declaration
public event EventHandler<AlertEventArgs> Alert;

// Function to check boiler parameters


public void CheckBoiler(int temp, int pressure, int waterLevel)
{
if (temp > MAX_TEMP)
OnAlert(new AlertEventArgs($"⚠️ Temperature too high!
({temp}°C)"));

if (pressure > MAX_PRESSURE)


OnAlert(new AlertEventArgs($"⚠️ Pressure exceeded limit!
({pressure} PSI)"));

if (waterLevel > MAX_WATER_LEVEL)


OnAlert(new AlertEventArgs($"⚠️ Water level too high! ({waterLevel}
%)"));
}

// Event trigger function


protected virtual void OnAlert(AlertEventArgs e)
{
Alert?.Invoke(this, e); // Raise the event
}
}

class Program
{
static void Main()
{
Boiler boiler = new Boiler();

// Subscribe to Alert event


boiler.Alert += (sender, e) => Console.WriteLine(e.Message);

// Get user input


Console.Write("Enter Temperature (°C): ");
int temp = Convert.ToInt32(Console.ReadLine());

Console.Write("Enter Pressure (PSI): ");


int pressure = Convert.ToInt32(Console.ReadLine());

Console.Write("Enter Water Level (%): ");


int waterLevel = Convert.ToInt32(Console.ReadLine());

// Check boiler safety


boiler.CheckBoiler(temp, pressure, waterLevel);

Console.WriteLine("Monitoring complete.");
}
}
}

You might also like