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...
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...
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:...
Invoice Class - Create a class called Invoice that a hardware store might use to represent...
Invoice Class - Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables—a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. If the quantity passed to the constructor is...
C++ Assignment 1) Write a C++ program specified below: a) Include a class called Movie. Include...
C++ Assignment 1) Write a C++ program specified below: a) Include a class called Movie. Include the following attributes with appropriate types: i. Title ii. Director iii. Release Year iv. Rating (“G”, “PG”, “PG-13”, etc) - Write code that instantiates a movie object using value semantics as text: - Write code that instantiates a movie object using reference semantics: - Write the print_movie method code: - Write Constructor code: - Write Entire Movie class declaration
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date...
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date object, a ClockWithAudio object, a BMI object, a Day object, and a FigurePane object. Then display all elements in the list. Assume that all classes (i.e. Date, Account, etc.) have their own no-argument constructor.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT