Knowee
Questions
Features
Study Tools

Create a class named Year that contains a data field that holds the number of days in theyear. Include a get method that displays the number of days and a constructor that setsthe number of days to 365. Create a subclass named LeapYear. LeapYear’s constructoroverrides Year’s constructor and sets the day field to 366.Write a program that instan6ates one object of each class and displays their data.Add a method named daysElapsed() to the Year class you created in Exercise 5a. ThedaysElapsed() method accepts two arguments represen6ng a month and a day; it returnsan integer indica6ng the number of days that have elapsed since January 1 of the year.Create a daysElapsed() method for the LeapYear class that overrides the method in theYear class. Write a program that calculates the days elapsed on March 1 for a Year and fora LeapYear.

Question

Create a class named Year that contains a data field that holds the number of days in theyear. Include a get method that displays the number of days and a constructor that setsthe number of days to 365. Create a subclass named LeapYear. LeapYear’s constructoroverrides Year’s constructor and sets the day field to 366.Write a program that instan6ates one object of each class and displays their data.Add a method named daysElapsed() to the Year class you created in Exercise 5a. ThedaysElapsed() method accepts two arguments represen6ng a month and a day; it returnsan integer indica6ng the number of days that have elapsed since January 1 of the year.Create a daysElapsed() method for the LeapYear class that overrides the method in theYear class. Write a program that calculates the days elapsed on March 1 for a Year and fora LeapYear.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a Python solution for your problem:

class Year:
    def __init__(self):
        self.days = 365

    def get_days(self):
        return self.days

    def daysElapsed(self, month, day):
        months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        return sum(months[:month-1]) + day


class LeapYear(Year):
    def __init__(self):
        super().__init__()
        self.days = 366

    def daysElapsed(self, month, day):
        months = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        return sum(months[:month-1]) + day


# Create objects and display their data
year = Year()
leap_year = LeapYear()

print("Days in a year: ", year.get_days())
print("Days in a leap year: ", leap_year.get_days())

# Calculate days elapsed on March 1 for a Year and for a LeapYear
print("Days elapsed on March 1 in a year: ", year.daysElapsed(3, 1))
print("Days elapsed on March 1 in a leap year: ", leap_year.daysElapsed(3, 1))

This program first creates a Year class with a constructor that sets the number of days to 365 and a get_days method that returns the number of days. It also includes a daysElapsed method that calculates the number of days elapsed since January 1

This problem has been solved

Similar Questions

Create a class Year to read year and find whether is is leap year or not. Create  a class month  which display 12 months . Create a class import which uses above classes and tell the current month and year and also tell whether it is leap or not

Suppose we want to design a class Day for working with calendar days (such as January 1, 2016). Specify methods for the following operations.1)A getMonth method that gets the month as an integer between 1 and 12.CheckShow answer2)A getMonthName method that gets the month as a string, such as "May".CheckShow answer3)An addDays method that returns the calendar day that is n days from this one.CheckShow answer4)A moveByDays method that moves this calendar day object by n days.CheckShow answer5)A constructor that constructs a Day with year y, month m (as an integer between 1 and 12), and day of month d.

Write a JAVA program in which take date(DDMMYYYY) from user and displaynext day date(DDMMYYYY) as output.Example:Input: date=09, month=-06, year=1992Output: date=10, month=-06, year=1992Note:-1. Consider condition for leap year2. Consider number of days in month of February based on leap year ( if leapyear then February days =29, else days = 28 ) )3. Consider number of days either 30 or 31 based on month entered by user

You are given a year in the form of an integer 'N', and your task is to check whether the given year is a leap year or not.Note:1) A year is said to be a leap year if it has 366 days. Normal years have 365 days.2) The integer 'N' does not contain any leading zeros.Sample Input 1:220002020Sample Output 1:YesYesExplanation for Sample Output 1:In test case 1, The year 2000 had 366 days since there were 29 days in the month of February in the year 2000.

Create a class called Date that includes three pieces of information as instance variables—a month, a day and a year. Your class should have a constructor that initializes the three instance variables after validating the given date. Provide a getDetails() member method to read the date. Provide a method displayDate() that displays the month, day and year separated by forward slashes(/). Write a C++ application and pseudocode that demonstrates classDate’s capabilities.Input : Read Month, Day and Year (Line by line)Output :Print Date that displays the month, day and year separated by forward slashes(/)Note: print "Invalid Date" other than the following2000 < Year < 20250 < Day <= 31 ( for the months Jan, March, May, July, August, October, December)0 < Day <= 30 ( for the months April, June, September, and November)0 < Day <= 28 ( for the month February ) and (0 < Day <= 29), if month = 2 and year = leap year0 < Month < = 12

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.