Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Date;
- import java.util.Calendar;
- import java.text.SimpleDateFormat;
- /**
- * Time is the current local clock time at an airport
- * at which a flight arrives or departs.
- * @author Some Student
- */
- public class Time
- {
- private Date aTime;
- private SimpleDateFormat df = new SimpleDateFormat("HHmm");
- public Time()
- {
- try {
- aTime = df.parse("0000");
- } catch (java.text.ParseException ex)
- { ex.printStackTrace();
- }
- }
- public Time(String time)
- {
- try {
- aTime = df.parse(time);
- } catch (java.text.ParseException ex)
- { ex.printStackTrace();
- }
- }
- public int subtract(Time other)
- {
- Calendar cal = Calendar.getInstance();
- cal.setTime(aTime);
- long ms = cal.getTimeInMillis();
- cal.setTime(other.aTime);
- ms -= cal.getTimeInMillis();
- final long msPerMin = 1000L * 60L;
- return (int) (ms / msPerMin);
- }
- public void addOne()
- {
- Calendar cal = Calendar.getInstance();
- cal.setTime(aTime);
- cal.add(Calendar.MINUTE,1);
- aTime = cal.getTime();
- }
- public String toString()
- {
- return df.format(aTime);
- }
- public int compareTo(Time other)
- {
- return aTime.compareTo(other.aTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement