Question: Heya I'm working on an assignment for class using C# and I'm having a bit of trouble getting this to work and would like any

Heya I'm working on an assignment for class using C# and I'm having a bit of trouble getting this to work and would like any advice you guys may have, thank you.

"Create an application that reads the records from the attached file of loan information. The application must calculate the average for each of the following columns: loan_amnt, int_rate, installment, and annual_inc. The averages should then be displayed to the user on the console. Construct a class to represent a record in the file and house the code for reading and parsing the records."

Program class

using System; using System.Collections.Generic; using System.Text; using System.IO;

namespace thomasns_pa3 { class Program { static void Main(string[] args) { StreamReader reader = new StreamReader("LoanData.csv"); string buffer;

buffer = reader.ReadLine(); while (!reader.EndOfStream) { Loans MyTransaction = new Loans(); MyTransaction.ReadCsv(reader);

// Processing //total += MyTransaction.Amt;

//Console.WriteLine("TransId: {0} DeptNo: {1} Amt: {2}", transId, deptNo, amt); //MyTransaction.Print(); }

reader.Close();

Pause(); }

private static void Pause() { Console.Write("Press any key to continue..."); Console.ReadKey(); } } }

Loans class

using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace thomasns_pa3 { class Loans { private static int loansCounter = 0;

public static int LoansCounter { get => loansCounter; set => loansCounter = value; }

// Autoimplemented properties public int Loan_Amount { get; set; } public string Term { get; set; } public double Int_Rate { get; set; } public double Installment { get; set; } public int Grade { get; set; } public string Home_Ownership { get; set; } public int Annual_Inc { get; set; }

// Default constructor public Loans() { } // Console Printout public void Print() { Console.WriteLine("-------------- Loans ---------------"); Console.WriteLine(" Loan Amount: {0}", Loan_Amount); Console.WriteLine(" Interest Rate: {0}", Int_Rate); Console.WriteLine(" Installment: {0}", Installment); Console.WriteLine(" Annual incurment: {0}", Annual_Inc); Console.WriteLine("------------------------------------------"); }

// Reads a record from a CSV file public void ReadCsv(StreamReader reader) { string buffer; string[] parts;

// Get record from file buffer = reader.ReadLine();

// Break record into components parts = buffer.Split(',');

// Convert field values to variable Loan_Amount = Convert.ToInt32(parts[0]); Term = Convert.ToString(parts[1]); Int_Rate = Convert.ToDouble(parts[2]); Installment = Convert.ToDouble(parts[3]); Grade = Convert.ToInt32(parts[4]); Home_Ownership = Convert.ToString(parts[5]); Annual_Inc = Convert.ToInt32(parts[6]);

} } }

Part of the CSV file for example

loan_amnt,term,int_rate,installment,grade,home_ownership,annual_inc,loan_status,purpose,addr_state 5000, 36 months,10.65%,162.87,B,RENT,24000,Fully Paid,credit_card,AZ 2500, 60 months,15.27%,59.83,C,RENT,30000,Charged Off,car,GA 2400, 36 months,15.96%,84.33,C,RENT,12252,Fully Paid,small_business,IL 10000, 36 months,13.49%,339.31,C,RENT,49200,Fully Paid,other,CA 3000, 60 months,12.69%,67.79,B,RENT,80000,Fully Paid,other,OR 5000, 36 months,7.90%,156.46,A,RENT,36000,Fully Paid,wedding,AZ 7000, 60 months,15.96%,170.08,C,RENT,47004,Fully Paid,debt_consolidation,NC 3000, 36 months,18.64%,109.43,E,RENT,48000,Fully Paid,car,CA 5600, 60 months,21.28%,152.39,F,OWN,40000,Charged Off,small_business,CA 5375, 60 months,12.69%,121.45,B,RENT,15000,Charged Off,other,TX 6500, 60 months,14.65%,153.45,C,OWN,72000,Fully Paid,debt_consolidation,AZ 12000, 36 months,12.69%,402.54,B,OWN,75000,Fully Paid,debt_consolidation,CA 9000, 36 months,13.49%,305.38,C,RENT,30000,Charged Off,debt_consolidation,VA 3000, 36 months,9.91%,96.68,B,RENT,15000,Fully Paid,credit_card,IL 10000, 36 months,10.65%,325.74,B,RENT,100000,Charged Off,other,CA 1000, 36 months,16.29%,35.31,D,RENT,28000,Fully Paid,debt_consolidation,MO 10000, 36 months,15.27%,347.98,C,RENT,42000,Fully Paid,home_improvement,CA 3600, 36 months,6.03%,109.57,A,MORTGAGE,110000,Fully Paid,major_purchase,CT 6000, 36 months,11.71%,198.46,B,MORTGAGE,84000,Fully Paid,medical,UT 9200, 36 months,6.03%,280.01,A,RENT,77385.19,Fully Paid,debt_consolidation,CA 20250, 60 months,15.27%,484.63,C,RENT,43370,Fully Paid,debt_consolidation,TX 21000, 36 months,12.42%,701.73,B,RENT,105000,Charged Off,debt_consolidation,FL 10000, 36 months,11.71%,330.76,B,OWN,50000,Fully Paid,credit_card,TX 10000, 36 months,11.71%,330.76,B,RENT,50000,Fully Paid,debt_consolidation,CA 6000, 36 months,11.71%,198.46,B,RENT,76000,Charged Off,major_purchase,CA 15000, 36 months,9.91%,483.38,B,MORTGAGE,92000,Fully Paid,credit_card,IL 15000, 36 months,14.27%,514.64,C,RENT,60000,Charged Off,debt_consolidation,NY 5000, 60 months,16.77%,123.65,D,RENT,50004,Charged Off,other,PA 4000, 36 months,11.71%,132.31,B,MORTGAGE,106000,Fully Paid,debt_consolidation,FL 8500, 36 months,11.71%,281.15,B,RENT,25000,Fully Paid,credit_card,MN 4375, 36 months,7.51%,136.11,A,MORTGAGE,17108,Fully Paid,debt_consolidation,NY 31825, 36 months,7.90%,995.82,A,MORTGAGE,75000,Fully Paid,debt_consolidation,NJ 10000, 60 months,15.96%,242.97,C,RENT,29120,Fully Paid,debt_consolidation,FL 5000, 36 months,8.90%,158.77,A,RENT,24044,Fully Paid,debt_consolidation,OR 7000, 36 months,15.96%,245.97,C,RENT,34000,Fully Paid,credit_card,CA 12400, 36 months,10.65%,403.91,B,RENT,41000,Fully Paid,credit_card,KY 10800, 36 months,9.91%,348.03,B,RENT,55596,Fully Paid,moving,CA 15000, 36 months,7.90%,469.36,A,RENT,45000,Fully Paid,debt_consolidation,OH 6000, 36 months,12.42%,200.5,B,RENT,36852,Fully Paid,debt_consolidation,AZ 12500, 60 months,12.69%,282.44,B,RENT,27000,Fully Paid,debt_consolidation,IL 9600, 36 months,7.51%,298.67,A,RENT,68004,Fully Paid,other,SC 12000, 36 months,7.90%,375.49,A,RENT,62300,Fully Paid,debt_consolidation,NJ 3000, 36 months,18.25%,108.84,D,MORTGAGE,65000,Fully Paid,other,PA

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!