Question: Java file outside of source root, there is the same error in both classes. How do I resolve this, so I will be able to

Java file outside of source root, there is the same error in both classes. How do I resolve this, so I will be able to run the code?

first Class

public class Month {

//data member to store the data

private String monthName;

private int amount;

//String parameter to set monthName field

//int parameter to set amount field

public Month(String monthName, int amount) {

this.monthName = monthName;

this.amount = amount;

}

//method to retrieve monthName and amount field

public String getmonthName() {

return monthName;

}

//method to retrieve the data

public int getamount() {

return amount;

}

}

Second Class

//import scanner function for prompting user

import java.util.Scanner;

//main class

public class RainFallAmounts {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

//an array hold 12 values

Month months[] = new Month[12];

String monthsName[] = {\"January\",\"February\",\"March\",\"April\",\"May\",\"June\",

\"July\",\"August\",\"Septmber\",\"October\",\"November\",\"December\"};

int rainfall;

for (int i = 0; i

//loop prompting user

while(true) {

System.out.print(\"Please enter the rainfall amount for \" +

monthsName[i] + \": \");

rainfall = sc.nextInt();

//invalid if input =>

if (rainfall > 0)

break;

System.out.println(\"Invalid amount. Try again.\");

}

months[i] = new Month(monthsName[i], rainfall);

}

//initialize totalRainfall to zero

int totalRainfall = 0;

// create and initialize min/max rainfall variable to month at index 0

int minRainfall = months[0].getamount();

int maxRainfall = months[0].getamount();

int maxIndex = 0;

int minIndex = 0;

for (int i = 0; i

//calculate total rain fall for 12 months

totalRainfall += months[i].getamount();

//find the month has the most rainfal

if (maxRainfall

maxIndex = i;

maxRainfall = months[i].getamount();

}

//find the month has the least rainfall

if (minRainfall > months[i].getamount()) {

minIndex = i;

minRainfall = months[i].getamount();

}

}

//calculate the average of 12 months

double avgRainfall;

avgRainfall = totalRainfall / 12.0;

//Display the results

System.out.println(\" The total rainfall is \" + totalRainfall + \" inches.\");

System.out.println(\"The average monthly rainfall is \" + avgRainfall + \" inches.\");

System.out.println(\"The month with the most rain was \" + monthsName[maxIndex] + \".\");

System.out.println(\"The month with the least rain was \" + monthsName[minIndex] + \".\");

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!