6:48 99% ooo AT&T; public asu.edu ASU CSE 110 Assignment #6 Due date/Time: Wedne
ID: 3810570 • Letter: 6
Question
6:48 99% ooo AT&T; public asu.edu ASU CSE 110 Assignment #6 Due date/Time: Wednesday, Apr. 5th, 2017 at 5:30pm What this Assignment Is About: Leam to read data from user and fill an array. Given an array, learn to compute the sum, find minimum/maximun, etc Leam to write methods by passing an amay as input parameter Coding Guidelines for All LabsAssignments (You will be graded on this) Give identifiers semantic meaning and make them easy to read (examples numStudents, gross Pay, etc) Keep identifiers to areasonably short length. Use upper for case constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects). Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent. Use white space to make your program more readable. Use comments properly before or after the ending brace of classes. methods. and blocks to identify to which block it belongs. 1 Assignment description In this assignment, you will write a program that analyzes Phoenix area 2016 rainfall data. Inside the main method, first you will get the rainfall data for each of the 12 months in 2016 from the user and stores them in a double array. Next, you will need to design the following four value-returning methods that compute and retum to main the total Rainfall average Rainfall driest Months and wettestMonth. The last two methods retumthe index (or number) of the month with the lowest and highest rainfall amounts, not the amount of rain that fell those months. Notice that this month index (or number) can be used to obtain the amount of rain that fell those months. int petiett tatic int get After above computation, your program should display the following summary rainfall report on screen (by using main or write another displayReport method) 2016 Rain Report for Phoenix Az Total rainfall 9.55 inches Average monthly rainfall: 0.80 inchesExplanation / Answer
Assignment6.java
import java.text.DecimalFormat;
import java.util.Scanner;
public class Assignment6 {
public static double getTotalRainfall(double rainfall[])
{
double tot = 0;
for(int i = 0; i < rainfall.length; i++)
{
tot += rainfall[i];
}
return tot;
}
public static double getAverage(double rainfall[])
{
double total = getTotalRainfall(rainfall);
return total/rainfall.length;
}
public static int getWettestMonth(double rainfall[])
{
double maxR = rainfall[0];
int index = 0;
for(int i = 1; i < rainfall.length; i++)
{
if (maxR < rainfall[i])
{
maxR = rainfall[i];
index = i;
}
}
return index;
}
public static int getDriestMonth(double rainfall[])
{
double minR = rainfall[0];
int index = 0;
for(int i = 1; i < rainfall.length; i++)
{
if (minR > rainfall[i])
{
minR = rainfall[i];
index = i;
}
}
return index;
}
public static void main(String[] args)
{
double rainfall[] = new double[12];
String[] months = {"January", "February", "March", "April", "May",
"June", "July", "August", "September", "October",
"November", "December"};
Scanner sc = new Scanner(System.in);
for(int i = 0; i < 12; i++)
{
System.out.print("Enter "+ months[i] + " rainfall amount: ");
rainfall[i] = sc.nextDouble();
}
DecimalFormat df = new DecimalFormat("0.00");
System.out.println("=== 2016 Rain Report for Phoenix AZ ===");
System.out.println("Total rainfall: " + df.format(getTotalRainfall(rainfall)) + " inches");
System.out.println("Average monthly rainfall: " + df.format(getAverage(rainfall)) + " inches");
int least = getDriestMonth(rainfall);
System.out.println("The least rain fell in " + months[least] + " with " + df.format(rainfall[least]) + " inches.");
int most = getWettestMonth(rainfall);
System.out.println("The most rain fell in " + months[most] + " with " + df.format(rainfall[least]) + " inches.");
sc.close();
}
}
Sample run
Enter January rainfall amount: 0.91
Enter February rainfall amount: 0.92
Enter March rainfall amount: 0.99
Enter April rainfall amount: 0.38
Enter May rainfall amount: 0.21
Enter June rainfall amount: 0.11
Enter July rainfall amount: 1.05
Enter August rainfall amount: 1.60
Enter September rainfall amount: 0.94
Enter October rainfall amount: 0.58
Enter November rainfall amount: 0.78
Enter December rainfall amount: 1.08
=== 2016 Rain Report for Phoenix AZ ===
Total rainfall: 9.55 inches
Average monthly rainfall: 0.80 inches
The least rain fell in June with 0.11 inches.
The most rain fell in August with 0.11 inches.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.