1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
nataly862011 [7]
3 years ago
13

Days in a Month Write a class named MonthDays. The class’s constructor should accept two arguments: An integer for the month (1

= January, 2 = February, etc.) An integer for the year The class should have a method named getNumberOfDays that returns the number of days in the specified month. The method should use the following criteria to identify leap years: Determine whether the year is evenly divisible by 100. If it is, then it is a leap year if and only if it is evenly divisible by 400. For example, 2000 is a leap year, but 2100 is not. If the year is not evenly divisible by 100, then it is a leap year if and only if it is evenly divisible by 4. For example, 2008 is a leap year but 2009 is not. Demonstrate the class in a program that asks the user to enter the month (letting the user enter an integer in the range of 1 through 12) and the year. The program should then display the number of days in that month. Here is a sample run of the program:

Computers and Technology
1 answer:
shusha [124]3 years ago
8 0

Answer:

The java program for the given scenario is as shown below.

import java.util.*;

class MonthDays {

//variables as required

static int month;

static int year;

static int days;

//variables initialized inside constructor

MonthDays(int m, int y)

{

month=m;

year=y;

}

//method to compute number of days

static int getNumberOfDays()

{

if(year%400 ==0)

days=366;

if((year%100==0) && (year%4==0))

days=366;

else

days=365;

if(month==1) return 31;

if((month==2) && (days==365)) return 28;

if( (month==2) && (days==366)) return 29;

if(month==3) return 31;

if(month==4) return 30;

if(month==5) return 31;

if(month==6) return 30;

if(month==7) return 31;

if(month==8) return 31;

if(month==9) return 30;

if(month==10) return 31;

if(month==11) return 30;

else return 31;

}

}

public class Test

{ public static void main(String args[]) {

MonthDays ob = new MonthDays(1,2020);

int d=ob.getNumberOfDays();

System.out.print("The month has "+ d +" days");

}

}

Explanation:

1. The variables are declared to hold days in a year, month and the year. All the variables are declared static.

2. Inside constructor, the month and year variables are initialized.

3. Inside method, getNumberOfDays(), it is examined whether the year is leap year or not. The number of days are returned based on the month.

4. Inside another class, Test, having the main() method, an integer variable, d, is declared.

5. An object of the class MonthDays is declared having two parameters, month and year.

6. Using this variable, the method, getNumberOfDays() is called.  

7. The value returned in step 6 is stored in the integer variable, d.

8. The number of days in the given month is displayed.

9. The class Test is declared public since it contains the main() method.

10. The program is written in java since classes are required.

11. The program can be tested for the weekdays and month alike.

12. The output is attached in an image.

13. Since java is purely object-oriented language, program involving classes is best implemented in java.

You might be interested in
What is the name of the interface that uses graphics as compared to a command-driven interface?
bonufazy [111]
Answer = GUI (Graphical User Interface)
4 0
3 years ago
Which operating system is used by most the supercomputer system in the world
DENIUS [597]

Answer:

Linux

Explanation:

Linux runs all of the top 500 supercomputers

3 0
2 years ago
Define a function group-by-nondecreasing, which takes in a stream of numbers and outputs a stream of lists, which overall has th
Debora [2.8K]

Answer:

def group_by_nondecreasing( *args ) :

     num_list = [arg for arg in args]

     sorted_numlist = sorted( num_list )

     list_stream = [ sorted_numlist, sorted_numlist, sorted_numlist ]

     return list_stream

Explanation:

This python function has the ability to accept multiple and varying amount of arguments. the list comprehension shorten the logical for statement to generate a list of numbers, sorts the list in ascending order by default and duplicates the list in another list.

5 0
4 years ago
Traveling abroad to have sex with underage children is known as?
insens350 [35]
The correct answer I believe is A Sex offender
3 0
3 years ago
Read 2 more answers
Value: 3
Citrus2011 [14]

Answer:

B - A word is correctly spelled but is used incorrectly in a document

4 0
3 years ago
Other questions:
  • Which type of message format is designed to arouse curiosity, not showing the product or delivering quite enough information to
    10·1 answer
  • Olivia creates a personal budget. She enters her current savings account balance in cell D3. In cell A3, she calculates her inco
    8·1 answer
  • What education and training is required to be an applications software engineer?
    9·1 answer
  • Explain how the operating system controls the software and hardware on the computer?
    5·1 answer
  • Splunk knows where to break the event, where the time stamp is located and how to automatically create field value pairs using t
    7·1 answer
  • What connectionless protocols are implemented at the lower layers of the OSI model, what is usually used to acknowledge that the
    5·2 answers
  • The first step in the information processing cycle is _____, which involves entering data into the computer.
    8·1 answer
  • Explain how computer system is different from computer in 150 words
    14·1 answer
  • The owner of a candle shop has asked for your help. The shop sells three types of candles as shown below:
    14·1 answer
  • Ryan would like to copy a list of contacts from a colleague into his personal address book. The list of contacts is contained in
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!