1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ruslelena [56]
3 years ago
10

Write a RainFall class that stores the total rainfall for each of 12 months into an array of doubles. The program should have me

thods that return the following:
the total rainfall for the year
the average monthly rainfall
the month with the most rain
the month with the least rain
Demonstrate the class in a complete program.
Input Validation: Do not accept negative numbers for monthly rainfall figures.
import java.io.*;
import java.util.*;
public class Rainfall
{
Scanner in = new Scanner(System.in);
private int month = 12;
private double total = 0;
private double average;
private double standard_deviation;
private double largest;
private double smallest;
private double months[];
public Rainfall()
{
months = new double[12];
}
public void setMonths()
{
for(int n=1; n <= month; n++)
{
System.out.println("Enter the rainfall (in inches) for month #" + n + ":" );
months[n-1] = in.nextInt();
}
}
public double getTotal()
{
total = 0;
for(int i = 0; i < 12; i++)
{
total = total + months[i];
}
System.out.println("The total rainfall for the year is" + total);
return total;
}
public double getAverage()
{
average = total/12;
System.out.println("The average monthly rainfall is" + average);
return average;
}
public double getLargest()
{
double largest = 0;
int largeind = 0;
for(int i = 0; i < 12; i++)
{
if (months[i] > largest)
{
largest = months[i];
largeind = i;
}
}
System.out.println("The largest amout of rainfall was" + largest +
"inches in month" + (largeind + 1));
return largest;
}
public double getSmallest()
{
double smallest = Double.MAX_VALUE;
int smallind = 0;
for(int n = 0; n < month; n++)
{
if (months[n] < smallest)
{
smallest = months[n];
smallind = n;
}
}
System.out.println("The smallest amout of rainfall was" + smallest +
"inches in month " + (smallind + 1));
return smallest;
}
public static void main(String[] args)
{
Rainfall r = new Rainfall();
r.setMonths();
System.out.println("Total" + r.getTotal());
System.out.println("Smallest" + r.getSmallest());
System.out.println("Largest" + r.getLargest());
System.out.println("Average" + r.getAverage());
}
}
Computers and Technology
1 answer:
RSB [31]3 years ago
8 0

Answer:

Explanation:

The code provided worked for the most part, it had some gramatical errors in when printing out the information as well as repeated values. I fixed and reorganized the printed information so that it is well formatted. The only thing that was missing from the code was the input validation to make sure that no negative values were passed. I added this within the getMonths() method so that it repeats the question until the user inputs a valid value. The program was tested and the output can be seen in the attached image below.

import java.io.*;

import java.util.*;

class Rainfall

{

   Scanner in = new Scanner(System.in);

   private int month = 12;

   private double total = 0;

   private double average;

   private double standard_deviation;

   private double largest;

   private double smallest;

   private double months[];

   public Rainfall()

   {

       months = new double[12];

   }

   public void setMonths()

   {

       for(int n=1; n <= month; n++)

       {

           int answer = 0;

           while (true) {

               System.out.println("Enter the rainfall (in inches) for month #" + n + ":" );

               answer = in.nextInt();

               if (answer > 0) {

                   months[n-1] = answer;

                   break;

               }

           }

       }

   }

   public void getTotal()

   {

       total = 0;

       for(int i = 0; i < 12; i++)

       {

           total = total + months[i];

       }

       System.out.println("The total rainfall for the year is " + total);

   }

   public void getAverage()

   {

       average = total/12;

       System.out.println("The average monthly rainfall is " + average);

   }

   public void getLargest()

   {

       double largest = 0;

       int largeind = 0;

       for(int i = 0; i < 12; i++)

       {

           if (months[i] > largest)

           {

               largest = months[i];

               largeind = i;

           }

       }

       System.out.println("The largest amount of rainfall was " + largest +

               " inches in month " + (largeind + 1));

   }

   public void getSmallest()

   {

       double smallest = Double.MAX_VALUE;

       int smallind = 0;

       for(int n = 0; n < month; n++)

       {

           if (months[n] < smallest)

           {

               smallest = months[n];

               smallind = n;

           }

       }

       System.out.println("The smallest amount of rainfall was " + smallest +

               " inches in month " + (smallind + 1));

   }

   public static void main(String[] args)

   {

       Rainfall r = new Rainfall();

       r.setMonths();

       r.getTotal();

       r.getSmallest();

       r.getLargest();

       r.getAverage();

   }

}

You might be interested in
A user calls the help desk to report that a mobile device exhibits very slow performance. What could cause this problem
kipiarov [429]

The performance of a mobile device is relative rather than absolute, since it depends on the utility the user requires of it.

It could be that the space remaining on the storage is low or the ram is too small.

Often times, users tend to load their devices with tonnes of applications not considering the RAM size, available memory of the device, these applications may be space demanding and expensive, and in the long run lead to the low performance of the device.

Learn more about Mobile device specification here:

brainly.com/question/25363479

3 0
2 years ago
Which company is credited with solving a problem by creating a program that could work on all computers?
Ksivusya [100]
It’s Microsoft because it deals with all tech stuff and helps other people out
5 0
4 years ago
Edhesive lesson practice 8.3, question 5
scZoUnD [109]

Answer:

3

Explanation:

8 0
3 years ago
Write the code to declare a variable to hold the value of the grade you hope to get in this class. What stdio.h input function w
GREYUIT [131]

Answer:

// code to read grade

#include <stdio.h>

// main function

int main(void) {

   // if grade is character

char grade;

// if grade is numeric then we can use int or double

// int grade;

// double grade;

printf("Enter your grade:");

// read grade from user

scanf("%c",&grade);

// print grade

printf("your grade is:%c",grade);

return 0;

}

Explanation:

To read a value, scanf() function is used from stdio.h.Read a grade from user and assign it to variable "grade".

Output:

Enter your grade:A

your grade is:A

// code to read die volt

#include <stdio.h>

// main function

int main(void) {

// variable

double die_volt;

printf("Enter die volt:");

// read die volt from user

scanf("%lf",&die_volt);

// print die volt

printf("Entered die volt is:%0.2lf",die_volt);

return 0;

}

Explanation:

Read the die volt from user and assign it to variable "die_volt" with the help

of scanf() function.

Output:

Enter die volt:220                                                                                                        

Entered die volt is:220.00

4 0
3 years ago
Help ASAP please ?
mylen [45]
Okay, so since I don't completely understand your question, I'll just try my best to explain each of them.

1. Someone can find your location based on a photo that you posted; If you tagged the location, obviously they can find the location. If you put in the caption where you were when you took the photo, again yes, they would be able to find the location. If you were in a well known location when you took the picture and you can clearly see the background or the setting, with context clues you can figure it out, but as far as the social media platform telling the public where the picture was taken or posted, it is not authorized to give out the location.

2. Colleges use social media during the admission process; Some colleges do check the social media, not all but some. Mostly the platforms where you are most careless, so watch out. You can decide if you want your account to be public or private in the account settings.

3. items posted online can be removed at anytime; yes it can be removed, but depending on how popular the post was, people will still remember it.

4. Things you post online become public information; yes and no. On any and all social media platforms, there is a setting where you can choose the audiences the post reaches. There is the public setting where it's completely public and out into the world, there is the privacy setting where you are the only one who can view it, there is the friends setting where your friends can view your posts, and on some there are the friends/followers except... where you can choose specific people that can't view your post/s, and finally there is the specific friends that can view the post. You can also decide if you want your account in general to be public or private, which you can go into the settings and decide.

5. Employers screen job candidates based on social medias; like number 2 up there, some employers do check your social medias, but if you have you account settings as private they will have to request access.

I hope I helped at least a little! If I didn't i'm sorry i didn't completely understand the question so I tried my best.
If I did help, I'd appreciate it if you would give me brainliest! Thank you!
5 0
3 years ago
Read 2 more answers
Other questions:
  • Why is it important to save a print copy of electronic sources?
    6·1 answer
  • Which type of color mixing do painters with a real brush and paints use?
    5·1 answer
  • The sound cards is a digital to____________ converter.
    11·1 answer
  • Angela's ready to get started with her first Smart Display campaign, but her account isn't yet eligible due to not having enough
    11·1 answer
  • Which of the following statements about creating arrays and initializing their elements is false?
    6·1 answer
  • What does the image depict:
    14·1 answer
  • Why is it important to install updates? Why should you use the Power button on the Start menu instead of the Power button on you
    7·1 answer
  • Write method reverseString, which takes a string str and returns a new string with the characters in str in reverse order. For e
    8·1 answer
  • Como se juega robótica de cokitos
    13·1 answer
  • Where can you get information on receiving financial help?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!