Question

3.6 Appointments PYTHON (3 pts) Create a new class called Appointment. An appointment should have a...

3.6 Appointments PYTHON

(3 pts) Create a new class called Appointment. An appointment should have a description and a date. Your Appointment class should take the description and date from the constructor and assign them to instance variables.

Your constructor should take parameters in the following order: description, year, month, day.

Your instance variables should be called:

  • description
  • year
  • month
  • day

(2 pts) Override the __str__(self) method to print a human-friendly version of the object. Your__str__ method should produce output similar to: Appointment on 1/2/20: Blood pressure check.

(2 pts) Write a main function to test your Appointment class. The main function should prompt the user for a description, month, day, and year; and then print the object to test the __str__ method.

Homework Answers

Answer #1
class Appointment:
    def __init__(self, description, year, month, day):
        self.description = description
        self.year = year
        self.month = month
        self.day = day

    def __str__(self):
        return 'Appointment on {}/{}/{}: {}.'.format(self.month, self.day, self.year, self.description)


def main():
    description = input("Enter description: ")
    month = int(input("Enter month: "))
    day = int(input("Enter day: "))
    year = int(input("Enter year: "))
    appointment = Appointment(description, year, month, day)
    print(appointment)


main()

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
* Python Programming * Write a class definition named Book. The Book class should have instance...
* Python Programming * Write a class definition named Book. The Book class should have instance variables for a book's title, the author's name, and the publisher's name. The class should also have the following: a) An __init__ method for the class. The method should accept an argument for each of the instance variables. b) An __str__ method that returns a string indicating the state of the object. Use the Car class file in resources/Margie's Notes/car.py as an example, but...
Write Python code to define a class called Student. The Student class should have the following...
Write Python code to define a class called Student. The Student class should have the following private fields: name – to store the name of a student attend – to store how many times a student attend the class grades – a list of all student’s grades The Student class should have the following methods: a constructor getter method for the name field attendClass method: that increments the attend field (should be called every time a student attends the class)....
Write a class called Hamburger in python The Hamburger class should have the following fields: weight...
Write a class called Hamburger in python The Hamburger class should have the following fields: weight – an int storing the weight of the hamburger patty in ounces doneness – a String which stores how well the burger is cooked i.e., rare, medium, well done, etc. cheese – a boolean indicating whether the burger has cheese or not toppings – a list of Strings storing the toppings on the burger i.e., lettuce, tomato, mayonnaise, etc. The Hamburger class should have...
Write a Date class that contains 3 integer data members (month, day, year) along with the...
Write a Date class that contains 3 integer data members (month, day, year) along with the appropriate methods (functions) that would allow you to write a main function that does the following: Declare a date called today, that contains today’s date: 9, 25, 2019 Declare a date called tomorrow but don’t send it any data values. Call the setValues() method on tomorrow to set tomorrow’s date. Write a C++ print statement to print the following to the screen:                 today’s...
Create java class with name Dog. Instructions for Dog class:              This class is modeled after...
Create java class with name Dog. Instructions for Dog class:              This class is modeled after a Dog. You should have instance variables as follows: The Dog’s name The number of tricks known by the Dog. The color*of the Dog’s coat (fur). *: For the Dog’s fur color you should use the Color class from the java.awt package. You should choose proper types and meaningful identifiers for each of these instance variables. Your class should contain two constructor methods. A...
java Create a program that defines a class called circle. Circle should have a member variable...
java Create a program that defines a class called circle. Circle should have a member variable called radius that is used to store the radius of the circle. Circle should also have a member method called calcArea that calculates the area of the circle using the formula area = pi*r^2. Area should NOT be stored in a member variable of circle to avoid stale data. Use the value 3.14 for PI. For now, make radius public and access it directly...
Create a class called Employee that should include four pieces of information as instance variables—a firstName...
Create a class called Employee that should include four pieces of information as instance variables—a firstName (type String), a lastName (type String), a mobileNumber (type String) and a salary (type int). Your class (Employee) should have a full argument constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. The validation for each attribute should be like below: mobileNumber should be started from “05” and the length will be limited to 10...
Assignment 1. Console Application IN PYTHON For this assignment you are to create a class called...
Assignment 1. Console Application IN PYTHON For this assignment you are to create a class called Lab1. Inside the class you will create three methods that will modify a three-digit whole number: sumNums - This method takes as input a three digit int and returns the sum of the three numbers. For instance, 123 would return 6 because 3 + 2 + 1 is 6 reverseNums - This method takes as input a three digit whole number and returns the...
In c++ create a class to maintain a GradeBook. The class should allow information on up...
In c++ create a class to maintain a GradeBook. The class should allow information on up to 3 students to be stored. The information for each student should be encapsulated in a Student class and should include the student's last name and up to 5 grades for the student. Note that less than 5 grades may sometimes be stored. Your GradeBook class should at least support operations to add a student record to the end of the book (i.e., the...
We encourage you to work in pairs for this challenge to create a Student class with...
We encourage you to work in pairs for this challenge to create a Student class with constructors. First, brainstorm in pairs to do the Object-Oriented Design for a Student class. What data should we store about Students? Come up with at least 4 different instance variables. What are the data types for the instance variables? Write a Student class below that has your 4 instance variables and write at least 3 different constructors: one that has no parameters and initializes...