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
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...
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.
Selection/Conditional Structure: Create a flowchart and pseudocode for the problem below: Juan dela Cruz Restaurant is...
Selection/Conditional Structure: Create a flowchart and pseudocode for the problem below: Juan dela Cruz Restaurant is offering a 20% discount to all customers whose last name is also dela Cruz. Input the last name of the customer and the total amount due to the customer and then output the amount to be paid. (C++ Program, choose only the LAST NAME)
In this Java lab, you use the flowchart and pseudocode found in the figure below to...
In this Java lab, you use the flowchart and pseudocode found in the figure below to add code to a partially created Java program. When completed, college admissions officers should be able to use the Java program to determine whether to accept or reject a student, based on his or her test score and class rank. Declare the variables testScoreString and classRankString. Write the interactive input statements to retrieve: A student’s test score (testScoreString) A student's class rank (classRankString) Write...
For this assignment you have to create tables as reviewed in class Manufacturer table, Product table...
For this assignment you have to create tables as reviewed in class Manufacturer table, Product table and Stock table. The code is in Week 7 PPT lecture. You are to add update as needed to make the tables the same as below and match Product, Manufacturer and Stock as below. For this assignment you will be working with these same tables.   Please complete the following tasks and submit in word file or notepad. 1. First insert tuples into two of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT