Below was the java code that i was hald done on it. in the java code, it supposed to count on min and max rainfall. the min and max rainfall should update on every rainfall entry.
Below was the java code that i was hald done on it.
in the java code, it supposed to count on min and max rainfall.
the min and max rainfall should update on every rainfall entry.
Don’t mind help me find out the mistake and amend on it.
import java.util.Scanner;
public class draft {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner kb = new Scanner(System.in);
int totalCount = 0;
double totalRainFall = 0;
double minRainFall = 0;
double maxRainFall = 0;
double aveRainFall = 0;
System.out.println("Rainfall Level Counter");
System.out.println();
System.out.print("Enter Rainfall Level: ");
double rainFall = kb.nextDouble();
while(rainFall > 0) {
totalCount++;
totalRainFall += rainFall;
if (rainFall > minRainFall) {
minRainFall = rainFall;
if (rainFall < maxRainFall) {
maxRainFall = rainFall;
}
}
System.out.print("Min: " + minRainFall +" ");
System.out.print("Max: " + maxRainFall +" ");
aveRainFall = totalRainFall/totalCount;
System.out.print("Ave: " + aveRainFall +" ");
System.out.println();
System.out.println();
System.out.print("Enter Rainfall Level: ");
rainFall = kb.nextDouble();
kb.nextLine();
}
if(rainFall <= 0) {
System.out.println("Rainfall Entries Made: " + totalCount);
}
}
}
The program should run as show below :
Enter rainfall : 3.2 Min : 3.2 Max : 3.2 Ave : 3.2
Enter rainfall : 3.8 Min : 3.2 Max : 3.8 Ave : 3.5
Enter rainfall : 2 Min : 2.0 Max : 3.8 Ave : 3.0
Enter : -1 Rainfall entries made : 3
|
But now the output was show as below :
Enter rainfall : 3.2 Min : 3.2 Max : 0 Ave : 3.2
Enter rainfall : 3.8 Min : 3.8 Max : 0 Ave : 3.5
Enter rainfall : 2 Min : 3.8 Max : 0 Ave : 3.0
Enter : -1 Rainfall entries made : 3
|
Step by step
Solved in 3 steps with 3 images