Question

In: Computer Science

The assignment is to write a class called data. A Date object is intented to represent...

The assignment is to write a class called data. A Date object is intented to represent a particuar date's month, day and year. It should be represented as an int.

-- write a method called earlier_date. The method should return True or False, depending on whether or not one date is earlier than another. Keep in mind that a method is called using the "dot" syntax. Therefore, assuming that d1 and d2 are Date objects, a valid method called to earlier_date would be

>>> d1.earlier_date(d2)

and the method should return True if d1 is earlier than d2, or False otherwise. For example:

>>> today = Date(1,23,2017)

>>> y2k.earlier_date(today)

True

>>> today.earlier_date(mlk_day)

False

>>> feb_29.earlier_date(march_1)

True

python 2.7.13

Solutions

Expert Solution


class Date:
def __init__(self,month,day,year):
self.month = month
self.day = day
self.year = year
  
def earlier_date(self,x):
if self.year==x.year and self.month==x.month and self.day==x.day :
return True
else:
return False
  
  
  
d1=Date(1,23,2017)
d2=Date(2,23,2017)
d1.earlier_date(d2)

y2k=Date(1,24,2017)
today = Date(1,24,2017)
y2k.earlier_date(today)

Code Image:

Output Image:


Related Solutions

Java Write a class called Triangle that can be used to represent a triangle. Write a...
Java Write a class called Triangle that can be used to represent a triangle. Write a class called Describe that will interface with the Triangle class The Server • A Triangle will have 3 sides. It will be able to keep track of the number of Triangle objects created. It will also hold the total of the perimeters of all the Triangle objects created. • It will allow a client to create a Triangle, passing in integer values for the...
Python: What are the defintions of the three method below for a class Date? class Date(object):...
Python: What are the defintions of the three method below for a class Date? class Date(object): "Represents a Calendar date"    def __init__(self, day=0, month=0, year=0): "Initialize" pass def __str__(self): "Return a printable string representing the date: m/d/y" pass    def before(self, other): "Is this date before that?"
Java - Write an abstract class called Shape with a string data field called colour. Write...
Java - Write an abstract class called Shape with a string data field called colour. Write a getter and setter for colour. Write a constructor that takes colour as the only argument. Write an abstract method called getArea()
1. Write a class called Rectangle that maintains two attributes to represent the length and width...
1. Write a class called Rectangle that maintains two attributes to represent the length and width of a rectangle. Provide suitable get and set methods plus two methods that return the perimeter and area of the rectangle. Include two constructors for this class. One a parameterless constructor that initializes both the length and width to 0, and the second one that takes two parameters to initialize the length and width. 2. Write a java program (a driver application) that tests...
: Design and implement class Radio to represent a radio object. The class defines the following...
: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. A private variable of type int named station to represent a station number. Set to A private variable of type int named volume to represent the volume setting. Set to 1. A private variable of type boolean named on to represent the radio on or off. Set to...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This class should contain information of a single student. last name, first name, credits, gpa, date of birth, matriculation date, ** you need accessor and mutator functions. You need a constructor that initializes a student by accepting all parameters. You need a default constructor that initializes everything to default values. write the entire program.
Write a Python class definition called CellPhone to represent a monthly cell phone bill. The bill...
Write a Python class definition called CellPhone to represent a monthly cell phone bill. The bill should contain the following information: customer name (default value is the empty string) account number (default value is 0) number of gigabytes (GB) used over the monthly limit (default value is 0) Include the following methods: a constructor which given a customer name, account number, and number of GB used in excess of the monthly limit, creates a CellPhone object (be sure to account...
DO THIS IN C#,Design and implement class Rectangle to represent a rectangle object. The class defines...
DO THIS IN C#,Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to create a rectangle with user-specified height and width. 4. Method getArea() that returns...
IN C++!!! Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class...
IN C++!!! Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 0 in the default constructor. A non-argument constructor method to create a default rectangle. Another constructor method to create a rectangle with user-specified height and width. Method getArea() that returns the area. Method...
Class AssignmentResult An object that represents the result of an assignment. __init__(self, id:int, assignment: Assignment, grade:...
Class AssignmentResult An object that represents the result of an assignment. __init__(self, id:int, assignment: Assignment, grade: float): """ This will contain the ID of the student, the assignment that the student worked on and the grade the student received on the assignment. :param id: The ID of the student that created this Assignment result :param assignment: The Assignment that the student worked on. :param grade: A number between 0-1 representing the numerical grade the student received """ id(self) -> int:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT