Question
Write a program RunningReport.Java that reports the statics of the running record. 1) Ask user to enter miles ran within the week. (Day 1, Monday, through day 7, Sunday). Runner could skip days . Save the information in an array. 2) Calculate the total and the average for the week (exclude non-running days) 3) Print out number of days ran, average, total, number of days ran below average(including non-running days), day of the week with longest run.
Explanation / Answer
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class RunningReport { public static void main(String[] args) throws IOException { double[] ran = new double[7]; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter miles ran within the week."); for (int i = 0; i < 7; i++) { ran[i] = Double.parseDouble(br.readLine()); } double total = 0, avg = 0, longDist = 0; int noRunDays = 0, ranBelowAvg = 0, longRun = 0; for (int i = 0; i < 7; i++) { total = total + ran[i]; if (ran[i] == 0) { noRunDays++; } } avg = total / (7 - noRunDays); longDist = ran[0]; longRun = 1; for (int i = 0; i < 7; i++) { if (ran[i] > longDist) { longDist = ran[i]; longRun = i + 1; } if (ran[i]