commit d45cae4ee739bc6f8fa919d816dfbbba14eea168 Author: Raphael Roberts Date: Thu Sep 12 20:08:54 2019 -0500 Added files diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c0647b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/HW1.zip +/HW1.pdf diff --git a/prog/Date.java b/prog/Date.java new file mode 100644 index 0000000..f3c628b --- /dev/null +++ b/prog/Date.java @@ -0,0 +1,51 @@ +// The Date class that represents dates +// Do not make any changes to this file! +// Xiwei Wang + +import java.io.*; + +public class Date implements Serializable +{ + // instance variables + protected int m_year; + protected int m_month; + protected int m_day; + + // copy constructor + public Date(Date o) + { + m_year = o.m_year; + m_month = o.m_month; + m_day = o.m_day; + } + + // constructor + public Date(int month, int day, int year) + { + m_year = year; + m_month = month; + m_day = day; + } + + // observers + public int getYear() + { + return m_year; + } + + public int getMonth() + { + return m_month; + } + + public int getDay() + { + return m_day; + } + + // return this date as a String + public String toString() + { + return (m_month + "/" + m_day + "/" + m_year); + } +} diff --git a/prog/IncDate.java b/prog/IncDate.java new file mode 100644 index 0000000..46b3232 --- /dev/null +++ b/prog/IncDate.java @@ -0,0 +1,23 @@ +// The IncDate class +// Do not make changes to anything other than the body of increment() method +// Your name here + +public class IncDate extends Date +{ + // copy constructor + public IncDate(Date o) + { + super(o.m_month, o.m_day, o.m_year); + } + + // constructor + public IncDate(int month, int day, int year) + { + super(month, day, year); + } + + public void addDays(int numDays) + { + // TODO: implement this method + } +} diff --git a/prog/TestIncDate.java b/prog/TestIncDate.java new file mode 100644 index 0000000..67449ee --- /dev/null +++ b/prog/TestIncDate.java @@ -0,0 +1,48 @@ +// Test driver for the IncDate class +// Do not make any changes to this file! +// Xiwei Wang + +import java.util.*; +import java.io.*; + +public class TestIncDate +{ + public static void main(String[] args) + { + try + { + ObjectInputStream in = new ObjectInputStream(new FileInputStream("testDates.dat")); + ArrayList oldDates; + ArrayList daysList; + ArrayList newDates; + oldDates = (ArrayList)in.readObject(); + daysList = (ArrayList)in.readObject(); + newDates = (ArrayList)in.readObject(); + + IncDate myDate; + int numCorrect = 0; + + for (int i = 0; i < oldDates.size(); i++) + { + System.out.println("The current date is " + oldDates.get(i) + " and " + daysList.get(i) + " days are added."); + myDate = new IncDate(oldDates.get(i)); + myDate.addDays(daysList.get(i)); + System.out.println("The correct new date is " + newDates.get(i) + " and the one calculated by your program is " + myDate + "."); + + if (myDate.toString().equals(newDates.get(i).toString())) + { + System.out.println("Correct!\n"); + numCorrect++; + } + else + System.out.println("Wrong!\n"); + } + + System.out.println("Total test cases: " + oldDates.size() + "\nCorrect: " + numCorrect + "\nWrong: " + (oldDates.size() - numCorrect)); + } + catch (Exception e) + { + System.out.println("Error occurred: " + e.getMessage()); + } + } +} diff --git a/prog/testDates.dat b/prog/testDates.dat new file mode 100644 index 0000000..af8da3f Binary files /dev/null and b/prog/testDates.dat differ