Results 1 to 4 of 4
  1. #1
    Legoland is offline Member
    Join Date
    Apr 2007
    Location
    Sweden
    Posts
    12
    Rep Power
    0

    Default 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.

  2. #2
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default

    For me it was difficult to understand spanish , Look at the code let me know the status

    Java 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&#228;lkommen!"+
    
    				"\nVill du r&#228;kna medel&#229;ldern?", "Fr&#229;ga", JOptionPane.YES_NO_OPTION);
    
    		while(start == 0){
    
    
    					int knapp= JOptionPane.showConfirmDialog(null,"En kvinna?");
    
    					if(knapp == 0) {
    
    						kvinna= JOptionPane.showInputDialog("Hur gammal &#228;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 &#228;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&#229;!");// (Hej d&#229; is Buy Buy in swedish)
    
    		
    
    		JOptionPane.showMessageDialog(null,"Medel&#229;ldern f&#246;r kvinnor &#228;r: " + sumk1/i + "\nMedel&#229;ldern f&#246;r m&#228;n &#228;r: " + summ1/j);//( this is the calculation for women and men)
    		System.exit(0);
    
    
    //		System.exit(0);
    	} //main slut
    } //class slut

  3. #3
    Legoland is offline Member
    Join Date
    Apr 2007
    Location
    Sweden
    Posts
    12
    Rep Power
    0

    Default Thank you goldhouse!

    Thanks for your help it works fine now I can continue on my own now.
    Thanks again from Legoland

  4. #4
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

Similar Threads

  1. Calculate Average
    By sthack99 in forum New To Java
    Replies: 4
    Last Post: 06-13-2008, 11:09 AM
  2. working out wrong average
    By gemtez in forum New To Java
    Replies: 4
    Last Post: 12-12-2007, 08:35 AM
  3. Calculate Tax in java
    By toby in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 09:03 AM
  4. Calculate what e1 and e2 should be
    By Legoland in forum New To Java
    Replies: 11
    Last Post: 07-02-2007, 06:01 PM
  5. get the average and maximum score
    By Eric in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 04:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •