Using system;
Namespace wrox. procsharp. ooprog // The first program
{
Class mainentrypoint
{
Static void main ()
{
Authenticator myaccess = new authenticator ();
Bool done;
Done = myaccess. changepassword ("", "mynewpassword ");
If (done = true)
Console. writeline ("password for myaccess changed ");
Else
Console. writeline ("failed to change password for myaccess ");
Done = myaccess. changepassword ("", "anotherpassword ");
If (done = true)
Console. writeline ("password for myaccess changed ");
Else
Console. writeline ("failed to change password for myaccess ");
If (myaccess. ispasswordcorrect ("whatpassword "))
Console. writeline ("verified myaccess/'password ");
Else
Console. writeline ("failed to verify myaccess/'password ");
}
}
Public class authenticator
{
// Implementation as shown earlier
Private string Password = "";
Public bool ispasswordcorrect (string trypassword)
{
Return (trypassword = PASSWORD )? True: false;
}
Public bool changepassword (string oldpassword, string newpassword)
{
If (oldpassword = PASSWORD)
{
Password = newpassword;
Return true;
}
Else
Return false;
}
}
}
Using system;
Namespace wrox. procsharp. ooprog // The second program
{
Class mainentrypoint
{
Static void main ()
{
Authenticator myaccess = new authenticator ();
Bool done;
Done = myaccess. changepassword ("", "mynewpassword ");
If (done = true)
Console. writeline ("password for myaccess changed ");
Else
Console. writeline ("failed to change password for myaccess ");
Done = myaccess. changepassword ("", "anotherpassword ");
If (done = true)
Console. writeline ("password for myaccess changed ");
Else
Console. writeline ("failed to change password for myaccess ");
If (myaccess. ispasswordcorrect ("whatpassword "))
Console. writeline ("verified myaccess/'password ");
Else
Console. writeline ("failed to verify myaccess/'password ");
}
}
Public class authenticator
{
// Implementation as shown earlier
Private string Password = "";
Public bool ispasswordcorrect (string trypassword)
{
Return (trypassword = PASSWORD )? True: false;
}
Public bool changepassword (string oldpassword, string newpassword)
{
If (oldpassword = PASSWORD)
{
Password = newpassword;
Return true;
}
Else
Return false;
}
}
}
Namespace wrox. procsharp. ooprog
{
Using system;
Public Enum typeofcall
{
Calltocellphone, calltolandline
}
Public Class Customer
{
Private string name;
Private decimal balance;
Public string name
{
Get
{
Return name;
}
Set
{
Name = value;
}
}
Public decimal balance
{
Get
{
Return balance;
}
}
Public void recordpayment (decimal amountpaid)
{
Balance-= amountpaid;
}
Public void recordcall (typeofcall calltype, uint nminutes)
{
Switch (calltype)
{
Case typeofcall. calltolandline:
Balance + = (0.02 M * nminutes );
Break;
Case typeofcall. calltocellphone:
Balance + = (0.30 m * nminutes );
Break;
Default:
Break;
}
}
}
Public class mainentrypoint
{
Public static void main ()
{
Customer arabel = new customer ();
Arabel. Name = "arabel Jones ";
Customer mrjones = new customer ();
Mrjones. Name = "Ben Jones ";
Arabel. recordcall (typeofcall. calltolandline, 20 );
Arabel. recordcall (typeofcall. calltocellphone, 5 );
Mrjones. recordcall (typeofcall. calltolandline, 10 );
Console. writeline ("{0,-20} owes $ {1: F2}", arabel. Name, arabel. Balance );
Console. writeline ("{0,-20} owes $ {1: F2}", mrjones. Name, mrjones. Balance );
}
}
}
Namespace wrox. procsharp. ooprog
{
Using system;
Public Enum typeofcall
{
Calltocellphone, calltolandline
}
Public Class Customer
{
Private string name;
Protected decimal balance;
Public String getfunnystring ()
{
Return "plain ordinary customer. kaark! ";
}
Public string name
{
Get
{
Return name;
}
Set
{
Name = value;
}
}
Public decimal balance
{
Get
{
Return balance;
}
}
Public void recordpayment (decimal amountpaid)
{
Balance-= amountpaid;
}
Public Virtual void recordcall (typeofcall calltype, uint nminutes)
{
Switch (calltype)
{
Case typeofcall. calltolandline:
Balance + = (0.02 M * nminutes );
Break;
Case typeofcall. calltocellphone:
Balance + = (0.30 m * nminutes );
Break;
Default:
Break;
}
}
}
Public class nevermore60customer: customer
{
Private uint highcostminutesused;
Public New String getfunnystring ()
{
Return "nevermore60. nevermore! ";
}
Public override void recordcall (typeofcall calltype, uint nminutes)
{
Switch (calltype)
{
Case typeofcall. calltolandline:
Balance + = (0.02 M * nminutes );
Break;
Case typeofcall. calltocellphone:
Uint highcostminutes, lowcostminutes;
Uint highcostminutestogo =
(Highcostminutesused <60 )? 60-highcostminutesused: 0;
If (nminutes> highcostminutestogo)
{
Highcostminutes = highcostminutestogo;
Lowcostminutes = nminutes-highcostminutes;
}
Else
{
Highcostminutes = nminutes;
Lowcostminutes = 0;
}
Highcostminutesused + = highcostminutes;
Balance + = (0.50 m * highcostminutes + 0.20 m *
Lowcostminutes );
Break;
Default:
Break;
}
}
}
Public class mainentrypoint
{
Public static void main ()
{
Customer cust1;
Nevermore60customer cust2;
Cust1 = new customer ();
Console. writeline ("customer referencing Customer :"
+ Cust1.getfunnystring ());
Cust1 = new nevermore60customer ();
Console. writeline ("customer referencing nevermore60customer :"
+ Cust1.getfunnystring ());
Cust2 = new nevermore60customer ();
Console. writeline ("nevermore60customer referencing :"
+ Cust2.getfunnystring ());
}
}
}