In: Computer Science
20.1: Checking on the Drought
[(JAVA, ECLIPSE), Please keep the program as short as possible]
2.99
3.31
2.05
1.06
0.39
0.08
0.08
0.08
0.24
0.79
1.89
2.13
2.89
5.61
3.20
0.00
0.00
0.00
0.00
0.00
0.00
0.00
1.92
1.53
input.close();
input = new Scanner(averageFile);
Rainfall in San Jose: A Comparison
Average
2018-9 Deficit
2.99 2.89
0.10
3.31 5.61
-2.30
2.05 3.2
-1.15
1.06 0.0
1.06
0.39 0.0
0.39
0.08 0.0
0.08
0.08 0.0
0.08
0.08 0.0
0.08
0.24 0.0
0.24
0.79 0.0
0.79
1.89 1.92
-0.03
2.13 1.53
0.60
Total deficit: -0.06
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// average_rain.txt
2.99
3.31
2.05
1.06
0.39
0.08
0.08
0.08
0.24
0.79
1.89
2.13
_________________
// rain2018_19.txt
2.89
5.61
3.20
0.00
0.00
0.00
0.00
0.00
0.00
0.00
1.92
1.53
__________________
// Rainfall.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Rainfall {
public static void main(String[] args) {
//Declaring one Dimensional
Array
double averageRain[]=new
double[12];
double rain2018_19[]=new
double[12];
//Declaring variables
double totalDeficit=0,def=0;
Scanner sc=null;
try {
//Opening the file and read the data and populate the
values into an array
sc=new
Scanner(new File("average_rain.txt"));
for(int
i=0;i<averageRain.length;i++)
{
averageRain[i]=sc.nextDouble();
}
sc.close();
sc=new
Scanner(new File("rain2018_19.txt"));
for(int
i=0;i<rain2018_19.length;i++)
{
rain2018_19[i]=sc.nextDouble();
}
sc.close();
} catch (FileNotFoundException e)
{
e.printStackTrace();
}
//Displaying the Results
System.out.println("Average\t2018-9\t\tDeficit");
for(int i=0;i<averageRain.length;i++)
{
def=averageRain[i]-rain2018_19[i];
System.out.printf("%.2f\t\t%.2f\t\t%.2f\n",averageRain[i],rain2018_19[i],def);
totalDeficit+=def;
}
//Displaying the output
System.out.printf("Total deficit:%.2f",totalDeficit);
}
}
______________________
Output:
Average 2018-9
Deficit
2.99 2.89
0.10
3.31 5.61
-2.30
2.05 3.20
-1.15
1.06 0.00
1.06
0.39 0.00
0.39
0.08 0.00
0.08
0.08 0.00
0.08
0.08 0.00
0.08
0.24 0.00
0.24
0.79 0.00
0.79
1.89 1.92
-0.03
2.13 1.53
0.60
Total deficit:-0.06
_______________Could you plz rate me well.Thank
You