// /// <summary> /// to find out which resident paid the least amount /// </summary> /// <param name="residentlist"></param> /// <param name="servicelist"></param> /// <returns></returns> public static Resident LeastPaid(ResidentList residentlist, ServiceList servicelist) { residentlist.Beginning(); Resident temp = residentlist.Get(); Resident resident = new Resident(); Resident residents = new Resident(); double temp1 = Calcs.HowMuchPaid(temp, servicelist); double temp2 = 0; if (residentlist.getCount() == 1) { residents = new Resident(residentlist.Get().Name, residentlist.Get().Surname, servicelist.Get().Title, residentlist.Get().Month); return(residents); } for (residentlist.Beginning(); residentlist.Exist(); residentlist.Next()) { temp2 = Calcs.HowMuchPaid(residentlist.Get(), servicelist); if (temp2 < temp1) { resident = new Resident(residentlist.Get().Name, residentlist.Get().Surname, servicelist.Get().Title, residentlist.Get().Month); temp1 = temp2; } } return(resident); }
/// <summary> /// method to find the average price of the service paid by the residents /// </summary> /// <param name="residentlist"></param> /// <param name="servicelist"></param> /// <returns></returns> public static double AveragePrice(ResidentList residentlist, ServiceList servicelist) { double average = 0; double sum = Calcs.TotalAmountPaid(residentlist, servicelist); average = sum / residentlist.getCount(); return(average); }
/// <summary> /// method to find the total sum of paid cash by the residents /// </summary> /// <param name="residentlist"></param> /// <param name="servicelist"></param> /// <returns></returns> public static double TotalAmountPaid(ResidentList residentlist, ServiceList servicelist) { double amount = 0; for (residentlist.Beginning(); residentlist.Exist(); residentlist.Next()) { amount += HowMuchPaid(residentlist.Get(), servicelist); } return(amount); }
/// <summary> /// method to find out how much did the resident pay /// </summary> /// <param name="resident"></param> /// <param name="servicelist"></param> /// <returns></returns> public static double HowMuchPaid(Resident resident, ServiceList servicelist) { for (servicelist.Beginning(); servicelist.Exist(); servicelist.Next()) { if (resident.ServiceId == servicelist.Get().ID) { return(resident.Amount * servicelist.Get().Price); } } return(0); }
/// <summary> /// to find out which resident didnt pay for the chosen month /// </summary> /// <param name="residentlist"></param> /// <param name="servicelist"></param> /// <param name="month"></param> /// <returns></returns> public static ResidentList DidntPay(ResidentList residentlist, ServiceList servicelist, string month, string serviceid) { ResidentList notpaidservices = new ResidentList(); for (residentlist.Beginning(); residentlist.Exist(); residentlist.Next()) { if (residentlist.Get().Month != month || residentlist.Get().ServiceId != serviceid) { notpaidservices.PutData(residentlist.Get()); } } return(notpaidservices); }
/// <summary> /// to find the list of the residents who paid less than average for the services /// </summary> /// <param name="residentlist"></param> /// <param name="servicelist"></param> /// <returns></returns> public static ResidentList PaidLessThanAvg(ResidentList residentlist, ServiceList servicelist) { ResidentList residentaverage = new ResidentList(); residentlist.Beginning(); double avg = Calcs.AveragePrice(residentlist, servicelist); residentlist.Beginning(); for (residentlist.Beginning(); residentlist.Exist(); residentlist.Next()) { if (Calcs.HowMuchPaid(residentlist.Get(), servicelist) < avg) { residentaverage.PutData(residentlist.Get()); } } return(residentaverage); }
/// <summary> /// printing initial data to txt /// </summary> /// <param name="services">services</param> public static void PrintServices(ServiceList services) { string file = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "App_Data"); services.Beginning(); List <string> lines = new List <string>(); lines.Add("Initial data \nServices:"); lines.Add(new string('-', services.Get().StringFormat().Length)); lines.Add(services.Get().StringFormat()); lines.Add(new string('-', services.Get().StringFormat().Length)); for (services.Beginning(); services.Exist(); services.Next()) { lines.Add(services.Get().ToString()); } services.Beginning(); lines.Add(new string('-', services.Get().StringFormat().Length)); File.AppendAllLines((file + "/Rezultatai.txt"), lines); }
/// <summary> /// Method to read services from data file /// </summary> /// <param name="path">path to the file</param> /// <returns></returns> public static ServiceList ReadServices(string path) { ServiceList servicelist = new ServiceList(); using (StreamReader reader = new StreamReader(path)) { string line = null; while (null != (line = reader.ReadLine())) { string[] Values = line.Split(';'); string ID = Values[0]; string Title = Values[1]; double Price = double.Parse(Values[2]); Service service = new Service(ID, Title, Price); servicelist.PutData(service); } } return(servicelist); }
/// <summary> /// inserting services to table /// </summary> /// <param name="table"></param> /// <param name="services"></param> public static void InsertServices(Table table, ServiceList services) { for (services.Beginning(); services.Exist(); services.Next()) { Service temp = services.Get(); TableCell servid = new TableCell(); TableCell servname = new TableCell(); TableCell servprice = new TableCell(); servid.Text = temp.ID; servname.Text = temp.Title; servprice.Text = temp.Price.ToString(); TableRow row = new TableRow(); row.Cells.Add(servid); row.Cells.Add(servname); row.Cells.Add(servprice); table.Rows.Add(row); } }