In: Computer Science
C# windows application form. Create a base class to store characteristics about a loan. Include customer details in the Loan base class such as name, loan number, and amount of loan. Define subclasses of auto loan and home loan. Include unique characteristics in the derived classes. For example you might include details about the specific auto in the auto loan class and details about the home in the home loan class. Create a presentation class to test your design by displaying information about both types of loans
using System;
class Loan
{
//data variables
private string customerName;
private int loanNumber;
private double amount;
//constructor
public Loan(){}
public Loan(string customerName,int loanNumber,double
amount)
{
this.customerName =
customerName;
this.loanNumber = loanNumber;
this.amount = amount;
}
//properties
public String CustomerName
{
set{customerName = value;}
get{return customerName;}
}
public int LoanNumber
{
set{loanNumber = value;}
get{return loanNumber;}
}
public double Amount
{
set{amount = value;}
get{return amount;}
}
}
class AutoLoan:Loan
{
private int autoNumber;
private String make;
//constructor
public AutoLoan(){}
public AutoLoan(string customerName,int
loanNumber,double amount,int autoNumber,String
make):base(customerName,loanNumber,amount)
{
this.autoNumber = autoNumber;
this.make = make;
}
//properties
public int AutoNumber
{
set{autoNumber = value;}
get{return autoNumber;}
}
public String Make
{
set{make = value;}
get{return make;}
}
}
class HomeLoan:Loan
{
private string homeAddress;
//constructor
public HomeLoan(){}
public HomeLoan(string customerName,int
loanNumber,double amount,string homeAddress):
base(customerName,loanNumber,amount)
{
this.homeAddress =
homeAddress;
}
//properties
public String HomeAddress
{
set{homeAddress = value;}
get{return homeAddress;}
}
}
public class Test
{
public static void Main()
{
Console.WriteLine("Enter Customer
Name : ");
string cname =
Console.ReadLine();
Console.WriteLine("Enter Loan
Number : ");
int lno =
Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Amount :
");
double amount =
Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the type
<1:Auto Loan 2: Home Loan>");
int type =
Convert.ToInt32(Console.ReadLine());
if(type ==1)
{
Console.WriteLine("Enter Auto
Number : ");
int autono =
Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter make :
");
string make =
Console.ReadLine();
AutoLoan al = new
AutoLoan(cname,lno,amount,autono,make);
Console.WriteLine("Auto Loan
Details :"+al.CustomerName + "\nloan number :"+al.LoanNumber
+"\nAmount :"+ al.Amount+"\nAuto Number :"+al.AutoNumber +"\nMake
:"+al.Make);
}
else if(type == 2)
{
Console.WriteLine("Enter home
address : ");
string haddress =
Console.ReadLine();
HomeLoan hl = new
HomeLoan(cname,lno,amount,haddress);
Console.WriteLine("Home Loan
Details :"+ "\ncustomer:"+hl.CustomerName + "\nloan number
:"+hl.LoanNumber +"\nAmount :"+ hl.Amount+"\nHome address :"+
hl.HomeAddress);
}
else
Console.WriteLine("Wrong
type");
}
}
output:
Enter Customer Name : John Smith Enter Loan Number : 87655 Enter Amount : 12000 Enter the type <1:Auto Loan 2: Home Loan> Enter home address : #23,hillside,NJ Home Loan Details :
customer:John Smith loan number :87655 Amount :12000 Home address :#23,hillside,NJ