C# Project - Do Exercise #2b (but you will need to read 2a also) here: 2a) Creat
ID: 3765741 • Letter: C
Question
C# Project - Do Exercise #2b (but you will need to read 2a also) here: 2a) Create a program named InvoiceExceptionDemo that attempts to create several valid and invalid Invoice objects. Immediately after each instantiation attempt, handle any thrown exceptions by displaying an error message. Create an Invoice class with three fields for an ID number, balance due, and day due. The Invoice constructor requires values for each field. Upon construction, throw an ArgumentException if the ID number is less than 100 or more than 999, or if the day due is not between 1 and 31 inclusive. And your assignment 2b) Create a program named InvoiceExceptionDemo that attempts to create several valid and invalid Invoice objects. Immediately after each instantiation attempt, handle any thrown exceptions by displaying an error message. Create an Invoice class with three fields for an ID number, balance due, and day due. The Invoice constructor requires values for each field. Upon construction, throw anArgumentException if the ID number is less than 100 or more than 999, or if the day due is not between 1 and 31 inclusive.
Explanation / Answer
using System;
namespace InvoiceExceptionDemo
{
class Invoice
{
int IDnumber;
int balance_due;
int day_due;
Invoice( )
{
IDnumber =100;
balance_due = 0;
day_due = 1;
}
public void check(int n1, int n2, int n3)
{
try
{
if ( n1 >100 && n1<900)
{
Console.WriteLine(“Id is:”, n1);
}
}
catch(Exception e)
{
Console.WriteLine(“you have entered a wrong ID. Please enter an Id in between 100 to 900”, e);
}
try
{
if( n3 >=1 && n3 <= 31)
Console.WriteLine(“days due are:”, n3);
}
catch(Exception e1)
{
Console.WriteLine(“You have entered wrong number of days due. Please enter days due in between 1 to 31”, e1);
}
}
static void Main (string [] args)
{
Invoice i= new Invoice( );
i.check( 50, 1000, 35);
Console.ReadKey( );
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.