Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a subclass time2tz which allows you to maintain the time zone in addition

ID: 665175 • Letter: W

Question

Write a subclass time2tz  which allows you to maintain the time zone in addition to the time. Allowed values for time zone include: EST, CST, MST, PST. You will need to override the toString and the toUniversalString methods to return the time with its corresponding time zone. Your class should include at least 2 constructors (your choice). Turn in your source code and do a demo showing your testing of the class where you create several time objects and several “time zoned” objects and show the polymorphic behavior of either the toString or the toUniversalString methods.

Here is a link for time2.java file

https://cs.fit.edu/~mmahoney/cis5100/examples/ch08/fig08_05_06/Time2.java

And link for Time2Test. java

https://cs.fit.edu/~mmahoney/cis5100/examples/ch08/fig08_05_06/Time2Test.java

Explanation / Answer

public class Time2tz extends Time2{
   private String timezone;
   public String getTimezone()
   {
      return timezone;
   }
   public void setTimeZone(String te)
   {
      timezone=te;
   }
   public Time2tz(){
      timezone="";
   }
   public Time2tz(String te)
   {
      timezone=te;
   }
   // convert to String in universal-time format (HH:MM:SS)
   public String toUniversalString()
   {
      return String.format(
         "%02d:%02d:%02d %s", getHour(), getMinute(), getSecond(), getTimezone());
   } // end method toUniversalString

   // convert to String in standard-time format (H:MM:SS AM or PM)
   public String toString()
   {
      return String.format( "%d:%02d:%02d %s %s",
         ( (getHour() == 0 || getHour() == 12) ? 12 : getHour() % 12 ),
         getMinute(), getSecond(), ( getHour() < 12 ? "AM" : "PM" ),getTimezone() );
   } // end method toString
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote