I am trying to execute a program called AverageRainfall. Most of the input works well (my while statement at the beginning is fine), but there are multiple months under the variable monthRain, and the while statement for monthRain is not functioning with the various months, only the initial input command, which is serving no purpose.
ETA: Posting entire code for testing
import java.util.Scanner; //for Scanner class
public class AverageRainfall
{
public static void main(String[] args)
{
final int NUM_MONTHS = 12; //Months per year
int years; //Number of years
double monthRain; //Rain for a month
double totalRain = 0; //Rainfall accumulator
double average; //Average rainfall
Scanner keyboard = new Scanner(System.in);
{
System.out.print("Enter the number of years: ");
years = keyboard.nextInt();
while (years < 1)
{
System.out.print("Invalid. Enter 1 or greater: ");
years = keyboard.nextInt();
}
}
{
System.out.println("Enter the rainfall, in inches, for each month. ");
monthRain = keyboard.nextDouble();
for(int y = 1; y <= years; y++){
for(int m = 1; m <= NUM_MONTHS; m++){
System.out.print("Year" + y + "month" + m + ": ");
monthRain = keyboard.nextDouble();
}
}
while (monthRain < 0)
{
System.out.print("Invalid. Enter 0 or greater: ");
monthRain = keyboard.nextDouble();
}
}
{
totalRain += monthRain;
average = totalRain / (years * NUM_MONTHS);
System.out.println("\nNumber of months: " + (years * NUM_MONTHS) );
System.out.println("Total rainfall: " + totalRain + " inches");
System.out.println("Average monthly rainfall: " + average + " inches");
}
}
}
This is the entire code.
You were using unnecessary braces. Moreover, some logical flaws were also present in your code. I have fixed your code. Please refer the following code:
import java.util.Scanner; //for Scanner class
public class AverageRainfall {
public static void main(String[] args) {
final int NUM_MONTHS = 12; // Months per year
int years; // Number of years
double monthRain=0; // Rain for a month
double totalRain = 0; // Rainfall accumulator
double average; // Average rainfall
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the number of years: ");
years = keyboard.nextInt();
while (years < 1) {
System.out.print("Invalid. Enter 1 or greater: ");
years = keyboard.nextInt();
}
System.out.println("Enter the rainfall, in inches, for each month. ");
for (int y = 1; y <= years; y++) {
for (int m = 1; m <= NUM_MONTHS; m++) {
System.out.print("Year" + y + "month" + m + ": ");
monthRain = keyboard.nextDouble();
while (monthRain < 0) {
System.out.print("Invalid. Enter 0 or greater: ");
monthRain = keyboard.nextDouble();
}
totalRain += monthRain;
}
}
average = totalRain / (years * NUM_MONTHS);
System.out.println("\nNumber of months: " + (years * NUM_MONTHS));
System.out.println("Total rainfall: " + totalRain + " inches");
System.out.println("Average monthly rainfall: " + average
+ " inches");
}
}
What you can do is add to the total of Rain each time the user inputs a month rain. Then you can do the average once he finishes inputting data.
`import java.util.Scanner;
public class test {
public static void main(String[]args){
double monthRain=0;
double totalRain=0;
Scanner keyboard = new Scanner(System.in);
int years = 1;
int NUM_MONTHS = 12;
System.out.println("Enter the rainfall, in inches, for each month. ");
for(int y = 1; y <= years; y++){
for(int m = 1; m <= NUM_MONTHS; m++){
System.out.print("Year" + y + "month" + m + ": ");
monthRain = keyboard.nextDouble();
totalRain+=monthRain;
}
}
int totalMonth = years*NUM_MONTHS;
System.out.println("\nNumber of months: " + totalMonth );
System.out.println("Total Rain: "+totalRain+" inches");
double average = totalRain / totalMonth;
System.out.println("Average monthly rainfall: " + average + " inches");
}
}
`
Related
We get a total of 47 because of [5 + 23 - 3 + 14 - (-8)]. My question is what formula should I use to get a total of 47 from the example?
This is my code but I always get an answer of -8 for some reason. Any help is much appreciated!
Scanner input = new Scanner(System.in);
System.out.print("Enter value of n: ");
nValue = input.nextInt();
for (int x = 1; x <= nValue; x++){
System.out.print("Enter number " + x + ": ");
num1 = input.nextInt();
num2 = num1 + num1;
total = num2 - num1;
}
System.out.println("Answer: " + total);
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter the value of n");
int n=obj.nextInt();
System.out.println("Enter"+1+"Number : ");
int num=obj.nextInt();
int sum=num;
for(int i=2;i<=n;i++){
System.out.println("Enter"+i+"Number : ");
num=obj.nextInt();
if(i%2==0){
sum=sum+num;
}
else{
sum=sum-num;
}
}
System.out.println("Answer: "+sum);
}
}
Not using loops but this does give the output you're asking for
Scanner input = new Scanner(System.in);
System.out.print("Enter value of n: ");
int n =input.nextInt();
System.out.print("Enter " + n + " integers: \n");
Scanner input = new Scanner(System.in);
System.out.print("Enter value of n: ");
int n =input.nextInt();
System.out.print("Enter " + n + " integers: \n");
System.out.print("Enter number 1:");
int num1 = input.nextInt();
System.out.print("Enter number 2:");
int num2 = input.nextInt();
System.out.print("Enter number 3:");
int num3 = input.nextInt();
System.out.print("Enter number 4:");
int num4 = input.nextInt();
System.out.print("Enter number 5:");
int num5 = input.nextInt();
int a = num1 + num2;
int b = a - num3;
int c = b + num4;
int d = c - num5;
System.out.print("Answer: " + d);
To determine whether you should add to, or subtract from the total, you just need to check the value of x.
If x is even or equal to 1, you add to the total. Otherwise you subtract:
for (int x = 1; x <= nValue; x++){
System.out.print("Enter number " + x + ": ");
num1 = input.nextInt();
if (x % 2 == 0 || x == 1) {
total += num1;
} else {
total -= num1;
}
}
System.out.println("Answer: " + total);
It appears you are adding an extra step that is resetting instead of adding values. Here is a way to keep adding to the total value and only keeping track of the immediate input.
Updated for any future passer-bys
Scanner input = new Scanner(System.in);
System.out.print("Enter value of n: ");
nValue = input.nextInt();
//variable for total value before loop
int total = 0
for (int x = 1; x <= nValue; x++){
System.out.print("Enter number " + x + ": ");
num = input.nextInt();
//add or subtract to total with each iteration (updated logic)
if (x%2==0){
total += num;
}
else {
total -= num;
}
}
System.out.println("Answer: " + total);
Use the for loop to write a program to prompt the user to enter twelve n amount of numbers and then display the minimum, maximum, sum and the average of these numbers.
I don't can't puzzle how I would use a for loop in order to this, I've been having a bit of trouble.
import java.util.Scanner;
public class Loop{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter number 1: ");
double a = scanner.nextDouble();
System.out.println("Enter number 2: ");
double b = scanner.nextDouble();
System.out.println("Enter number 3: ");
double c = scanner.nextDouble();
System.out.println("Enter number 4: ");
double d = scanner.nextDouble();
System.out.println("Enter number 5: ");
double e = scanner.nextDouble();
System.out.println("Enter number 6: ");
double f = scanner.nextDouble();
System.out.println("Enter number 7: ");
double g = scanner.nextDouble();
System.out.println("Enter number 8: ");
double h = scanner.nextDouble();
System.out.println("Enter number 9: ");
double i = scanner.nextDouble();
System.out.println("Enter number 10: ");
double j = scanner.nextDouble();
System.out.println("Enter number 11: ");
double k = scanner.nextDouble();
System.out.println("Enter number 12: ");
double l = scanner.nextDouble();
double minNum = Math.min(a, Math.min(b, Math.min(c, Math.min(d, Math.min(e, Math.min(f, Math.min(g, Math.min(h, Math.min(i , Math.min(j, Math.min(k, l)))))))))));
double maxNum = Math.max(a, Math.max(b, Math.max(c, Math.max(d, Math.max(e, Math.max(f, Math.max(g, Math.max(h, Math.max(i , Math.max(j, Math.max(k, l)))))))))));
double sumNum = (a + b + c + d + e + f + g + h + i + j + k + l);
for(int i = 0; )
}
}
I expected the output to be used with the for loop, but then again I do not understand how I would use it in this method.
Here is a nicer way to do this, which doesn't even require storing all the numbers at once. The approach here is to keep a running tab on the largest and smallest input, as each new number is input. Also, we maintain a running total of all numbers entered, which later easily can be used to compute the average.
Scanner scanner = new Scanner(System.in);
double max, min, avg;
double total = 0.0d;
boolean first = true;
int numbers = 12;
for (int i=0; i < numbers; ++i) {
System.out.println("Enter number:");
double d = scanner.nextDouble();
if (first) {
max = d;
min = d;
total = d;
first = false;
}
else {
if (d > max) {
max = d;
}
else if (d < min) {
min = d;
}
total += d;
}
}
avg = total / numbers;
System.out.println("max: " + max + ", min: " + min + ", avg: " + avg);
Note that a more advanced approach might be to do something like store all 12 numbers into a list, and then leverage the Java 8 stream API to find the max, min, and average. But I suspect that is not the answer you want for your question.
Place this java code in the main function
`Scanner s=new Scanner(System.in);
int t=s.nextInt(); //12
int sum=0;
int min=Integer.MIN_VALUE;
int max=Integer.MAX_VALUE;
for(int i=0;i<t;i++){
int temp=s.nextInt();
if(temp<min)
min=temp;
if(temp>max)
max=temp;
sum+=temp;
}
System.out.println(min +" "+max+" "+sum);`
You can do this.
Scanner scanner = new Scanner(System.in);
double max = Double.MAX_VALUE, min = Double.MIN_VALUE, total = 0.00d;
int n = 12; // Change this to the number of values needed
for (int i=0; i < n; i++) {
System.out.println("Enter number:");
double d = scanner.nextDouble();
if (d > max) {
max = d;
}
else if (d < min) {
min = d;
}
total += d;
}
Double avg = total / n;
System.out.println("max: " + max + ", min: " + min + ", avg: " + avg);
I'm new to Java, and am attempting to do an assignment...but am feeling lost right about now. We haven't been introduced to arrays yet, so our vocabulary is a bit limited.
1.) Modify your current code so that it will handle multiple years of rainfall data. Give the option to the user to supply the actual number of years they want to enter in the program for evaluation. This program must output the year (i.e. Year 1, Year 2, etc.) for most rainfall and the year with the least amount of total rainfall.
Below is my code:
import java.util.Scanner;
public class Test2OF
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
double[] rainfall = new double[4];
double totalRainfall = 0.0;
double max = 0, min = 0;
int year = scan.nextInt();
int maxQuarter = 1;
int minQuarter = 1;
// Prompt user for the number of years
System.out.println("Enter the number of years: ");
year = scan.nextInt();
for (int i=0; i < year*4; i++)
{
System.out.print("Enter rainfall for quarter " + (i+1) + ": ");
rainfall[i] = scan.nextDouble();
totalRainfall += rainfall[i];
if (i == 0)
{
max = min = rainfall[i];
}
{
if (rainfall[i] > max) {
max = rainfall[i];
maxQuarter = i + 1;
}
if (rainfall[i] < min) {
min = rainfall[i];
minQuarter = i + 1;
}
}
}
System.out.println("Total rainfall = "+totalRainfall);
System.out.println("Average rainfall = "+(totalRainfall / 4.0));
System.out.println("Max quarter rainfall = "+ max);
System.out.println("Min quarter rainfall = " + min);
System.out.println("Max quarter rainfall = "+ maxQuarter);
System.out.println("Min quarter rainfall = " + minQuarter);
}//end main
}//end class
Upon compiling, I get this exception when I try to put data in for quarter 5.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at Test2OF.main(Test2OF.java:22)
I'm also pretty clueless as to how I can specify what year had the most/least amount of rainfall at the end.
Your help is appreciated! Thank you very much.
problem:
year*4
Your rainfall is only of a size 4 which means it is only good for 1 year which has 4 quarter.
solution:
You need to calculate the number of quarter of the specified number of years and then resize your array by using year*4
sample:
Scanner scan = new Scanner(System.in);
double[] rainfall;
double totalRainfall = 0.0;
double max = 0, min = 0;
int year = 0;
int maxQuarter = 1;
int minQuarter = 1;
System.out.println("Enter the number of years: ");
year = scan.nextInt();
rainfall = new double[year*4]
EDIT:
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
double[] rainfall;
int curyear = 0;
double totalRainfall = 0.0;
double max = 0, min = 0;
int year = 0;
int maxQuarter = 1;
int minQuarter = 1;
// Prompt user for the number of years
System.out.println("Enter the number of years: ");
year = scan.nextInt();
rainfall = new double[year*4];
for (int i=0; i < year*4 + 1; i++)
{
if((i % 4) == 0 && i != 0)
{
System.out.println();
System.out.println("YEAR: " + ++curyear );
System.out.println("Total rainfall = "+totalRainfall);
System.out.println("Average rainfall = "+(totalRainfall / 4.0));
System.out.println("Max quarter rainfall = "+ max);
System.out.println("Min quarter rainfall = " + min);
System.out.println("Max quarter rainfall = "+ maxQuarter);
System.out.println("Min quarter rainfall = " + minQuarter);
System.out.println();
if(i == (year*4))
break;
}
System.out.print("Enter rainfall for quarter " + (i+1) + ": ");
rainfall[i] = scan.nextDouble();
totalRainfall += rainfall[i];
if (i == 0)
{
max = min = rainfall[i];
}
{
if (rainfall[i] > max) {
max = rainfall[i];
maxQuarter = i + 1;
}
if (rainfall[i] < min) {
min = rainfall[i];
minQuarter = i + 1;
}
}
}
}//end main
new double[4]; this is wrong.
if you get size from user then why you initialized?
give size after user provide size like new double[year];
First thing I notice right off of the bat is
Int year = Scanner.nextInt();
Blahblahblah
year = Scanner.nextInt();
Don't give year a value yet.
Int year;
Year = scanner.nextInt();
As for the rest I don't know if I want to help you on this. It is unethical to assist you because the point of this is to learn. Note that it is perfectly fine to tell you professor that you were unable to complete the assignment and that he would be of better assistance than the internet.
Sent from iPad so please excuse spelling and capitalization mistakes
Everything is working fine, I just need my output to say the quarter with the highest/lowest rainfall, not the actual values. I am not sure how to tie the quarter and the values together so that the output will be quarter 1, 2, 3 or 4.
import java.util.Scanner;
public class rainfall
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
double[] rainfall = new double[4];
double totalRainfall = 0.0;
double max = 0, min = 0;
for (int i=0; i < 4; i++)
{
System.out.print("Enter rainfall for quarter " + (i+1) + ": ");
rainfall[i] = scan.nextDouble();
totalRainfall += rainfall[i];
if (i == 0)
{
max = min = rainfall[i];
}
{
if (rainfall[i] > max)
max = rainfall[i];
else if (rainfall[i] < min)
min = (i + 1);
//min = rainfall[i];
}
}
System.out.println("Total rainfall = "+totalRainfall);
System.out.println("Average rainfall = "+(totalRainfall / 4.0));
System.out.println("Max quarter rainfall = "+ max);
System.out.println("Min quarter rainfall = " + min);
//System.out.println("Max quarter rainfall = "+ maxQuarter);
//System.out.println("Min quarter rainfall = " + minQuarter);
}//end main
}//end class
Just store the indexes instead of the values:
if (rainfall[i] > rainfall[max])
max = i;
else if (rainfall[i] < rainfall[min])
min = i;
System.out.println("Max quarter rainfall = " + max + 1);
System.out.println("Min quarter rainfall = " + min + 1);
You need to track maxQuarter and minQuarter (added as ints) as well as max and min. Like so:
import java.util.Scanner;
public class rainfall
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
double[] rainfall = new double[4];
double totalRainfall = 0.0;
double max = 0, min = 0;
// init to Q1 as that's the 1st tested
int maxQuarter = 1, minQuarter = 1;
for (int i=0; i < 4; i++)
{
System.out.print("Enter rainfall for quarter " + (i+1) + ": ");
rainfall[i] = scan.nextDouble();
totalRainfall += rainfall[i];
if (i == 0)
{
max = min = rainfall[i];
}
{
if (rainfall[i] > max) {
max = rainfall[i];
maxQuarter = i + 1;
}
if (rainfall[i] < min) {
min = rainfall[i];
minQuarter = i + 1;
}
}
}
System.out.println("Total rainfall = "+totalRainfall);
System.out.println("Average rainfall = "+(totalRainfall / 4.0));
System.out.println("Max quarter rainfall = "+ max);
System.out.println("Min quarter rainfall = " + min);
System.out.println("Max quarter rainfall = "+ maxQuarter);
System.out.println("Min quarter rainfall = " + minQuarter);
}//end main
}//end class
With these changes, it runs fine for my basic tests:
Enter rainfall for quarter 1: 2
Enter rainfall for quarter 2: 4
Enter rainfall for quarter 3: 6
Enter rainfall for quarter 4: 7
Total rainfall = 19.0
Average rainfall = 4.75
Max quarter rainfall = 7.0
Min quarter rainfall = 2.0
Max quarter rainfall = 4
Minquarter rainfall = 1
You should format your code (Ctrl+Shift+f in Eclipse).
Keep the i index in parallel to the min and max, something like imax, imin. Otherwise you lose the origin of the values like in your case.
I am creating a program that calculates rainfall for the year etc. I had the first block of code below working with the user input, perfectly. However, I am trying to change the program now, so that the array values are specified (I'm basically trying to eliminate the user input).
Why isn't the second block of code working? I am getting errors at the bottom for r.getTotalRainFall, r.getAverageRainFall etc.
Please note that I had to introduce the array thisYear (this is required).
CODE BLOCK #1:
import java.util.*;
public class Rainfall {
Scanner in = new Scanner(System.in);
int month = 12;
double total = 0;
double average;
double months[];
public Rainfall() {
months = new double[12];
}
public void enterMonthData() {
for (int n = 1; n <= month; n++) {
System.out.print("Enter the rainfall (in inches) for month #" + n + ": ");
months[n - 1] = in.nextDouble();
// Input Validation - Cannot accept a negative number
while (months[n - 1] < 0) {
System.out.print("Rainfall must be at least 0. Please enter a new value.");
months[n - 1] = in.nextDouble();
}
}
}
public double getTotalRainFall() {
total = 0;
for (int i = 0; i < 12; i++) {
total = total + months[i];
}
return total;
}
public double getAverageRainFall() {
average = total / 12;
return average;
}
/**
* Returns the index of the month with the highest rainfall.
*/
public int getHighestMonth() {
int highest = 0;
for (int i = 0; i < 12; i++) {
if (months[i] > months[highest]) {
highest = i;
}
}
return highest;
}
/**
* Returns the index of the month with the lowest rainfall.
*/
public int getLowestMonth() {
int lowest = 0;
for (int i = 0; i < 12; i++) {
if (months[i] < months[lowest]) {
lowest = i;
}
}
return lowest;
}
public static void main(String[]args) {
Rainfall r = new Rainfall();
r.enterMonthData();
System.out.println("The total rainfall for this year is " + r.getTotalRainFall());
System.out.println("The average rainfall for this year is " + r.getAverageRainFall());
int lowest = r.getLowestMonth();
int highest = r.getHighestMonth();
System.out.println("The month with the highest amount of rain is " + (highest+1) + " with " + r.months[highest] + " inches");
System.out.println("The month with the lowest amount of rain is " + (lowest+1) + " with " + r.months[lowest] + " inches");
}
}
CODE BLOCK #2:
package rain;
public class Rain {
int month = 12;
double total = 0;
double average;
double getRainAt[];
public Rain {
getRainAt = new double[12];
}
double getTotalRainFall() {
total = 0;
for (int i = 0; i < 12; i++) {
total = total + getRainAt[i];
}
return total;
}
double getAverageRainFall() {
average = total / 12;
return average;
}
int getHighestMonth() {
int high = 0;
for (int i = 0; i < 12; i++) {
if (getRainAt[i] > getRainAt[high]) {
high = i;
}
}
return high;
}
int getLowestMonth() {
int low = 0;
for (int i = 0; i < 12; i++) {
if (getRainAt[i] < getRainAt[low]) {
low = i;
}
}
return low;
}
public static void main(String[] args) {
// Create an array of rainfall figures.
double[] thisYear = {1.6, 2.1, 1.7, 3.5, 2.6, 3.7,
3.9, 2.6, 2.9, 4.3, 2.4, 3.7 };
int high; // The high month
int low; // The low month
// Create a RainFall object initialized with the figures
// stored in the thisYear array.
Rainfall r = new Rainfall(thisYear);
// Display the statistics.
System.out.println("The total rainfall for this year is " +
r.getTotalRainFall();
System.out.println("The average rainfall for this year is " +
r.getAverageRainFall());
high = r.getHighestMonth();
System.out.println("The month with the highest amount of rain " +
"is " + (high+1) + " with " + r.getRainAt(high) +
" inches.");
low = r.getLowestMonth();
System.out.println("The month with the lowest amount of rain " +
"is " + (low+1) + " with " + r.getRainAt(low) +
" inches.");
}
}
}
I have re-factored the 2 classes
now Rain class only contains the main method whereas all the other logic is contained in the Rainfall class
Rainfall class has a method - getRainAt() to get rain base don the given month
in Rainfall class has a constructor that takes a double array as an argument so it has to be instantiated with this argument provided.
take a look at the classes now and see if this fits your requirement.
import java.util.*;
public class Rainfall {
Scanner in = new Scanner(System.in);
int month = 12;
double total = 0;
double average;
double months[];
public Rainfall(double newmonths[]){
months = newmonths;
}
public void enterMonthData() {
for (int n = 1; n <= month; n++) {
System.out.print("Enter the rainfall (in inches) for month #" + n
+ ": ");
months[n - 1] = in.nextDouble();
// Input Validation - Cannot accept a negative number
while (months[n - 1] < 0) {
System.out
.print("Rainfall must be at least 0. Please enter a new value.");
months[n - 1] = in.nextDouble();
}
}
}
public double getTotalRainFall() {
total = 0;
for (int i = 0; i < 12; i++) {
total = total + months[i];
}
return total;
}
public double getAverageRainFall() {
average = total / 12;
return average;
}
/**
* get rain given the month number
*/
public double getRainAt(int month){
double rainValue = 0;
for (int i = 0; i < months.length; i++) {
if(month == i){
rainValue = months[i];
break;
}
}
return rainValue;
}
/**
* Returns the index of the month with the highest rainfall.
*/
public int getHighestMonth() {
int highest = 0;
for (int i = 0; i < 12; i++) {
if (months[i] > months[highest]) {
highest = i;
}
}
return highest;
}
/**
* Returns the index of the month with the lowest rainfall.
*/
public int getLowestMonth() {
int lowest = 0;
for (int i = 0; i < 12; i++) {
if (months[i] < months[lowest]) {
lowest = i;
}
}
return lowest;
}
}
Rain class only has the main method now
public class Rain {
public static void main(String[] args) {
// Create an array of rainfall figures.
double[] thisYear = { 1.6, 2.1, 1.7, 3.5, 2.6, 3.7, 3.9, 2.6, 2.9, 4.3,
2.4, 3.7 };
int high; // The high month
int low; // The low month
// Create a RainFall object initialized with the figures
// stored in the thisYear array.
Rainfall r = new Rainfall(thisYear);
// Display the statistics.
System.out.println("The total rainfall for this year is "
+ r.getTotalRainFall());
System.out.println("The average rainfall for this year is "
+ r.getAverageRainFall());
high = r.getHighestMonth();
System.out.println("The month with the highest amount of rain " + "is "
+ (high + 1) + " with " + r.getRainAt(high) + " inches.");
low = r.getLowestMonth();
System.out.println("The month with the lowest amount of rain " + "is "
+ (low + 1) + " with " + r.getRainAt(low) + " inches.");
}
}
hope this helps
I'm not sure if this was just a copying error, but in the second block you've called the class Rain, but then you declared r as Rainfall.
Not sure why you are creating a getRainAt class just to initialise it, try using the Rain class constructor to do this.
Replace this:
public class getRainAt {
public getRainAt() {
getRainAt = new double[12];
}
}
With:
public Rain() {
getRainAt = new double[12];
}
and since you are using Rain instead of Rainfall now, in the main method it should be:
Rain r = new Rain();