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: to this method returns the season as a String
private static String monthToSeasonint monthNum
String season;
if monthNum monthNum
season No Season: Invalid Month Number";
else
if monthNum monthNum
season "Winter";
else
if monthNum
season "Spring";
else
if monthNum
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 elseif structure
instead of the nested ifelse structure used in monthToSeason
private static String monthToSeasonint monthNum
Your code starts here
Your code ends here
Given a season number: to this method returns the season as a String
private static String seasonNumToSeasonint seasonNum
String season;
if seasonNum
season "Spring";
else if seasonNum
season "Summer";
else if seasonNum
season "Autumn";
else if seasonNum
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 caseswitch structure
instead of the elseif structure used in seasonNumToSeason
private static String seasonNumToSeasonint seasonNum
Your code starts here
Your code ends here
public static void mainString args
for int i ; i ; i
System.out.printlnMonth Number i ; Season
monthToSeasoni;
for int i ; i ; i
System.out.printlnSeason Number i ; Season
seasonNumToSeasoni;
OUTPUT:
Month Number ; Season No Season: Invalid Month Number
Month Number ; Season Winter
Month Number ; Season Winter
Month Number ; Season Spring
Month Number ; Season Spring
Month Number ; Season Spring
Month Number ; Season Summer
Month Number ; Season Summer
Month Number ; Season Summer
Month Number ; Season Autumn
Month Number ; Season Autumn
Month Number ; Season Autumn
Month Number ; Season Winter
Month Number ; Season No Season: Invalid Month Number
Season Number ; Season No Season: Invalid Season Number
Season Number ; Season Spring
Season Number ; Season Summer
Season Number ; Season Autumn
Season Number ; Season Winter
Season Number ; Season No Season: Invalid Season Number
INSTRUCTIONS:
Complete the code by writing the body of the bodyless 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
