static void Main(string[] args) { studentStats[] bestKidsEver = new studentStats[maxStudent]; cohortStats[] bestYearEver = new cohortStats[maxCohort]; int currentCohort = minMatriculation; welcome(); //populates a studentStats array for (int i = 0; i < maxStudent; i++) { bestKidsEver[i] = generateStudent(); } //tests each student in studentStats array for (int i = 0; i < maxStudent; i++) { Console.WriteLine("Testing studentStat class for lucky student #" + i); testStudentStats(bestKidsEver[i]); } Console.WriteLine("Press Enter to Continue..."); pause(); //populates a cohortStats array for (int i = 0; i < maxCohort; i++) { bestYearEver[i] = generateCohort(bestKidsEver, currentCohort); currentCohort++; } currentCohort = minMatriculation; for (int i = 0; i < maxCohort; i++) { Console.WriteLine("Testing cohortStats class for lucky cohort of year: " + currentCohort); if (bestYearEver[i].empty()) { Console.WriteLine("Whoops. I guess no one matriculated that year."); currentCohort++; } else { testCohortStats(bestYearEver[i], currentCohort); currentCohort++; } } goodbye(); Console.WriteLine("Press Enter to Continue..."); pause(); }
static studentStats generateStudent() { Random debtStatData = new Random(); int newID = debtStatData.Next(); double[] theseLoans = new double[numDegrees]; double[] theseGrants = new double[numDegrees]; int[] theseStartYrs = new int[numDegrees]; int[] theseGrdYrs = new int[numDegrees]; int tempGrants = 0; int tempLoans = 0; //generates a random array of possible grants for (int i = 0; i < numDegrees; i++) { tempGrants = debtStatData.Next(minGrants, maxGrants); theseGrants[i] = (double)tempGrants; } //generates a random array of possible loans for (int i = 0; i < numDegrees; i++) { tempLoans = debtStatData.Next(minLoans, maxLoans); theseLoans[i] = (double)tempLoans; } //generates a random array of possible matriculation years for (int i = 0; i < numDegrees; i++) { theseStartYrs[i] = debtStatData.Next(minMatriculation, maxMatriculation + 1); } //generates a random array of possble grad years for (int i = 0; i < numDegrees; i++) { theseGrdYrs[i] = debtStatData.Next(minGrad, maxGrad); } studentStats newStudent = new studentStats(newID); for (int i = 0; i < numDegrees; i++) { newStudent.addDegree(theseStartYrs[i], theseGrdYrs[i], theseLoans[i], theseGrants[i]); } return(newStudent); }
static void testCohortStats(cohortStats testCohort, int cohortYear) { studentStats testStudent = generateStudent(); double oldBurden = 0; double newBurden = 0; Console.WriteLine("Data has already been preloaded. Testing if empty: "); if (testCohort.empty()) { Console.WriteLine("True"); } else { Console.WriteLine("False"); } Console.WriteLine("Test for most burden: " + testCohort.findMostBurden()); Console.WriteLine("Test for least burden: " + testCohort.findLeastBurden()); Console.WriteLine("Test for numDeactive: " + testCohort.numDeactive()); oldBurden = testCohort.totalLoans(); Console.WriteLine("Test for total Burden: " + oldBurden); Console.WriteLine("Test for adding student: "); while (testStudent.checkMatriculation(cohortYear) == false) { testStudent = generateStudent(); } newBurden = testCohort.totalLoans(); if (newBurden > oldBurden) { Console.WriteLine("The loan total has increased, meaning add was successful."); } else { Console.WriteLine("The loan total has not increased, meaning add was unsuccessful."); } }
//preconditions: grad year must match the cohort's //postconditions: new student added, cohort list may be full public bool addStudent(studentStats newStudent) { if (newStudent.checkMatriculation(matriculation)) { if (currentStudent == students.Length) { Array.Resize(ref students, students.Length + moreSlots); } students[currentStudent] = newStudent; currentStudent++; return(true); } else { return(false); } }
static void testStudentStats(studentStats testStudent) { Random debtStatData = new Random(); int tempLoans = debtStatData.Next(minLoans, maxLoans); int tempGrants = debtStatData.Next(minGrants, maxGrants); double newGrants = (double)tempGrants; double newLoans = (double)tempLoans; int newMatriculation = debtStatData.Next(minMatriculation, maxMatriculation); int newGradYear = debtStatData.Next(minGrad, maxGrad); double oldBurden = 0; double newBurden = 0; Console.WriteLine("Data has already been preloaded. Testing if empty: "); if (testStudent.isEmpty()) { Console.WriteLine("True"); } else { Console.WriteLine("False"); } Console.WriteLine("Test for most burden: " + testStudent.checkMostBurden()); Console.WriteLine("Test for least burden: " + testStudent.findLeastBurden()); Console.WriteLine("Test for numDeactive: " + testStudent.numDeactive()); Console.WriteLine("Test for default on biggest loan: "); if (testStudent.anyActive()) { testStudent.defaultMostBurden(); } Console.WriteLine("numDeactive is now: " + testStudent.numDeactive()); Console.WriteLine("Previous Biggest Loan now inactive. Biggest Loan is now: " + testStudent.checkMostBurden()); oldBurden = testStudent.totalLoans(); Console.WriteLine("Test for total burden:" + oldBurden); Console.WriteLine("Test for adding degree:"); testStudent.addDegree(newMatriculation, newGradYear, newLoans, newGrants); newBurden = testStudent.totalLoans(); if (oldBurden < newBurden) { Console.WriteLine("The loan total has increased, meaning add was successful."); } else { Console.WriteLine("The loan total has not increased, meaning add was unsuccessful."); } }