Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java Program 1

BunkerHillBroad
BunkerHillBroad 


use file SeasonTest.java Write a method named season that takes as parameters two integers representing a month number and a day number, and returns a String that indicates the season for that month and day. Assume that the month is specified as an integer between 1 and 12 (1 for January, 2 for February, and so on), and that the day of the month is a number between 1 and 31. • If the date falls between 12/16 and 3/15, the method should return “winter” . • If the date falls between 3/16 and 6/15, the method should return “spring” . • If the date falls between 6/16 and 9/15, the method should return “summer” . • And if the date falls between 9/16 and 12/15, the method should return “fall” . Write a main method that clearly illustrates your program in action. For one additional point of “extra credit”, season should return “impossible” if an illegal date such as 15/3 or 11/31 gets passed to the method. You may assume that February always has 28 days, since we cannot determine whether we have a leap year without knowing the year. You must create a method that has return type String, it's not enough to just print the season in the method. Attachments
Tags Clarifications

Answers

Java Program 1 - Solution

mariobeka
mariobeka 



Implementation of the SeasonTest.
*It includes the implementation for the extra point.
Attachments
SeasonTest.java (1 K) Download Preview
// At position 0 is the number of days for January, continuing with days of February at // position 1 and so on. public final static int[] DAYS_OF_MONTHS = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; public static void main(String[] args) { System.out.println(season(11, 15)); }

Screenshots
Purchase Answer