Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you help me with the solution in python 3. Task 1.1 (12 marks) In UML, class methods and class variables are indicated by an

Can you help me with the solution in python 3.

image text in transcribedimage text in transcribed
Task 1.1 (12 marks) In UML, class methods and class variables are indicated by an underlined name. Consider the following UML diagram: Date +monthNames: string[12] +getMonthName(number): string +getDaysInMonth(month, year=1): int +is ValidY ear(year): boolean +is ValidMonth(month): boolean +isValidDay(day, month, year): boolean Create the class methods of the Date class: monthNames - a class variable containing a list of all the month names. getMonthName(number) - returns the name of the month where 1 is January, 12 is December, etc. Hint: you may use the class variable, monthNames, to get this name. getDaysInMonth(month, year=1) - returns the number of days in the given month: 31 for the months of January, March, May, July, August, October, and December; 30 for the months of April, June, September, and November; 29 for the month of February if the year divisible by 4 but not 100, unless it is divisible by 400; 28 otherwise. is ValidYear(year) - a class method to return True if the argument year is an int; False otherwise. isValidMonth(month) - a class method to return True if the argument month is an int between 1 and 12; False otherwise. isValidDay(day, month, year) - a class method to return True if the day is between 1 and the number of days in the given month, in the given year. Hint: You may use your getDaysInMonth method to assist you. . Test each of your class methods with at least 3 different cases each. Hint: Remember to call your method using the name of the class such as: Date.getMonthName(1) or Date.isValidDay(29, 2, 2020).Task 2 Consider the UML diagram below. Date +monthNames: string[12] day: int -month: int -year: int +getMonthName(number): string +getDaysInMonth(month, year=1): int +is ValidYear(year): boolean +isValidMonth(month): boolean +isValidDay(day, month, year): boolean init_(day, month, year) _str_(): string It_(other: Date): boolean Complete the non-class members of the Date class: day - attribute to hold the day of month as an int. . month - attribute to hold the month of year as an int. . year - attribute to hold the year as an int. init_- Use the class methods to validate the day, month, and year. If any argument is invalid, raise an Exception with an appropriate error message. str_- Return a string in the format "[day] [month name], [year]", such as "18 February, 2021". Hint: You may call your class method getMonthName(number) to help you write this method. _It_- This magic method overloads the less than operator <. the method must return true if self represents a date that is less than other false otherwise. test your class using following code: d1="Date(18," d2="Date(3," d2: print elif d1: more else: equal to you should receive output: february march construct different invalid dates and use exception handling prevent code from crashing display error messages>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions