Question
What is the UML diagram for this program: MonthDaysTest.java import java.util.Scanner; public class MonthDaysTest { public static void main(String[] args) { Scanner scan = new
What is the UML diagram for this program:
MonthDaysTest.java
import java.util.Scanner;
public class MonthDaysTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter a month (1-12): ");
int month = scan.nextInt();
System.out.println("Enter a year: ");
int year = scan.nextInt();
MonthDays m = new MonthDays(month, year);
System.out.println(m.getNumberOfDays()+" days");
}
}
MonthDays.java
public class MonthDays {
private int month ;
private int year;
public MonthDays(int m, int y){
month = m;
year = y;
}
public int getNumberOfDays(){
int days = 0;
if(month ==1 || month == 3 || month ==5 || month == 7 || month ==8 || month == 10 || month == 12){
days = 31;
}
else if(month == 4 || month == 6 || month == 9 || month ==11){
days = 30;
}
else if(month == 2){
if ((year%4 == 0 && year%100 !=0)|| year%400 == 0)
days = 29;
else
days = 28;
}
return days;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started