From d45cae4ee739bc6f8fa919d816dfbbba14eea168 Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Thu, 12 Sep 2019 20:08:54 -0500 Subject: [PATCH] Added files --- .gitignore | 2 ++ prog/Date.java | 51 ++++++++++++++++++++++++++++++++++++++++++ prog/IncDate.java | 23 +++++++++++++++++++ prog/TestIncDate.java | 48 +++++++++++++++++++++++++++++++++++++++ prog/testDates.dat | Bin 0 -> 1521 bytes 5 files changed, 124 insertions(+) create mode 100644 .gitignore create mode 100644 prog/Date.java create mode 100644 prog/IncDate.java create mode 100644 prog/TestIncDate.java create mode 100644 prog/testDates.dat 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 0000000000000000000000000000000000000000..af8da3f9c91d09be593ac6902a81f65c6a3f8719 GIT binary patch literal 1521 zcmbW1y=xRv6vgk%evB~@^C76{ZXsg1wO|kgn?dnkSe|5v8+O(>JG;&bih-bots)kJ zg@r}_1Pj5!!p_pK#ArG#CE9t;3vX^-rn8vYJHNee=AAR=&c-ik3^Q3+F=Nvi<-LCA zQkI#?)!r~K);_eJy)(~i62wv;_U0*Ml8*=J4sBow-W0Dk?7;_mfVvNSEq5{H~Lf|pG(q4PtEHg!5$*NrvdWC zTh#>l>X8U!(<6sKwmdQg^35ZMLAE_I4f5S1Gax@oauhrCl~&0S^!VBxQC-kvwX3e# z3c+)%8>$q#g>Inqv;LQOt2SUfxAKX>w z*iKz6Tyxd)Tcs^tj8)MTSB}FE)+IMY~UQeMB`x)rmh<58Ze%8jP3@9Ig%w6MHyb8afv!9ZIfZp!^=jM}x^8#z$kw z`!GHlLlVYEL&sH&kA{vt42wpLJq(LRj6FD_9cu#rKZ%2%1Xbz=PF1wfgWi2A+~-GC zzzN&q@0tE6fdcD>Ds^L_x;O+}rIF_dQib;L>HaXC0`WgK?gOCO*+ZXymfDYj@L7LL PLZu|?5BJRXwOjlHiiQ5E literal 0 HcmV?d00001