81.4k views
4 votes
Python

You will be writing a scheduling application allowing a convention center to schedule events at their location. This program will contain two different classes: Date and Event. Both classes should be defined on their own .py modules.

The Date class should have the following attributes: day, month, and year.

The Date class should have the following methods:

set_date: Takes three arguments: the day, month, and year. Sets the day, month, and year attributes of the object. Do not allow values to be negative, day to be greater than 31, and month to be greater than 12.
__str__: Returns a string representation of the date's information in the form "dd/mm/yyyy".
Properties and setters for the attributes
The Event class should have the following attributes:

event_date (which should be a Date object)
event_name
start_hour: Uses a 24-hour clock, so should be a value between 0 and 23
endHour: Uses a 24-hour clock, so should be a value between 0 and 23
The Event class should have the following methods:

__str__. Return a string representation of all important info about this Event: The name of the event, the start and end times (you can simply print their value i.e. from 14 to 16) and the Date.
Properties and setters for the attributes.
A constructor which takes a name, start and end hours, and a Date object.
Note: For sake of simplicity, each event will only take one day. Each event will also not go over midnight, so start_hour must be less than end_hour. For example, an event that starts at 2pm and ends at 4pm would have a start_hour of 14 and an end_hour of 16.

In your program's main function, create a list that holds Event objects. Continually give the user the following choices:

Add an Event to the list. Ask the user for the date info (day, month, year) start and end time (the user should enter values between 0 and 23) and the name of the event: If there is already an event in the list on the given date and its time overlaps the event the user is trying to add, print out the info about that event and do not add the new event.
Cancel an event: The user will type in the name of the event to cancel. Remove the event from the list (if it exists).
View all events: In a loop, print the info of all the events currently planned.
Quit
Submit all 3 files (or copy and paste the code from all 3 files).

User Sylwit
by
8.5k points

1 Answer

3 votes

Final answer:

The Date class should have attributes for day, month, and year, as well as methods to set the date and return a string representation. The Event class should have attributes for event date, name, start hour, and end hour, along with a method to return a string representation. Lastly, the main function can create a list of Event objects and provide options to add, cancel, or view events.

Step-by-step explanation:

Date Class

The Date class should have the following attributes: day, month, and year. It should also have a set_date method that sets the day, month, and year attributes of the object.

This method should not allow negative values, day to be greater than 31, and month to be greater than 12. The class should also have a __str__ method that returns a string representation of the date's information in the form "dd/mm/yyyy". Lastly, the class should have properties and setters for the attributes.

Event Class

The Event class should have the following attributes: event_date (which should be a Date object), event_name, start_hour, and end_hour.

The start_hour and end_hour should be values between 0 and 23, representing the hours in a 24-hour clock.

The class should also have a __str__ method that returns a string representation of all important information about the event. Lastly, the class should have properties and setters for the attributes.

In the main function, you can create a list that holds Event objects. You can continually give the user choices to add an event to the list, cancel an event, view all events, or quit the program.

User Federico Builes
by
8.6k points