Answer to Question #47552 in C# for rabia

Question #47552
Design custom exception Handlers for a boiler class.Throw the custom exceptionBoilerException when the pressure is more than 2000 units or less than 500 units.It should have the following Members and Methods.
Members: double pressure
Methods: void Increase()
void Decrease()
1
Expert's answer
2014-10-08T01:05:46-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C_Sharp_Test
{
class Boiler
{
public const long MAxPressure = 2000;
public const long MINPressure = 500;
public Boiler()
{
pressure = (MAxPressure + MINPressure) / 2;
}
void Increase()
{
pressure++;
if (pressure > MAxPressure) throw new BoilerException("Too high pressure");
}

void Decrease()
{
pressure--;
if (pressure < MINPressure) throw new BoilerException("Too low pressure");
}
double pressure;
}
class BoilerException : Exception
{
public BoilerException()
: base()
{ }
public BoilerException(string message)
: base(message)
{ }
public BoilerException(string message, Exception innerException)
: base(message, innerException)
{ }
}

}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS