Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. public void report_year(List<Account> list1) {
  2. int current_year = 2017; //Current year of the bank
  3. int max_year = 4; //How many year to check
  4. int count_4 = 0; //Count how many 4 years acc
  5. foreach (Account x in list1) { //Init loop
  6. string first_date = x.date; //x.date assign to first_date for easier to do thing
  7. string[] date_split = first_date.Split('-'); //Split between text with ' - ' and then add each one to Array
  8. int date_selected = Int32.Parse(date_split[2]); //[20,6,2011] select the 3rd as it is the year and then convert to Int andddd then assign to date_selected
  9. int cal_date = current_year - date_selected; //Calculate
  10. if (cal_date > max_year) { //Check if it is more than 4 year
  11. Console.WriteLine("Account that has more than 4 year : "+x.name); //Write Name
  12. count_4++; //Increase counter
  13. }
  14.  
  15. }
  16. Console.WriteLine("Number of account with more than 4 year of banking : " + count_4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement