I need help with pseudocode and flowgorithm chart. In Java, design a program tha
ID: 3859949 • Letter: I
Question
I need help with pseudocode and flowgorithm chart.
In Java, design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should then calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts.
Expected Output
Please enter the rainfall for JANUARY
1
Please enter the rainfall for FEBRUARY
3
Please enter the rainfall for MARCH
6
Please enter the rainfall for APRIL
8.5
Please enter the rainfall for MAY
5.5
Please enter the rainfall for JUNE
4
Please enter the rainfall for JULY
6
Please enter the rainfall for AUGUST
3
Please enter the rainfall for SEPTEMBER
4
Please enter the rainfall for OCTOBER
6.5
Please enter the rainfall for NOVEMBER
1
Please enter the rainfall for DECEMBER
0.5
The total annual rainfall was 49 inches
The average annual rainfall was 4.08333 inches
The month with the lowest rainfall was DECEMBER
The month with the highest rainfall was APRIL
Explanation / Answer
NOTE: I have provided the java code and pseudo code along with screenshot of java program execution. Please check and let me know if you face any issues. I will revert back within 24 hours.
Code:
import java.io.*;
import java.util.*;
public class HelloWorld{
public static void main(String []args){
String max_mon, min_mon;
double sum, max, min;
String[] mon_names = {"January", "February", "MARCH", "APRIL", "May", "June",
"July", "August", "September", "October", "November", "December"};
sum = max = min = 0;
max_mon = min_mon = "";
Scanner in = new Scanner(System.in);
for(int i = 0; i < 12; i++){
System.out.println("Please enter the rainfall for " + mon_names[i]);
double val = in.nextDouble();
sum += val;
// initializing max and min value to the first location of the array
if (i == 0) {
max = min = val;
max_mon = min_mon = mon_names[i];
continue;
}
// identifying max month here
if (val > max) {
max = val;
max_mon = mon_names[i];
}
// identifying min month here
if (val < min) {
min = val;
min_mon = mon_names[i];
}
}
System.out.println("The total annual rainfall was " + sum + " inches");
System.out.println("The average annual rainfall was "+ sum/12 + " inches");
System.out.println("The month with the lowest rainfall was "+ min_mon);
System.out.println("The month with the highest rainfall was "+ max_mon);
}
}
Code output screenshot:
https://pasteboard.co/GCqvXyg.png
pseudocode:
declare max_mon, min_mon as integers
declare sum, max, min as double
declare mon_names as a string of months {"January", "February", "MARCH", "APRIL", "May", "June",
"July", "August", "September", "October", "November", "December"}
declare val as double
sum <- max <- min <- 0
max_mon <- min_mon <- ""
Do for i <- 1 to 10
{
Display "Please enter the rainfall for ", mon_names[i]
read val
sum <- sum + val
if i == 0 then
{
max <- min <- val
max_mon <- min_mon <- mon_names[i]
continue
}
if val > max then
{
max <- val
max_mon <- mon_names[i]
}
if val < min then
{
min <- val
min <- mon_names[i]
}
}
Display "The total annual rainfall was " ,sum, " inches"
Display "The average annual rainfall was ",sum/12, " inches"
Display "The month with the lowest rainfall was ", min_mon
Display "The month with the highest rainfall was ", max_mon