Сделала, но все равно неправильно генерируются исключения
| Код | using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace _1Б_задание_4 { class Data { public double Year { get; set; } public double Month { get; set; } public double Day { get; set; } public void setYear(double y) {
Year = y;
if (y < 1600) { throw new System.ArgumentException("Parameter cannot be null", "original"); }
}
public void setMonth(double m) { Month = m;
if (m > 12) { throw new System.ArgumentException("Parameter cannot be null", "original"); }
} public void setDay(double d) { Day = d;
if ((((Year % 4) == 0) && (Month == 2)) || (Day > 29)) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if ((((Year % 4) == 1) && (Month == 2)) || (Day > 28)) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if ((((Year % 4) == 2) && (Month == 2)) || (Day > 28)) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if ((((Year % 4) == 3) && (Month == 2)) || (Day > 28)) { throw new System.ArgumentException("Parameter cannot be null", "original"); }
}
static void Main() { int[] myArr = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int[] myArray = new int[12]; myArray[0] = 31; myArray[1] = 28; myArray[2] = 31; myArray[3] = 30; myArray[4] = 31; myArray[5] = 30; myArray[6] = 31; myArray[7] = 31; myArray[8] = 30; myArray[9] = 31; myArray[10] = 30; myArray[11] = 31; int i; double t = 0; double t1; Data data1 = new Data(); Console.WriteLine("Введите год");
double y = Convert.ToDouble(Console.ReadLine()); data1.setYear(y); Data data2 = new Data(); Console.WriteLine("Введите месяц");
double m = Convert.ToDouble(Console.ReadLine()); data2.setMonth(m);
Data data3 = new Data(); Console.WriteLine("Введите день");
double d = Convert.ToDouble(Console.ReadLine()); data3.setDay(d); if (myArray[0] < d) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if (myArray[1] < d) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if (myArray[2] < d) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if (myArray[3] < d) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if (myArray[4] < d) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if (myArray[5] < d) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if (myArray[6] < d) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if (myArray[7] < d) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if (myArray[8] < d) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if (myArray[9] < d) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if (myArray[10] < d) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if (myArray[11] < d) { throw new System.ArgumentException("Parameter cannot be null", "original"); } if ((y % 4) == 0) { myArr[2] = 29; for (i = 0; i < m; i++) { t = t + myArr[i]; } t1 = t + d;
Console.WriteLine(t1); } else { for (i = 0; i < m; i++) { t = t + myArr[i]; } t1 = t + d;
Console.WriteLine(t1); }
} } }
|
|