Lab Set Q1W5 Classes & Objects Level 1 Create a class called

advertisement
Lab Set Q1W5
Classes & Objects
Level 1
Create a class called MyTime that has the following attributes:
Variables:
 minutes – stores the minute as an integer
 seconds – stores the seconds as a real number
Methods:
1. MyTime (constructor)
o Input Variables – integer minute, double second
o Output – none
o Action – takes in and sets the initial variable values
2. getMinute
o Input Variables – none
o Output – integer
o Action – returns the minute
3. getSecond
o Input Variables – none
o Output – double
o Action – returns the seconds
4. toString
o Input Variables – none
o Output – String
o Action – returns a String description of the time such that the following variable values
would result in the following String being returned:
minute – 32, seconds – 24.35
“32 : 24.35”
Level 2
Create a class called MyTime that has the following attributes:
Variables:
 hours – stores the hour as an integer
 minutes – stores the minute as an integer
 seconds – stores the seconds as a real number
Methods:
1. MyTime (constructor)
o Input Variables – integer hour, integer minute, double second
o Output – none
o Action – takes in and sets the initial variable values
2. getHour
o Input Variables – none
o Output – integer
o Action – returns the hour
3. getMinute
o Input Variables – none
o Output – integer
o Action – returns the minute
4. getSecond
o Input Variables – none
o Output – double
o Action – returns the seconds
5. toString
o Input Variables – none
o Output – String
o Action – returns a String description of the time such that the following variable values
would result in the following String being returned:
hour – 17, minute – 32, seconds – 24.35
“5 PM : 32 : 24.35”
6. equals
o Input Variables – Time other
o Output – boolean
o Action – returns whether or not the time object passed in has the same time as this time
object
Level 3
Create a class called MyTime that has the following attributes:
Variables:
 hours – stores the hour as an integer
 minutes – stores the minute as an integer
 seconds – stores the seconds as a real number
Methods:
7. MyTime (constructor)
o Input Variables – integer hour, integer minute, double second
o Output – none
o Action – takes in and sets the initial variable values
8. getHour
o Input Variables – none
o Output – integer
o Action – returns the hour
9. getMinute
o Input Variables – none
o Output – integer
o Action – returns the minute
10. getSecond
o Input Variables – none
o Output – double
o Action – returns the seconds
11. toString
o Input Variables – none
o Output – String
o Action – returns a String description of the time such that the following variable values
would result in the following String being returned:
hour – 17, minute – 32, seconds – 24.35
“5 PM : 32 : 24.35”
12. equals
o Input Variables – MyTime other
o Output – boolean
o Action – returns whether or not the time object passed in has the same time as this time
object
13. compareTo
o Input Variables – MyTime other
o Output – integer
o Action – Compares this object with the specified object for order. Returns a negative
integer if the other time comes after this one, zero if they are the same, or a positive integer
if this one comes after the other one.
Level 4
Create a class called MyTime that has the following attributes:
Variables:
 year – stores the year as an integer
 month – stores the month as an integer
 day – stores the day as an integer
 hours – stores the hour as an integer
 minutes – stores the minute as an integer
 seconds – stores the seconds as a real number
Methods:
1. MyTime (constructor)
o Input Variables – integer year, integer month, integer day, integer hour, integer minute,
double second
o Output – none
o Action – takes in and sets the initial variable values
2. getYear
o Input Variables – none
o Output – integer
o Action – returns the year
3. getMonth
o Input Variables – none
o Output – integer
o Action – returns the month
4. getDay
o Input Variables – none
o Output – integer
o Action – returns the day
5. getHour
o Input Variables – none
o Output – integer
o Action – returns the hour
6. getMinute
o Input Variables – none
o Output – integer
o Action – returns the minute
7. getSecond
o Input Variables – none
o Output – double
o Action – returns the seconds
8. toString
o Input Variables – none
o Output – String
o Action – returns a String description of the time such that the following variable values
would result in the following String being returned:
year – 2014, month – 10, hour – 17, minute – 32, seconds – 24.35
“2014 : October 2 : 5 PM : 32 : 24.35”
9. equals
o Input Variables – MyTime other
o Output – boolean
o Action –returns whether or not the time object passed in has the same time as this time
object
10. compareTo
o Input Variables – MyTime other
o Output – integer
o Action – Compares this object with the specified object for order. Returns a negative
integer if the other time comes after this one, zero if they are the same, or a positive integer
if this one comes after the other one.
Level 5
Create a class called MyTime that has the following attributes:
Variables:
 year – stores the year as an integer
 month – stores the month as an integer
 day – stores the day as an integer
 hours – stores the hour as an integer
 minutes – stores the minute as an integer
 seconds – stores the seconds as a real number
Methods:
1. MyTime (constructor)
o Input Variables – integer year, integer month, integer day, integer hour, integer minute,
double second
o Output – none
o Action – takes in and sets the initial variable values
2. getYear
o Input Variables – none
o Output – integer
o Action – returns the year
3. getMonth
o Input Variables – none
o Output – integer
o Action – returns the month
4. getDay
o Input Variables – none
o Output – integer
o Action – returns the day
5. getHour
o Input Variables – none
o Output – integer
o Action – returns the hour
6. getMinute
o Input Variables – none
o Output – integer
o Action – returns the minute
7. getSecond
o Input Variables – none
o Output – double
o Action – returns the seconds
8. toString
o Input Variables – none
o Output – String
o Action – returns a String description of the time such that the following variable values
would result in the following String being returned:
year – 2014, month – 10, hour – 17, minute – 32, seconds – 24.35
“2014 : October 2 : 5 PM : 32 : 24.35”
9. equals
o Input Variables – MyTime other
o Output – boolean
o Action –returns whether or not the time object passed in has the same time as this time
object
10. compareTo
o Input Variables – MyTime other
o Output – integer
o Action – Compares this object with the specified object for order. Returns a negative
integer if the other time comes after this one, zero if they are the same, or a positive integer
if this one comes after the other one.
11. incrementMinute
o Input Variables – none
o Output – none
o Action – Increments the time stored by one minute. This method takes into account how
minutes eventually increment hours, days, months, and years once each one reaches their
respective limit.
Download