Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-17-2007, 02:32 PM
Member
 
Join Date: Apr 2007
Location: Sweden
Posts: 12
Legoland is on a distinguished road
Calculate average age for women and men?
Hi!
I have just started with Java and found this forum before I have been doing a lot of reading here but now I need some help since I´m stuck.
I want to make a program that will calculate the averageage for women and and men one group for women and one for men.At the end the program should say buy buy and then show the averageage for women and men.
The program looks like this.
import javax.swing.*;

public class Person {

public static void main(String [] arg) {

String kvinna;

String man;

String txt= "";

int start= JOptionPane.showConfirmDialog(null,"Välkommen!"+

"\nVill du räkna medelåldern?", "Fråga", JOptionPane.YES_NO_OPTION);

if (start == 0){

for (int i=1 ; i>= 0; i++) {

for(int j=1 ;j <= i; j++){

int knapp= JOptionPane.showConfirmDialog(null,"En kvinna?");

if(knapp == 0) {

kvinna= JOptionPane.showInputDialog("Hur gammal är kvinnan?");

if (false)

break;

else {

int k1= Integer.parseInt(kvinna);

int medel1= k1 / j;

String txt1= txt + medel1;
}
}

else if(knapp == 1) {

man= JOptionPane.showInputDialog("Hur gammal är mannen?");

if (false)

break;

else {

int m1= Integer.parseInt(man);

int medel2= m1 / j;

String txt2= txt +medel2;

}
}

else

break;

} // for1 slut

} // for2 slsut

} // if1 slut

else




JOptionPane.showMessageDialog(null, "Hej då!"); (Hej då is Buy Buy in swedish)

System.exit(0);


//JOptionPane.showMessageDialog(null,"Medelåldern för kvinnor är: " + txt1 + "\nMedelåldern för män är: " + txt2);( this is the calculation for women and men)

//System.exit(0);
} //main slut
} //class slut

Thansk for input and help in advance.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-18-2007, 07:22 AM
Senior Member
 
Join Date: Mar 2007
Posts: 136
goldhouse is on a distinguished road
For me it was difficult to understand spanish , Look at the code let me know the status

Code:
package com.test.workarea; import javax.swing.JOptionPane; public class Person { public static void main(String [] arg) { String kvinna; String man; String txt= ""; int i=0,j=0; int sumk1=0,summ1 =0; int start= JOptionPane.showConfirmDialog(null,"Välkommen!"+ "\nVill du räkna medelåldern?", "Fråga", JOptionPane.YES_NO_OPTION); while(start == 0){ int knapp= JOptionPane.showConfirmDialog(null,"En kvinna?"); if(knapp == 0) { kvinna= JOptionPane.showInputDialog("Hur gammal är kvinnan?");// Assumes this asks men if(kvinna != null ){ int k1= Integer.parseInt(kvinna); sumk1 = sumk1 + k1; i = i +1; } } else if(knapp == 1) { man= JOptionPane.showInputDialog("Hur gammal är mannen?"); //Assumes this asks women if(man != null){ int m1= Integer.parseInt(man); summ1 = summ1 + m1; j = j +1; } } else break; } // if1 slut JOptionPane.showMessageDialog(null, "Hej då!");// (Hej då is Buy Buy in swedish) JOptionPane.showMessageDialog(null,"Medelåldern för kvinnor är: " + sumk1/i + "\nMedelåldern för män är: " + summ1/j);//( this is the calculation for women and men) System.exit(0); // System.exit(0); } //main slut } //class slut
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-18-2007, 11:21 AM
Member
 
Join Date: Apr 2007
Location: Sweden
Posts: 12
Legoland is on a distinguished road
Thank you goldhouse!
Thanks for your help it works fine now I can continue on my own now.
Thanks again from Legoland
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-18-2007, 11:38 AM
Senior Member
 
Join Date: Mar 2007
Posts: 136
goldhouse is on a distinguished road
you are welcome... dont hesitate to ask more
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate Average sthack99 New To Java 4 06-13-2008 12:09 PM
working out wrong average gemtez New To Java 4 12-12-2007 09:35 AM
Calculate Tax in java toby New To Java 2 07-30-2007 10:03 AM
Calculate what e1 and e2 should be Legoland New To Java 11 07-02-2007 07:01 PM
get the average and maximum score Eric Advanced Java 2 07-01-2007 05:15 AM


All times are GMT +3. The time now is 04:20 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org