1. Other
  2. Other
  3. below was the java code that supposed to count on...

Question: below was the java code that supposed to count on...

Question details

Below was the java code that supposed to count on min and max rainfall.
it should update on every rainfall entry.

Don’t mind help me find out the mistake.

 

 

 

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

 

 

Need help on solving my mistake.
Dont make any big change on my java code.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution