Question

In this exam, you will design and implement a Python class called Date according to the following API specifications. • Do N

objeci, (d) [10 points] Date.add( other ) will add the provided number of days to the current date and return the resulting dRun Code Раээ In [ ]: 1 da = Date 2018, 9, 28 ) WNE assert str(da ) == 2018/09/28 In [ ]: 1 dd = da.add( 94 ) 2 3 assert str

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Date:

def __inti__(self,y,m,d):

self.month=y

self.day=m

self.year=d

def add(time):

self.years+=time//360

self.month+=(time%360)//12

self.day+=(time%360)%12

def sub(time):

self.years+=time//360

self.month+=(time%360)//12

self.day+=(time%360)%12

def __str__(self)

y=str(self.years)

m=str(self.month)

d=str(self.day):

while len(y)<4:

y='0'+y

while len(m)<2:

m='0'+m

while len(d)<2:

d='0'+d

print(y+'/'+m+'/'+d)

if __name__='__main__':

print('enter year month and date')

y=int(input())

m=int(input())

d=int(input())

a=Date(y,m,d)

print(a)

while True:

print('1) add 2)sub 3)exit')

n=int(input())

if n==1:

print('enter time to be added')

a.add(int(input())

print(a)

  

elif n==2:

  print('enter time to be added')

a.add(int(input())

print(a)

elif n==3:

break

else:

print('invalid option')

''' tried a lot for it pls upvote if u like'''

Add a comment
Know the answer?
Add Answer to:
In this exam, you will design and implement a Python class called 'Date according to the...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Description: This project focuses on creating a Java class, Date.java, along with a client class, DateCleint.java,...

    Description: This project focuses on creating a Java class, Date.java, along with a client class, DateCleint.java, which will contain code that utilizes your Date.java class. You will submit both files (each with appropriate commenting). A very similar project is described in the Programming Projects section at the end of chapter 8, which you may find helpful as reference. Use (your own) Java class file Date.java, and a companion DateClient.java file to perform the following:  Ask user to enter Today’s...

  • Given the following date class interface: class date {private: int month;//1 - 12 int day;//1 -...

    Given the following date class interface: class date {private: int month;//1 - 12 int day;//1 - 28. 29. 30. 31 depending on month & year int year;//4-digit, e.g.. 2017 public: date();//Default constructor (investigate; find what it is used for)//Postcondition: the newly declared date object is initialized to 01/01/2000 date(int mm, int dd, int yyyy);//Second constructor//Postcondition: the newly declared data object is initialized to mm/dd/yyyy void setDate(int mm. int dd. int yyyy);//Postcondition: set the contents of the calling date object to...

  • Design and implement a C++ class called Date that has the following private member variables month...

    Design and implement a C++ class called Date that has the following private member variables month (int) day (nt) . year (int Add the following public member functions to the class. Default Constructor with all default parameters: The constructors should use the values of the month, day, and year arguments passed by the client program to set the month, day, and year member variables. The constructor should check if the values of the parameters are valid (that is day is...

  • public class Date { private int month; private int day; private int year; /** default constructor...

    public class Date { private int month; private int day; private int year; /** default constructor * sets month to 1, day to 1 and year to 2000 */ public Date( ) { setDate( 1, 1, 2000 ); } /** overloaded constructor * @param mm initial value for month * @param dd initial value for day * @param yyyy initial value for year * * passes parameters to setDate method */ public Date( int mm, int dd, int yyyy )...

  • Please write the program in C++ Problem Description: Design a class called Date. The class should...

    Please write the program in C++ Problem Description: Design a class called Date. The class should store a date in three integers: month, day, and year.     Create the necessary set and get methods.       Design member functions to return the date as a string in the following formats:                                     12/25/2012                                     December 25, 2012                                     25 December 2012 Input Validation: Do not accept values for day greater than 30 or less than 1. Do not accept values for month...

  • 12.2 LAB 12.2: Classes (Date) C++ Rewrite the class definition of Date class (From Lab 12.1)...

    12.2 LAB 12.2: Classes (Date) C++ Rewrite the class definition of Date class (From Lab 12.1) including 4 added member functions: bool isLeapYear(): this function will return true if the year of the date is a leap year. int daysPassed(): This function will return how many days has been passed in this year. int daysLeft(): This function will return how many days has left of this year. int diff(Date AnotherDate): This function will return the difference between the calling object...

  • Using c++.Complete the implementation of the class date that represents dates written in the form day/month/year....

    Using c++.Complete the implementation of the class date that represents dates written in the form day/month/year. Do not modify the main program. You must write the prototypes and the definitions of the methods of the class. Declaration of Class Date /File: date.h A class representing dates in the form: day, month and year dat e s are written to a stream in the form day/mon th / year day number () returns the number of days since 1/1 of the...

  • Write a class called Date that represents a date consisting of a year, month, and day....

    Write a class called Date that represents a date consisting of a year, month, and day. A Date object should have the following methods: public Date(int year, int month, int day) Constructs a new Date object to represent the given date. public void addDays(int days) Moves this Date object forward in time by the given number of days. public void addWeeks(int weeks) Moves this Date object forward in time by the given number of seven-day weeks. public int daysTo( Date...

  • Tasks A. (20 po ints) In Lab 6, you defined and implemented a class called Date....

    Tasks A. (20 po ints) In Lab 6, you defined and implemented a class called Date. You will make some modific ation to the Date class so that it mccts the folowing specific ations: The Date class consists of three private member variables: Member Variable year month day Description An int variable that hokls the value of a year. An int variable that hokds the value of a month An int variable that hokis the value of a day. The...

  • My values are not storing into my object and I keep returning zero. please explain my...

    My values are not storing into my object and I keep returning zero. please explain my mistake thanks public class CalanderDate { int year = 0 ; int day = 0; int month= 0;    public static void main(String[] args) { CalanderDate date; date = new CalanderDate( 1, 10 ,1999); System.out.print(date); }          public CalanderDate(int month, int day , int year ) { if (month < 1){ month = 1; } if (month> 12){ month = 12; }...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT