Question

In: Computer Science

Homework Arrays and Tables In this assignment you are to create an algorithm, flowchart, and pseudocode...

Homework

Arrays and Tables

In this assignment you are to create an algorithm, flowchart, and pseudocode for a solution of the following problem. This solution will include the use of arrays needed to complete all parts of the logic.

You have requested to develop a program that will record and process the rainfall totals of a 12 month period. You would use an array to store each months total. Once all 12 months amounts are entered then your solution need to process this array to complete the following requirements:

The user wants to know the total rainfall for the year.

Then you will need to calculate the average monthly rainfall

You will then need to find the month with the most rainfall and the month with the least amount of rainfall

When you have completed this assignment drop it into the dropbox for this assignment.

Solutions

Expert Solution

RainfallTest.java


import java.util.Arrays;
import java.util.Scanner;

public class RainfallTest {

  
   static String month[] = {"January", "Fabruary", "March", "April", "May", "June", "July", "August", "September","October","November","December"};
  
   public static void main(String[] args) {
           double monthlyRainfall[] = new double[12];
           Scanner scan = new Scanner(System.in);
           for(int i=0; i<monthlyRainfall.length; i++){
               System.out.print("Enter rainfall amount (in inches) for "+month[i]+":");
               monthlyRainfall[i] = scan.nextDouble();
           }
           System.out.println("Entered rainfall details "+Arrays.toString(monthlyRainfall));
               displayTotalRainFall(monthlyRainfall);
               displayAverageRainFall(monthlyRainfall);
               displayMaximumRainFall(monthlyRainfall);
               displayMinimumRainFall(monthlyRainfall);
              
          
   }
   public static void displayEachMonthRainFall(double months[]){
       for(int i=0; i<months.length; i++){
           System.out.println(month[i]+": "+months[i]);
       }
   }
   public static void displayTotalRainFall(double months[]){
       double total = 0;
       for(int i=0; i<months.length; i++){
           total = total + months[i];
       }
       System.out.printf("Total Rainfall for the Year (in inches): %.2f\n",total);
   }
   public static void displayAverageRainFall(double months[]){
       double total = 0;
       double avg = 0;
       for(int i=0; i<months.length; i++){
           total = total + months[i];
       }
       avg = total/(double)months.length;
       System.out.printf("Average Rainfall for the Year (in inches): %.2f\n",avg);
   }
   public static void displayMaximumRainFall(double months[]){
       double max = 0;
       for(int i=0; i<months.length; i++){
           if(max < months[i]){
               max = months[i];
           }
       }
       System.out.println("Maximum Monthly Rainfall (in inches): "+max);
   }
   public static void displayMinimumRainFall(double months[]){
       double min = months[0];
       for(int i=0; i<months.length; i++){
           if(min > months[i]){
               min = months[i];
           }
       }
       System.out.println("Minimum Monthly Rainfall (in inches): "+min);
   }
}

Output:

Enter rainfall amount (in inches) for January:22
Enter rainfall amount (in inches) for Fabruary:21
Enter rainfall amount (in inches) for March:33
Enter rainfall amount (in inches) for April:44
Enter rainfall amount (in inches) for May:55
Enter rainfall amount (in inches) for June:11
Enter rainfall amount (in inches) for July:88
Enter rainfall amount (in inches) for August:66
Enter rainfall amount (in inches) for September:77
Enter rainfall amount (in inches) for October:25
Enter rainfall amount (in inches) for November:45
Enter rainfall amount (in inches) for December:32
Entered rainfall details [22.0, 21.0, 33.0, 44.0, 55.0, 11.0, 88.0, 66.0, 77.0, 25.0, 45.0, 32.0]
Total Rainfall for the Year (in inches): 519.00
Average Rainfall for the Year (in inches): 43.25
Maximum Monthly Rainfall (in inches): 88.0
Minimum Monthly Rainfall (in inches): 11.0


Related Solutions

Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the...
Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the following requirements: Reads in a series of positive integers,  one number at a time;  and Calculate the product (multiplication) of all the integers less than 25,  and Calculate the sum (addition) of all the integers greater than or equal to 25. Use 0 as a sentinel value, which stops the input loop. [ If the input is 0 that means the end of the input list. ]...
Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user...
Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user unless he enters '$'. Thereafter display how may vowels were entered by the user. Also display the number of each vowel ('a', 'e', 'i', 'o' and 'u') separately. For example if the user enters B a b e c o o d i u g o a l $ Then we have the output below: #A=2 #E=1 #I=1 #O=3 #U=2
Write an algorithm (flowchart OR Pseudocode) for the following problems: Take ten different numbers as input...
Write an algorithm (flowchart OR Pseudocode) for the following problems: Take ten different numbers as input and display the sum of there squares (SS). Example: let the inputs are: 3, 0, -1, 0, 9, -5, 6, 0, 2, 1 then 157 is displayed, because: SS=32+02+(-1)2+02+92+(-5)2+62+02+22+12=157 Take input character from the user unless he enters '$'. Thereafter display how may vowels were entered by the user. Also display the number of each vowel ('a', 'e', 'i', 'o' and 'u') separately. For...
Using RAPTOR Create a flowchart and create the pseudocode for the following question Le Chef Heureux...
Using RAPTOR Create a flowchart and create the pseudocode for the following question Le Chef Heureux Restaurant has 20 tables that can be reserved at 5 p.m., 7 p.m., or 9 p.m. Design a program that accepts reservations for specific tables at specific times; the user enters the number of customers, the table number, and the time. Do not allow more than four guests per table or invalid table numbers or times. If an attempt is made to reserve a...
For this assignment, you will create flowchart using Flowgorithm to represent the logic of a program...
For this assignment, you will create flowchart using Flowgorithm to represent the logic of a program that allows the user to enter a number of dollars and convert it to Euros and Japanese yen. You will have to do some research on current rates of monetary exchange for this one. Don't forget to declare your variables and use output statements to prompt the user to enter specific values prior to including an input statement. You will use an assignment statement...
Given two unsorted arrays of integers. a) Write a pseudocode algorithm which will output only the...
Given two unsorted arrays of integers. a) Write a pseudocode algorithm which will output only the integers not common to both arrays. When writing pseudocode, consider that no implementation for data structures or algorithms exist. b) Implement your algorithm in Modern C++
create flowchart using Flowgorithm and Pseudocode for the following program example:   Design a program for Jones...
create flowchart using Flowgorithm and Pseudocode for the following program example:   Design a program for Jones College. The current tuition is $12,000 per year, and tuition is expected to increase by 5 percent each year. Display the tuition amount for each year over the next five years (use a looping structure).
Show your results all planning tools (algorithm, IPO chart, desk checking, pseudocode, flowchart) for an application...
Show your results all planning tools (algorithm, IPO chart, desk checking, pseudocode, flowchart) for an application that allows a user to enter the price of an item and computes 6.25 percent sales tax on the item.
Show your results using all planning tools (algorithm, IPO chart, desk checking, pseudocode, flowchart) for an...
Show your results using all planning tools (algorithm, IPO chart, desk checking, pseudocode, flowchart) for an application that allows a user to enter the number of text messages he or she sent last month and then displays the bill. Messages cost 25 cents each, and 8 percent tax is charged on the total.
Write an algorithm and draw a flowchart for the following problem: Create an adaptive cruise control...
Write an algorithm and draw a flowchart for the following problem: Create an adaptive cruise control for a car. Include functions for enabling/disabling the cruise control; setting up the speed. The system should always maintain the speed unless there is a slower car in front of it. Make sure to define inputs and outputs. Do not forget that computer’s microprocessor works in very small steps (tiny steps!), so be careful not to assign large number of steps to one flowchart...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT