Knowee
Questions
Features
Study Tools

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

Question

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

🧐 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, year):
        self.year = year

    def is_leap(self):
        if self.year % 4 == 0:
            if self.year % 100 == 0:
                if self.year % 400 == 0:
                    return True
                else:
                    return False
            else:
                return True
        else:
            return False


class Month:
    def __init__(self):
        self.months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']

    def display(self):
        for month in self.months:
            print(month)


class Import:
    def __init__(self, year):
        self.year = Year(year)
        self.month = Month()

    def display(self):
        print("Current Year: ", self.year.year)
        print("Is Leap: ", self.year.is_leap())
        print("Months: ")
        self.month.display()


# Usage
import datetime
current_year = datetime.datetime.now().year
i = Import(current_year)
i.display()

This code creates three classes: Year, Month, and Import. The Year class has a method is_leap to check if the year is a leap year or not. The Month class has a method display to print all 12 months. The Import class uses the Year and Month classes to display the current year, whether it's a leap year or not, and all 12 months.

This problem has been solved

Similar Questions

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.

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.

Given a year, determine whether it is a leap year. If it is a leap year, return the Boolean True, otherwise return False.Note that the code stub provided reads from STDIN and passes arguments to the is_leap function. It is only necessary to complete the is_leap function.

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

Search course Type to search Minimum 3 characters required for search Close 1.1.2. Leap year checking 02:30 Sophia, a software developer, is working on a calendar application where accurate identification of leap years is crucial. She needs a program that efficiently checks whether a given year is a leap year. In the Gregorian calendar, a leap year is either divisible by 4 but not divisible by 100, or it is divisible by 400. Write a Java program that takes a year as input and uses a ternary operator to determine and display whether the provided year is a leap year or not. Input format: The input is the integer that represents the year. Output format: The output states whether the given year is leap year or not as shown in displayed test cases. Note: The code for handling inputs and outputs is already been given, your task is to fill in the required code. Sample Test Cases Explorer LeapYearChecker.java Submit 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ⌄ ⌄ package q22489; import java.util.Scanner; public class LeapYearChecker { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int year = scanner.nextInt(); String result = (year%==0)?"Leap year": "Not a leap year"; System.out.println(year + " is " + result); scanner.close(); } } Terminal Test cases Reason for late submission Eucs.Learner.Contents.LateSubmissionModal.Input.Placeholder Please enter at least 15 characters

1/3

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.