Solved

Average Rain Fall

Posted on 2009-07-01
14
1,087 Views
Last Modified: 2013-12-14
im trying to write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. Basically the program should ask for the number of years. The Outer Loop will iterate once for each year. The Inner Loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program shold display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period.

Im having a hard time starting the code and that is why i have not posted anything.
0
Comment
Question by:AgentC4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 2
14 Comments
 
LVL 20

Expert Comment

by:a_b
ID: 24760406
To help you get started, nested loops -

for(int i=0;i<noOfYrs;i++)
{
     for(int j=0;,j<12;j++)
     {
           // Do all the processing here
     }
}
0
 

Author Comment

by:AgentC4
ID: 24760449
Thanks this helped a bit. Are you able to post the full code so I can compare to what have. I have a feeling I'm way off. My teacher doesn't do a well job at explaining much.
0
 
LVL 20

Expert Comment

by:a_b
ID: 24760532
@AgentC4: Why don't you post your code so that we can have a look at what is wrong, instead of you copying the stuff off the website?
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

Author Comment

by:AgentC4
ID: 24762316
Ok ill post my code as soon as I'm finished with my exam. And no one said I'm just copingy and calling it a day. I've been doing over twenty problems because I've been on medical leave and my teachers notes online are probably better starting a fire rather than teach.
0
 

Author Comment

by:AgentC4
ID: 24762879
Oh no please don't think I'm accusing you or anyone I just don't want you guys to think I'm coming here for an easy outcome. I do need this stuff explained because my teacher isn't doing a great job at it. Ill post what I have soon after I leave the doctors office. And thanks in advance.
0
 
LVL 7

Accepted Solution

by:
humanonomics earned 500 total points
ID: 24765364
OOps soory, I thought he is the same other guy, who had posted incomplete code in another question, their problem questions are pretty much same @ Venabili

http://www.experts-exchange.com/Programming/Languages/Java/J2EE/JavaMail/Q_24538353.html
0
 

Author Comment

by:AgentC4
ID: 24765592
This is what i have so far, i cant figure out which LOOP choice to go with.
public class AverageRainFall
{
    public static void main(String [] args)
    {
        double years;
        double months=12;
        double total=0;
        double average;
        double months[];
        double grandTotal=0;
        months = new double[12];
        String input;
 
        Scanner keyboard = new Scanner(System.in);
 
        DecimalFormat dollar = new DecimalFormat("##0.00");
 
        input = JOptionPane.showInputDialog("Please enter number of years? "); 
		
        years = Integer.parseInt(input);

Open in new window

0
 

Author Comment

by:AgentC4
ID: 24765612
sorry please use this for the decimal
DecimalFormat Rain = new DecimalFormat("##0.00");

Open in new window

0
 

Author Comment

by:AgentC4
ID: 24765940
My teacher didnt do  a well job at explaining the differences between WHILE, DO-WHILE, and FOR  nad how they work and thats where im pretty much stuck
0
 
LVL 7

Expert Comment

by:humanonomics
ID: 24769458
OOps soory, I thought he is the same other guy, who had posted incomplete code in another question, their problem questions are pretty much same @ Venabili

http://www.experts-exchange.com/Programming/Languages/Java/J2EE/JavaMail/Q_24538353.html
0
 
LVL 7

Expert Comment

by:humanonomics
ID: 24769723
Go step by step, first loop over the years initially and then loop over the months
0
 

Author Comment

by:AgentC4
ID: 24769936

public class AverageRainFall
{
    public static void main(String [] args)
    {
        double years;
        double months=12;
        double total=0;
        double average;
        double months[];
        double grandTotal=0;
        months = new double[12];
        String input;
 
        Scanner keyboard = new Scanner(System.in);
 
        DecimalFormat dollar = new DecimalFormat("##0.00");
 
        input = JOptionPane.showInputDialog("Please enter number of years? "); 
                
        years = Integer.parseInt(input);
 
        for(int y = 1; y <= years; y++) 
        {
           System.out.println("Please enter rainfall using inches for         year #: " + y +);
         
        }

Open in new window

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java string replace 11 74
How to convert from xls to xlsx using java 7 144
jsp error 6 67
transfer content to new site design 7 44
This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question