Welcome to Dream.In.Code
Become a Java Expert!

Join 150,178 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,150 people online right now. Registration is fast and FREE... Join Now!




program writting help

 
Reply to this topicStart new topic

program writting help, programing

ziburgos27
23 Aug, 2008 - 12:09 PM
Post #1

New D.I.C Head
*

Joined: 23 Aug, 2008
Posts: 5

How would I answer this question?

Input a list of people's ages form the user ( terminated by 0) and find the avarage?

This post has been edited by ziburgos27: 23 Aug, 2008 - 12:10 PM
User is offlineProfile CardPM
+Quote Post

nick2price
RE: Program Writting Help
23 Aug, 2008 - 12:14 PM
Post #2

D.I.C Regular
***

Joined: 23 Nov, 2007
Posts: 338



Thanked: 12 times
My Contributions
use a scanner or InputDialog to input the users ages through a loop and set the input variable to terminate if input == 0.
User is offlineProfile CardPM
+Quote Post

ziburgos27
RE: Program Writting Help
23 Aug, 2008 - 12:18 PM
Post #3

New D.I.C Head
*

Joined: 23 Aug, 2008
Posts: 5

QUOTE(ziburgos27 @ 23 Aug, 2008 - 01:09 PM) *

How would I answer this question?

Input a list of people's ages form the user ( terminated by 0) and find the avarage?



How would I write the code?
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Program Writting Help
23 Aug, 2008 - 12:20 PM
Post #4

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Average is a sum of the values divided by the number of values. As for an example of how you can do this, you need to provide your code you have so far and then we can assist you. We DO NOT do people's homework for them. You have to show an effort first. smile.gif
User is offlineProfile CardPM
+Quote Post

ziburgos27
RE: Program Writting Help
23 Aug, 2008 - 12:41 PM
Post #5

New D.I.C Head
*

Joined: 23 Aug, 2008
Posts: 5







QUOTE(ziburgos27 @ 23 Aug, 2008 - 01:18 PM) *

QUOTE(ziburgos27 @ 23 Aug, 2008 - 01:09 PM) *

How would I answer this question?

Input a list of people's ages form the user ( terminated by 0) and find the avarage?



How would I write the code?





this is what I came up with:

Input Number
While Number > o
Write Number
Input Number
End with average of number
write "Done"

QUOTE(Martyr2 @ 23 Aug, 2008 - 01:20 PM) *

Average is a sum of the values divided by the number of values. As for an example of how you can do this, you need to provide your code you have so far and then we can assist you. We DO NOT do people's homework for them. You have to show an effort first. smile.gif



this is what I came up with:

Input Number
While Number > o
Write Number
Input Number
End with average of number
write "Done"
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Program Writting Help
23 Aug, 2008 - 12:44 PM
Post #6

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Close...

Input number
while number > 0
write number
add number to sum
add 1 to counter
input next number
end while

average = sum / counter
Write Done

smile.gif

User is offlineProfile CardPM
+Quote Post

ziburgos27
RE: Program Writting Help
23 Aug, 2008 - 12:54 PM
Post #7

New D.I.C Head
*

Joined: 23 Aug, 2008
Posts: 5


Marty Thank you very much



QUOTE(Martyr2 @ 23 Aug, 2008 - 01:44 PM) *

Close...

Input number
while number > 0
write number
add number to sum
add 1 to counter
input next number
end while

average = sum / counter
Write Done

smile.gif


User is offlineProfile CardPM
+Quote Post

nick2price
RE: Program Writting Help
23 Aug, 2008 - 12:55 PM
Post #8

D.I.C Regular
***

Joined: 23 Nov, 2007
Posts: 338



Thanked: 12 times
My Contributions
I will show you a simple program of what u want to do. This way uses an InputDialog though and is closed through a yes/no dialog. You should hopefully see how things work though and easily tweak it to fix your needs.
CODE
import javax.swing.*;

public class Unit6Dem2
{
   public static void main(String[] args)
   {
       //declare variables
       String input;
       double mark, average, sum;
       int count, answer;

       sum = 0;
       count = 0;

       //ask user to enter an percentage mark atleast once.
       do
       {
          input = JOptionPane.showInputDialog("Please enter a percentage mark");
          mark = Double.parseDouble(input);  //stored as a double to get a more precise answer

             //store the value of the current sum to the user's last input.
          sum = sum + mark;

        //ask user if they want to enter another integer
          answer = JOptionPane.showConfirmDialog(null, "Input another percentage mark?",
                  "???", JOptionPane.YES_NO_OPTION);//stating my dialog box
       count++;

        //get the average of the sum by dividing it by how many integers the user inputted
       average = sum / count;

       }while (answer == JOptionPane.YES_OPTION);

        //show user how many marks they've entered and what the average of the numbers they put in.
       JOptionPane.showMessageDialog(null, "You have entered " + count + " percentage marks\nThe average is " + average);

       System.exit(0);

   }
}

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:43AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month