C# windows application form. Create a base class to store characteristics about
ID: 3791890 • Letter: C
Question
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
Explanation / Answer
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 + " loan number :"+al.LoanNumber +" Amount :"+ al.Amount+" Auto Number :"+al.AutoNumber +" Make :"+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 :"+ " customer:"+hl.CustomerName + " loan number :"+hl.LoanNumber +" Amount :"+ hl.Amount+" Home address :"+ hl.HomeAddress);
}
else
Console.WriteLine("Wrong type");
}
}
output:
customer:John Smith loan number :87655 Amount :12000 Home address :#23,hillside,NJ
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.