Question: How to solve Below is a partial code for a class followed by the output that would be displayed on the screen when we run

How to solve Below is a partial code for a class followed by the output that would be displayed on the screen when we run the class:
CODE:
public class Decision {
// Given a monthNum number: 1 to 12, this method returns the season as a String
private static String monthToSeason(int monthNum){
String season;
if (monthNum <1|| monthNum >12){
season ="No Season: Invalid Month Number";
}
else {
if (monthNum <3|| monthNum >11){
season = "Winter";
}
else {
if (monthNum <6){
season = "Spring";
}
else {
if (monthNum <9){
season = "Summer";
}
else {
season = "Autumn";
}
}
}
}
return season;
}
// This method does exactly what the above method, monthToSeason does
// The only difference is that this one uses an else-if structure
// instead of the nested if-else structure used in monthToSeason
private static String monthToSeason2(int monthNum){
// Your code starts here
// Your code ends here
}
// Given a season number: 1 to 4, this method returns the season as a String
private static String seasonNumToSeason(int seasonNum){
String season;
if (seasonNum ==1)
season = "Spring";
else if (seasonNum ==2)
season = "Summer";
else if (seasonNum ==3)
season = "Autumn";
else if (seasonNum ==4)
season = "Winter";
else
season ="No Season: Invalid Season Number";
return season;
}
// This method does exactly what the above method, seasonNumToSeason does
// The only difference is that this one uses a case-switch structure
// instead of the else-if structure used in seasonNumToSeason
private static String seasonNumToSeason2(int seasonNum){
// Your code starts here
// Your code ends here
}
public static void main(String[] args){
for (int i =0; i <14; i++)
System.out.println("Month Number ="+ i +"; Season ="+
monthToSeason2(i));
for (int i =0; i <6; i++)
System.out.println("Season Number ="+ i +"; Season ="+
seasonNumToSeason2(i));
}
}
OUTPUT:
Month Number =0; Season = No Season: Invalid Month Number
Month Number =1; Season = Winter
Month Number =2; Season = Winter
Month Number =3; Season = Spring
Month Number =4; Season = Spring
Month Number =5; Season = Spring
Month Number =6; Season = Summer
Month Number =7; Season = Summer
Month Number =8; Season = Summer
Month Number =9; Season = Autumn
Month Number =10; Season = Autumn
Month Number =11; Season = Autumn
Month Number =12; Season = Winter
Month Number =13; Season = No Season: Invalid Month Number
Season Number =0; Season = No Season: Invalid Season Number
Season Number =1; Season = Spring
Season Number =2; Season = Summer
Season Number =3; Season = Autumn
Season Number =4; Season = Winter
Season Number =5; Season = No Season: Invalid Season Number
INSTRUCTIONS:
Complete the code by writing the body of the body-less methods. Your code must go between the comments "// Your code starts here" and "// Your code ends here." Do not make any other modifications to the code.
Copy and paste the partial code to the answer box and complete it. You may also copy it to a Java development environment, complete it, and test the code. In that case, copy the completed code to the answer box after you are done testing.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!