You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.7 KiB

6 years ago
  1. // Test driver for the IncDate class
  2. // Do not make any changes to this file!
  3. // Xiwei Wang
  4. import java.util.*;
  5. import java.io.*;
  6. public class TestIncDate
  7. {
  8. public static void main(String[] args)
  9. {
  10. try
  11. {
  12. ObjectInputStream in = new ObjectInputStream(new FileInputStream("testDates.dat"));
  13. ArrayList<Date> oldDates;
  14. ArrayList<Integer> daysList;
  15. ArrayList<Date> newDates;
  16. oldDates = (ArrayList<Date>)in.readObject();
  17. daysList = (ArrayList<Integer>)in.readObject();
  18. newDates = (ArrayList<Date>)in.readObject();
  19. IncDate myDate;
  20. int numCorrect = 0;
  21. for (int i = 0; i < oldDates.size(); i++)
  22. {
  23. System.out.println("The current date is " + oldDates.get(i) + " and " + daysList.get(i) + " days are added.");
  24. myDate = new IncDate(oldDates.get(i));
  25. myDate.addDays(daysList.get(i));
  26. System.out.println("The correct new date is " + newDates.get(i) + " and the one calculated by your program is " + myDate + ".");
  27. if (myDate.toString().equals(newDates.get(i).toString()))
  28. {
  29. System.out.println("Correct!\n");
  30. numCorrect++;
  31. }
  32. else
  33. System.out.println("Wrong!\n");
  34. }
  35. System.out.println("Total test cases: " + oldDates.size() + "\nCorrect: " + numCorrect + "\nWrong: " + (oldDates.size() - numCorrect));
  36. }
  37. catch (Exception e)
  38. {
  39. System.out.println("Error occurred: " + e.getMessage());
  40. }
  41. }
  42. }