In C Create a class named Customer that implements IComparab
In C#:
Create a class named Customer that implements IComparable interface.
Create 3 Customer class fields: Customer number, customer name, and amount due. Create automatic accessors for each field.
Create an Customer class constructor that takes parameters for all of the class fields and assigns the passed values through the accessors.
Create a default, no-argument Customer class constructor that will take no parameters and will cause default values of (9, \"ZZZ\", 0) to be sent to the 3-argument constructor.
Create an (override) Equals() method that determines two Customers are equal if they have the same Customer number.
Create an (override) GetHashCode() method that returns the Customer number.
Create an (override) ToString() method that returns a string containing the general Customer information (eg: CreditCustomer 1 russell AmountDue is $4,311.00 Interest rate is 0.01). Display the dollar amounts in currency format.
Implement CompareTo to compare object customer numbers for >, <, == to implement sorting for the array of objects.
Create a CreditCustomer class that derives from Customer and implements IComparable interface.
Create a class variable named Rate using an automatic accessor.
Create an CreditCustomer class constructor that takes parameters for the Customer class fields customer number, name, amount, and rate percent that sets the Rate CreditCustomer variable to the rate percentage. Pass the id number, name and amount back to the base Customer class constructor.
Create a default, no-argument CreditCustomer class constructor that will take no parameters and will cause default values of (0, \"\", 0, 0) to be sent to the 4-argument CreditCustomer constructor.
Create an (override) ToString() method that returns a string containing the general Customer information (eg: CreditCustomer 1 russell AmountDue is $4,311.00 Interest rate is 0.01 Monthly payment is $179.63). Display the dollar amounts in currency format.
Implement CompareTo to compare CreditCustomer objects based on customer numbers for >, <, == to implement sorting for the array of objects.
In Main:
Create an array of five CreditCustomer objects.
Prompt the user for values for each of the five Customer object; do NOT allow duplicate Customer numbers and force the user to reenter the Customer when a duplicate Customer number is entered.
CreditCustomer objects should be sorted by Customer number before they are displayed.
When the five valid Customers have been entered, display them all, display a total amount due for all Customers, display the same information again with the monthly payment for each customer. See the input/output example shown below.
Create a static GetPaymentAmounts method that will have the current Credit customer object as a parameter and returns a double value type. Each CreditCustomer monthly payment will be 1/24 of the balance (amount due). The computed monthly individual customer payment will be returned for each CreditCustomer object in the object array.
Internal Documentation.
Note that you will be overriding three object methods in the Customer class and one in the CreditCustomer class. Don\'t forget about IComparable.
An example of program output might look like this:
Enter customer number 3
 Enter name johnson
 Enter amount due 1244.50
 Enter interest rate .10
 Enter customer number 2
 Enter name jensen
 Enter amount due 543.21
 Enter interest rate .15
 Enter customer number 2
 Sorry, the customer number 2 is a duplicate.
 Please reenter 5
 Enter name swenson
 Enter amount due 6454.00
 Enter interest rate .11
 Enter customer number 1
 Enter name olson
 Enter amount due 435.44
 Enter interest rate .20
 Enter customer number 4
 Enter name olafson
 Enter amount due 583.88
 Enter interest rate .25
 
 Summary:
 
 CreditCustomer 1 olson AmountDue is $435.44 Interest rate is 0.2
 CreditCustomer 2 jensen AmountDue is $543.21 Interest rate is 0.15
 CreditCustomer 3 johnson AmountDue is $1,244.50 Interest rate is 0.1
 CreditCustomer 4 olafson AmountDue is $583.88 Interest rate is 0.25
 CreditCustomer 5 swenson AmountDue is $6,454.00 Interest rate is 0.11
 
 AmountDue for all Customers is $9,261.03
 
 Payment Information:
 
 CreditCustomer 1 olson AmountDue is $435.44 Interest rate is 0.2
 Monthly payment is $18.14
 CreditCustomer 2 jensen AmountDue is $543.21 Interest rate is 0.15
 Monthly payment is $22.63
 CreditCustomer 3 johnson AmountDue is $1,244.50 Interest rate is 0.1
 Monthly payment is $51.85
 CreditCustomer 4 olafson AmountDue is $583.88 Interest rate is 0.25
 Monthly payment is $24.33
 CreditCustomer 5 swenson AmountDue is $6,454.00 Interest rate is 0.11
 Monthly payment is $268.92
 Press any key to continue . . .
Solution
// Online URL for testing :http://ideone.com/PRB8cw
using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 //Create a class named Customer
 class Customer: IComparable < Customer > {
 //create 3 customer class fields: Customer number, Customer Name and amoutn due.
 //create automatic accessors for each field.
 public int customerNum {
 get;
 set;
 }
 public string customerName {
 get;
 set;
 }
 public double amountDue {
 get;
 set;
 }
 public Customer(int cusNum, string CusName, double amtDue) {
 customerNum = cusNum;
 customerName = CusName;
 amountDue = amtDue;
 }
 public Customer() {
 customerNum = 9;
 customerName = \"ZZZ\";
 amountDue = 0;
 }
public override String ToString() {
 return (GetType() + \" \" + customerNum + \" \" + customerName + \" AmountDue is \" + amountDue.ToString(\"C2\"));
 }
public override bool Equals(object e) {
 Customer temp = (Customer) e;
 return this.customerNum == temp.customerNum;
 }
 public override int GetHashCode() {
 return customerNum;
 }
 // Implement IComparable CompareTo to provide default sort order.
 public int CompareTo(Customer obj) {
 return -obj.customerNum.CompareTo(this.customerNum); //negative for asc sort order.
 }
 }
 class CreditCustomer: Customer, IComparable < CreditCustomer > {
 public double rate {
 get;
 set;
 }
 public CreditCustomer(int cusNum, string CusName, double amtDue, double rt) {
 rate = rt;
 customerNum = cusNum;
 customerName = CusName;
 amountDue = amtDue;
 }
 public CreditCustomer() {
 rate = 0;
 customerNum = 0;
 customerName = \"\";
 amountDue = 0;
 }
 public override String ToString() {
 return (GetType() + \" \" + customerNum + \" \" + customerName + \" AmountDue is \" + amountDue.ToString(\"C2\") + \" Interest Rate is \" + rate.ToString(\"C2\"));
 }
 public static double GetPaymentAmounts(CreditCustomer c) {
 double r = c.amountDue / 24;
 Console.WriteLine(\"Monthly payment is \" + r.ToString(\"C2\"));
 return r;
 }
 public int CompareTo(CreditCustomer obj) {
 return -obj.customerNum.CompareTo(this.customerNum); //negative for asc sort order.
 }
 }
 class MainCustomer {
 public static int MAX_CUSTOMER = 5;
 public static void Main(string[] args) {
 CreditCustomer[] list = new CreditCustomer[MAX_CUSTOMER];
 int i = 0;
 while (i < MAX_CUSTOMER) {
 list[i] = new CreditCustomer();
 Console.WriteLine(\"Enter the customer id = \");
 list[i].customerNum = Convert.ToInt32(Console.ReadLine());
 if (idExists(list[i].customerNum, list,i)) continue;
 Console.WriteLine(\"Enter the customer name = \");
 list[i].customerName = Console.ReadLine();
 Console.WriteLine(\"Enter the AmountDue = \");
 list[i].amountDue = Convert.ToDouble(Console.ReadLine());
 Console.WriteLine(\"Enter the Interest Rate = \");
 list[i].rate = Convert.ToDouble(Console.ReadLine());
 i++;
 }
 Array.Sort(list);
 displayAll(list);
 displayTotalDue(list);
 displayAllM(list);
 }
 static bool idExists(int id, CreditCustomer[] lst,int maxl) {
 for(int i=0;i<maxl;i++) {
 if (id == lst[i].customerNum) {
 Console.WriteLine(\"Sorry, the customer number \" + id + \" is a duplicate!\");
 return true;
 }
 }
 return false;
 }
 static void displayAll(CreditCustomer[] lst) {
 Console.WriteLine(\"Summary : \");
 foreach(CreditCustomer c in lst) {
 Console.WriteLine(c.ToString());
 }
}
 static void displayTotalDue(CreditCustomer[] lst) {
 double totDue = 0;
 foreach(CreditCustomer c in lst) {
 totDue += c.amountDue;
 }
 Console.WriteLine(\"AmountDue for all Customers is \" + totDue.ToString(\"C2\"));
 }
 static void displayAllM(CreditCustomer[] lst) {
 Console.WriteLine(\"Payment Information: \");
 foreach(CreditCustomer c in lst) {
 Console.WriteLine(c.ToString());
 double t = CreditCustomer.GetPaymentAmounts(c);
 }
 }
 }
Output:




