Sie sind auf Seite 1von 5

Martina Atabong maa2247 Part 1: Theory 1) a) Assignment 2

Transitivity: If y has that relation to x, x is literally inside of x. If z has the same relation of y, it contains y which contains x, so it contains them both, hence z contains x. Reflexivity: The square always has the same size in the same so it would always be able to consume itself Antisymmetry: the only way the two squares could contain each other without one over powering is if they had the same corners. b)Counter example: theyre next to eachother. c)Make x and y always stat at (0,0). So two squares will have to always contain one in the other. 2) public class DaysSinceClassTester { public static void main(String[] args){ DayCounter dayCounter=new DayCounter(); System.out.println("Days since class: "+dayCounter.countDaysSinceClass()); //anonymous variable prints the days since class }//closes main }//closes class import java.util.GregorianCalendar; /** * This class has a final class field which is the day class started and today class field. The class is * able to calculate the days since class started * @author Martina * */ public class DayCounter { private static final GregorianCalendar firstDay=new GregorianCalendar (2013, 8, 3); private GregorianCalendar today; /** * Constructor that creates what today is. */ public DayCounter(){

Martina Atabong maa2247 today=new GregorianCalendar(); }//closes constructor /** * Method that counts the days since class * @return number of days since class started */ public int countDaysSinceClass(){ long millisecs=today.getTimeInMillis()-firstDay.getTimeInMillis(); long secs=millisecs/1000;//could still hypothetically be pretty big for

an int

long hours=secs/3600; int numDays=(int) (hours/24); //the number has gone down in size to allow an int return numDays; }//closes countDays method }//closes class

3) /** * This class holds hours, minutes, seconds, and milliseconds. It's able to addmilliseconds and find out * how many milliseconds it's been. * The reason milliseconds is used is because it'd be pointless to have that variable if you didn't use it * to be more precise. It catches a wrong input by taking the overlarge numbers and rolling over till it's * in the proper form. * @author matabong * */ public class TimeOfDay { private int hours; private int minutes; private int seconds; private int millisecs; private static final int MILLI_PER_SEC = 1000;

Martina Atabong maa2247 private static final int MILLI_PER_MINUTE = 1000*60; private static final int MILLI_PER_HOUR = 60*60*1000; private static final int MILLI_PER_DAY =12* MILLI_PER_HOUR; /** * Constructor initializes and rolls over if parameters aren't in the right range * @param h number of hours (0-11) * @param m number of minutes (0-59) * @param s number of seconds (0-59) * @param mil number of milliseconds (0-99) */ public TimeOfDay(int h, int m, int s, int mil){ hours=h; minutes=m; seconds=s; millisecs=mil; if (h>11||m>59||s>59||mil>100){ TimeOfDay better=addMilliseconds(0); hours=better.getHours(); minutes=better.getMins(); seconds=better.getSecs(); millisecs=better.getMilli(); } }//Closes constructor //all of the gets public int getHours(){ return hours; }//closes getHours method public int getMins(){ return minutes; }//closes getMins method public int getSecs(){ return seconds; }//closes getSecs method public int getMilli(){ return millisecs; }//closes getMilli method public TimeOfDay addMilliseconds(int addedMillis){

Martina Atabong maa2247 int milli=(getTotalMilli()+addedMillis)%MILLI_PER_DAY; //parses the number of milliseconds of the day int hrs=milli/MILLI_PER_HOUR; int mins=(milli-hrs*MILLI_PER_HOUR)/MILLI_PER_MINUTE; int secs=(milli-hrs*MILLI_PER_HOURmins*MILLI_PER_MINUTE)/MILLI_PER_SEC; milli=milli%MILLI_PER_SEC; return new TimeOfDay(hrs, mins, secs, milli); }//closes addSeconds Method /** * Method calculate the milliseconds apart 2 times of day are, accounting for roll over. * @param other another time of day * @return milliseconds apart day 1 is from days 2 */ public int millisecondsFrom(TimeOfDay other){ int diff=other.getTotalMilli()-getTotalMilli(); if (diff<0){ diff=MILLI_PER_DAY-Math.abs(diff); }//closes if return diff; }//closes secondsFrom method /** * Method that returns the number of milliseconds in the current time * @return number of milliseconds */ public int getTotalMilli(){ int total=hours*MILLI_PER_HOUR+minutes*MILLI_PER_MINUTE+seconds*MILLI_PER_S EC+millisecs; return total; }//closes getTotalMilli method }//closes class

Martina Atabong maa2247 4) Cohesion: The second toArray() seems out of place and is overly complex. Completeness: There is an add() for a remove() and a set for the get so its consistent. Convenience: It uses a stack, which may be inefficient at times if what youre looking for is on the other side. But it is slightly more efficient by having last and first methods. Clarity: the explanations of the methods are straight forward, but they dont explain well what to insert. Consistency: listIterator() and descendingIterator() are an example of inconsistency.

Das könnte Ihnen auch gefallen