Question

Java

4. Write the code of data type class ExerciseMonitor_yourLastName including data members with an double array size 7 to store the distance of 7 days, constructors, and all the following methods Total rainfall for the year The average monthly rainfall The month with the most rain . The month with the less rain The method toString to display the result in the following format: For example if the input from the keyboard for each month as data in the following table: JAN | FEB | MAR? APR? MAY JUN? JUL AUG? SEP OCT| NOVE DEC 3.95 2.53 3.51 8.6916.77 4.05 1.02 0.03 1.039.43 13.57 6.4 The output is: Rainfall in the year: Average monthly rainfall: The month with the most rain The month with the less rain 70.98 5.92 May August

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class ExerciseMonitor_yourLastName {

    public static void main(String[] args) {

        // to store rainfall for 12 months
        double rainfall[] = new double[12];

        String months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
        Scanner in = new Scanner(System.in);

        for(int i=0; i<12; i++) {
            System.out.printf("Enter rainfall for %s: ", months[i]);
            rainfall[i] = in.nextDouble();
        }

        double totalRainFall = 0;
        int maxRainFallMonth = 0;
        int minRainFallMonth = 0;

        for(int i=0; i<12; i++) {
            totalRainFall += rainfall[i];

            if(rainfall[i] > rainfall[maxRainFallMonth]) {
                maxRainFallMonth = i;
            }
            if(rainfall[i] < rainfall[minRainFallMonth]) {
                minRainFallMonth = i;
            }
        }

        System.out.printf("Rainfall in the year: %.2f\n", totalRainFall);
        System.out.printf("Average Monthly rainfall: %.2f\n", totalRainFall/12);
        System.out.printf("The month with the most rain : %s\n", months[maxRainFallMonth]);
        System.out.printf("The month with the least rain : %s\n", months[minRainFallMonth]);


        in.close();
    }

}
Add a comment
Know the answer?
Add Answer to:
Java 4. Write the code of data type class ExerciseMonitor_yourLastName including data members with an double...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java language: Write a rainfall class that stores the total rainfall for each of 12...

    In Java language: Write a rainfall class that stores the total rainfall for each of 12 months of years 2015 -2017 into an 2D array of doubles. Use the text file at Actividades/Tareas link as input of rainfall data. The program should read the input data from a text file. The program should have methods that at least return the following: • Total rainfall for the years 2015 – 2017 - return a 1D array • The average monthly rainfall...

  • Consider the following data: Monthly Profit of a Gym Month Jan-12 Feb-12 Mar-12 Apr-12 May-12 ...

    Consider the following data: Monthly Profit of a Gym Month Jan-12 Feb-12 Mar-12 Apr-12 May-12 Jun-12 Jul-12 Aug-12 Sep-12 Profit ($) 5,550 5,303 4,944 4,597 5,140 5,518 6,219 6,143 5,880 Step 2 of 5 : What are the MAD, MSE and MAPE scores for the three-period moving average? Round any intermediate calculations, if necessary, to no less than six decimal places, and round your final answer to one decimal place.

  • Consider the following data: Monthly Profit of a Gym Month Jan-12 Feb-12 Mar-12 Apr-12 May-12 Jun-12...

    Consider the following data: Monthly Profit of a Gym Month Jan-12 Feb-12 Mar-12 Apr-12 May-12 Jun-12 Jul-12 Aug-12 Sep-12 Profit ($) 5,350 5,103 4,824 4,437 5,080 5,358 5,819 6,091 5,837 Step 4 of 5: What are the MAD, MSE and MAPE scores for the three-period weighted moving average forecast? Round any intermediate calculations, if necessary, to no less than six decimal places, and round your final answer to one decimal place.

  • Consider the following data: Monthly Profit of a Gym Month Jan-12 Feb-12 Mar-12 Apr-12 May-12 Jun-12...

    Consider the following data: Monthly Profit of a Gym Month Jan-12 Feb-12 Mar-12 Apr-12 May-12 Jun-12 Jul-12 Aug-12 Sep-12 Profit ($) 5,350 5,103 4,824 4,437 5,080 5,358 5,819 6,091 5,837 Step 2 of 5 : What are the MAD, MSE and MAPE scores for the three-period moving average? Round any intermediate calculations, if necessary, to no less than six decimal places, and round your final answer to one decimal place.

  • Consider the following data: Monthly Profit of a Gym Month Jan-12 Feb-12 Mar-12 Apr-12 May-12 Jun-12...

    Consider the following data: Monthly Profit of a Gym Month Jan-12 Feb-12 Mar-12 Apr-12 May-12 Jun-12 Jul-12 Aug-12 Sep-12 Profit ($) 5,500 5,253 4,914 4,557 5,125 5,478 6,119 6,130 5,870 Step 2 of 5 : What are the MAD, MSE and MAPE scores for the three-period moving average? Round any intermediate calculations, if necessary, to no less than six decimal places, and round your final answer to one decimal place.

  • Consider the following data: Monthly Profit of a Gym Month Jan-12 Feb-12 Mar-12 Apr-12 May-12 Jun-12...

    Consider the following data: Monthly Profit of a Gym Month Jan-12 Feb-12 Mar-12 Apr-12 May-12 Jun-12 Jul-12 Aug-12 Sep-12 Profit ($) 5,350 5,103 4,824 4,437 5,080 5,358 5,819 6,091 5,837 Step 3 of 5: Determine the three-period weighted moving average for the next time period with weights of 3 (most recent), 2 (second recent), and 1 (oldest time period). If necessary, round your answer to one decimal pl

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT