@@ -315,11 +315,12 @@ public class TransactionInfo : IComparable<TransactionInfo>
315315 public DateOnly Date { get ; set ; }
316316 public TimeOnly Time { get ; set ; }
317317 public double Amount { get ; set ; }
318- public string Description { get ; set ; }
319- public string TransactionType { get ; set ; }
318+ public string Description { get ; set ; } = string . Empty ;
319+ public string TransactionType { get ; set ; } = string . Empty ;
320320
321- public int CompareTo ( TransactionInfo other )
321+ public int CompareTo ( TransactionInfo ? other )
322322 {
323+ if ( other == null ) return 1 ;
323324 int dateComparison = Date . CompareTo ( other . Date ) ;
324325 if ( dateComparison == 0 )
325326 {
@@ -328,306 +329,3 @@ public int CompareTo(TransactionInfo other)
328329 return dateComparison ;
329330 }
330331}
331-
332-
333-
334-
335-
336- // public class SimulateDepositsWithdrawalsTransfers
337- // {
338- // public static BankCustomer SimulateActivityDateRange(DateOnly startDate, DateOnly endDate, BankCustomer bankCustomer)
339- // {
340- // // Determine the starting day, month, and year
341- // int startDay = startDate.Day;
342- // int startMonth = startDate.Month;
343- // int startYear = startDate.Year;
344-
345- // // Determine the ending day, month, and year
346- // int endDay = endDate.Day;
347- // int endMonth = endDate.Month;
348- // int endYear = endDate.Year;
349-
350- // DateOnly currentDate = startDate;
351-
352- // // Call SimulateActivityForPeriod if the startDate is not the first day of the month
353- // if (startDay != 1)
354- // {
355- // DateOnly lastDayOfMonth = new DateOnly(startYear, startMonth, DateTime.DaysInMonth(startYear, startMonth));
356- // bankCustomer = SimulateActivityForPeriod(startDate, lastDayOfMonth, bankCustomer);
357-
358- // // Update the currentDate to the first day of the next month
359- // currentDate = lastDayOfMonth.AddDays(1);
360- // }
361-
362- // // Need to compare the month and year of the start and end dates
363- // DateOnly firstDayFirstFullMonth = new DateOnly(currentDate.Year, currentDate.Month, 1);
364- // DateOnly lastDayOfFirstFullMonth = new DateOnly(currentDate.Year, currentDate.Month, DateTime.DaysInMonth(currentDate.Year, currentDate.Month));
365- // DateOnly firstDayLastMonth = new DateOnly(endYear, endMonth, 1);
366- // DateOnly lastDayOfLastMonth = new DateOnly(endYear, endMonth, DateTime.DaysInMonth(endYear, endMonth));
367-
368-
369- // // If the first day of the current month and the first day of the last month are the same, then the remaining date range is exactly one month
370- // if (firstDayFirstFullMonth == firstDayLastMonth && lastDayOfFirstFullMonth == lastDayOfLastMonth)
371- // {
372- // // Call SimulateActivityForPeriod once
373- // bankCustomer = SimulateActivityForPeriod(currentDate, endDate, bankCustomer);
374- // }
375- // else
376- // {
377- // // Call SimulateActivityForPeriod for each full month in the date range
378- // DateOnly currentMonth = firstDayFirstFullMonth;
379- // while (currentMonth < firstDayLastMonth)
380- // {
381- // DateOnly lastDayOfMonth = new DateOnly(currentMonth.Year, currentMonth.Month, DateTime.DaysInMonth(currentMonth.Year, currentMonth.Month));
382- // bankCustomer = SimulateActivityForPeriod(currentMonth, lastDayOfMonth, bankCustomer);
383- // currentMonth = currentMonth.AddMonths(1);
384- // }
385-
386- // // Call SimulateActivityForPeriod for the remaining days in the last month
387- // bankCustomer = SimulateActivityForPeriod(firstDayLastMonth, endDate, bankCustomer);
388- // }
389-
390- // // Return the updated bankCustomer
391- // return bankCustomer;
392- // }
393-
394- // private static BankCustomer SimulateActivityForPeriod(DateOnly startDate, DateOnly endDate, BankCustomer bankCustomer)
395- // {
396- // foreach (BankAccount account in bankCustomer.Accounts)
397- // {
398- // if (account.AccountType == "Savings")
399- // {
400- // SavingsAccount savingsAccount = (SavingsAccount)account;
401- // savingsAccount.ResetWithdrawalLimit();
402- // }
403- // }
404-
405- // double[] monthlyExpenses = ReturnMonthlyExpenses();
406-
407- // double semiMonthlyPaycheck = monthlyExpenses[0];
408- // double transferToSavings = monthlyExpenses[1];
409- // double rent = monthlyExpenses[2];
410- // double entertainment1 = monthlyExpenses[3];
411- // double entertainment2 = monthlyExpenses[4];
412- // double entertainment3 = monthlyExpenses[5];
413- // double entertainment4 = monthlyExpenses[6];
414- // double monthlyGasElectric = monthlyExpenses[7];
415- // double monthlyWaterSewer = monthlyExpenses[8];
416- // double monthlyWasteManagement = monthlyExpenses[9];
417- // double monthlyHealthClub = monthlyExpenses[10];
418- // double creditCardBill = monthlyExpenses[11];
419-
420- // double minCheckingBalance = 1000.00;
421- // double maxCheckingBalance = 5000.00;
422- // double transferToChecking = 2000.00;
423-
424- // DateOnly dateMiddleWeekday = new DateOnly(startDate.Year, startDate.Month, 14);
425- // if (dateMiddleWeekday.DayOfWeek == DayOfWeek.Saturday)
426- // {
427- // dateMiddleWeekday = dateMiddleWeekday.AddDays(2);
428- // }
429- // else if (dateMiddleWeekday.DayOfWeek == DayOfWeek.Sunday)
430- // {
431- // dateMiddleWeekday = dateMiddleWeekday.AddDays(1);
432- // }
433-
434- // DateOnly dateFinalWeekday = new DateOnly(endDate.Year, endDate.Month, DateTime.DaysInMonth(endDate.Year, endDate.Month));
435- // if (dateFinalWeekday.DayOfWeek == DayOfWeek.Saturday)
436- // {
437- // dateFinalWeekday = dateFinalWeekday.AddDays(-1);
438- // }
439- // else if (dateFinalWeekday.DayOfWeek == DayOfWeek.Sunday)
440- // {
441- // dateFinalWeekday = dateFinalWeekday.AddDays(-2);
442- // }
443-
444- // // deposit semi-monthly paychecks at the middle and end of the month
445- // if (dateMiddleWeekday >= startDate && dateMiddleWeekday <= endDate)
446- // {
447- // bankCustomer.Accounts[0].Deposit(semiMonthlyPaycheck, dateMiddleWeekday, new TimeOnly(12, 00), "Bi-monthly salary deposit");
448- // }
449- // if (dateFinalWeekday >= startDate && dateFinalWeekday <= endDate)
450- // {
451- // bankCustomer.Accounts[0].Deposit(semiMonthlyPaycheck, dateFinalWeekday, new TimeOnly(12, 00), "Bi-monthly salary deposit");
452- // }
453-
454- // // withdraw rent payment on the first day of the month
455- // DateOnly rentDueDate = new DateOnly(startDate.Year, startDate.Month, 1);
456- // if (startDate <= rentDueDate && rentDueDate <= endDate)
457- // {
458- // bankCustomer.Accounts[0].Withdraw(rent, rentDueDate, new TimeOnly(12, 00), "Rent payment");
459- // }
460-
461- // DateOnly saturday1 = new DateOnly(startDate.Year, startDate.Month, 1);
462- // while (saturday1.DayOfWeek != DayOfWeek.Saturday)
463- // {
464- // saturday1 = saturday1.AddDays(1);
465- // }
466- // DateOnly saturday2 = saturday1.AddDays(7);
467- // DateOnly saturday3 = saturday2.AddDays(7);
468- // DateOnly saturday4 = saturday3.AddDays(7);
469-
470- // // withdraw entertainment expenses on the first four Saturdays of the month
471- // if (saturday1 >= startDate && saturday1 <= endDate)
472- // {
473- // bankCustomer.Accounts[0].Withdraw(entertainment1, saturday1, new TimeOnly(21, 00), "Debit card purchase");
474- // //public virtual bool Withdraw(double amount, DateOnly transactionDate, TimeOnly transactionTime, string description)
475- // }
476- // if (saturday2 >= startDate && saturday2 <= endDate)
477- // {
478- // bankCustomer.Accounts[0].Withdraw(entertainment2, saturday2, new TimeOnly(21, 00), "Debit card purchase");
479- // }
480- // if (saturday3 >= startDate && saturday3 <= endDate)
481- // {
482- // bankCustomer.Accounts[0].Withdraw(entertainment3, saturday3, new TimeOnly(21, 00), "Debit card purchase");
483- // }
484- // if (saturday4 >= startDate && saturday4 <= endDate)
485- // {
486- // bankCustomer.Accounts[0].Withdraw(entertainment4, saturday4, new TimeOnly(21, 00), "Debit card purchase");
487- // }
488-
489- // // withdraw monthly bill payments on the 20th of the month
490- // DateOnly billPayDate = new DateOnly(startDate.Year, startDate.Month, 20);
491- // if (billPayDate >= startDate && billPayDate <= endDate)
492- // {
493- // bankCustomer.Accounts[0].Withdraw(monthlyGasElectric, billPayDate, new TimeOnly(12, 00), "Auto-pay gas and electric bill");
494- // bankCustomer.Accounts[0].Withdraw(monthlyWaterSewer, billPayDate, new TimeOnly(12, 00), "Auto-pay water and sewer bill");
495- // bankCustomer.Accounts[0].Withdraw(monthlyWasteManagement, billPayDate, new TimeOnly(12, 00), "Auto-pay waste management bill");
496- // bankCustomer.Accounts[0].Withdraw(monthlyHealthClub, billPayDate, new TimeOnly(12, 00), "Auto-pay health club membership");
497- // }
498-
499- // DateOnly monday1 = new DateOnly(startDate.Year, startDate.Month, 1);
500- // while (monday1.DayOfWeek != DayOfWeek.Monday)
501- // {
502- // monday1 = monday1.AddDays(1);
503- // }
504- // DateOnly monday2 = monday1.AddDays(7);
505- // DateOnly monday3 = monday2.AddDays(7);
506- // DateOnly monday4 = monday3.AddDays(7);
507-
508- // double weeklyCash = 400.00;
509- // // withdraw weekly expenses on the first four Mondays of the month
510- // if (monday1 >= startDate && monday1 <= endDate)
511- // {
512- // bankCustomer.Accounts[0].Withdraw(weeklyCash, monday1, new TimeOnly(8, 00), "Withdraw for expenses");
513- // }
514- // if (monday2 >= startDate && monday2 <= endDate)
515- // {
516- // bankCustomer.Accounts[0].Withdraw(weeklyCash, monday2, new TimeOnly(8, 00), "Withdraw for expenses");
517- // }
518- // if (monday3 >= startDate && monday3 <= endDate)
519- // {
520- // bankCustomer.Accounts[0].Withdraw(weeklyCash, monday3, new TimeOnly(8, 00), "Withdraw for expenses");
521- // }
522- // if (monday4 >= startDate && monday4 <= endDate)
523- // {
524- // bankCustomer.Accounts[0].Withdraw(weeklyCash, monday4, new TimeOnly(8, 00), "Withdraw for expenses");
525- // }
526-
527- // // withdraw credit card bill payment on the last workday of the month
528- // if (dateFinalWeekday >= startDate && dateFinalWeekday <= endDate)
529- // {
530- // bankCustomer.Accounts[0].Withdraw(creditCardBill, dateFinalWeekday, new TimeOnly(12, 00), "Auto-pay credit card bill");
531- // }
532-
533- // // deposit refund for overcharge on the 5th of the month
534- // DateOnly refundDate = new DateOnly(startDate.Year, startDate.Month, 5);
535- // if (refundDate >= startDate && refundDate <= endDate)
536- // {
537- // bankCustomer.Accounts[1].Deposit(100.00, refundDate, new TimeOnly(12, 00), "Refund for overcharge -(BANK REFUND)");
538- // }
539-
540- // DateOnly feeDate1 = new DateOnly(startDate.Year, startDate.Month, 3);
541- // DateOnly feeDate2 = new DateOnly(startDate.Year, startDate.Month, 10);
542-
543- // // withdraw monthly fee on the 3rd and 10th of the month
544- // if (feeDate1 >= startDate && feeDate1 <= endDate)
545- // {
546- // bankCustomer.Accounts[0].Withdraw(50.00, feeDate1, new TimeOnly(12, 00), "-(BANK FEE)");
547- // }
548- // if (feeDate2 >= startDate && feeDate2 <= endDate)
549- // {
550- // bankCustomer.Accounts[0].Withdraw(50.00, feeDate2, new TimeOnly(12, 00), "-(BANK FEE)");
551- // }
552-
553- // // evaluate checking account balance at the end of the month and transfer funds as needed
554- // DateOnly dateFinalDayOfMonth = new DateOnly(endDate.Year, endDate.Month, DateTime.DaysInMonth(endDate.Year, endDate.Month));
555- // if (startDate <= dateFinalDayOfMonth && dateFinalDayOfMonth <= endDate)
556- // {
557- // if (bankCustomer.Accounts[0].Balance <= minCheckingBalance)
558- // {
559- // bool transferSavingsToChecking = bankCustomer.Accounts[1].Transfer(bankCustomer.Accounts[0], transferToChecking, dateFinalDayOfMonth, new TimeOnly(12, 00), "Transfer from savings to checking account");
560- // if (transferSavingsToChecking != true)
561- // {
562- // // Running out of money in Savings account?
563- // }
564- // }
565- // else if (bankCustomer.Accounts[0].Balance >= maxCheckingBalance)
566- // {
567- // bool transferSavingsToChecking = bankCustomer.Accounts[0].Transfer(bankCustomer.Accounts[1], transferToSavings, dateFinalDayOfMonth, new TimeOnly(12, 00), "Transfer from checking to savings account");
568- // if (transferSavingsToChecking != true)
569- // {
570- // // Need to contact the bank?
571- // }
572- // }
573- // }
574-
575- // return bankCustomer;
576- // }
577-
578- // static double[] ReturnMonthlyExpenses()
579- // {
580- // Random random = new Random();
581-
582- // // Generate a salary paycheck amount. Calculate a random salary amount between 2000 and 5000.
583- // double semiMonthlyPaycheck = random.Next(3000, 4000);
584-
585- // // Generate a default transfer that's 25% of the salary paycheck amount rounded down to nearest 100.
586- // double transferToSavings = Math.Floor(semiMonthlyPaycheck * 0.25 / 100) * 100;
587-
588- // // Generate a rent amount using random value between 800 and 1000 plus 30% of a paycheck.
589- // double rent = random.Next(1800, 2000) + semiMonthlyPaycheck * 0.3;
590-
591- // // Generate four random entertainment expense amounts between 150 and 220.
592- // double entertainment1 = random.Next(150, 220);
593- // double entertainment2 = random.Next(150, 220);
594- // double entertainment3 = random.Next(150, 220);
595- // double entertainment4 = random.Next(150, 220);
596-
597- // // Generate a monthly gas and electric bill using a random number between 100 and 150.
598- // double monthlyGasElectric = random.Next(100, 150);
599-
600- // // Generate a monthly water and sewer bill using a random number between 80 and 90.
601- // double monthlyWaterSewer = random.Next(80, 90);
602-
603- // // Generate a monthly waste management bill using a random number between 60 and 70.
604- // double monthlyWasteManagement = random.Next(60, 70);
605-
606- // // Generate a monthly health club membership bill using a random number between 120 and 160.
607- // double monthlyHealthClub = random.Next(120, 160);
608-
609- // // Generate a random credit card bill between 1000 and 1500 plus 30% of a paycheck.
610- // double creditCardBill = random.Next(500, 800) + semiMonthlyPaycheck * 0.25;
611-
612- // // Create an array with the monthly expenses
613- // double[] monthlyExpenses = new double[]
614- // {
615- // semiMonthlyPaycheck,
616- // transferToSavings,
617- // rent,
618- // entertainment1,
619- // entertainment2,
620- // entertainment3,
621- // entertainment4,
622- // monthlyGasElectric,
623- // monthlyWaterSewer,
624- // monthlyWasteManagement,
625- // monthlyHealthClub,
626- // creditCardBill
627- // };
628-
629- // return monthlyExpenses;
630- // }
631- // }
632-
633-
0 commit comments