Results 1 to 8 of 8
  1. #1
    zifkele is offline Member
    Join Date
    May 2012
    Posts
    3
    Rep Power
    0

    Default need help with java program

    hey guys, need help, i need thread to count BMI it's kmi in my code
    Java Code:
     
    package kmiSkaiciuoklis;
    
     /**
     *
     * @author zizi9880
     */
     public class Kmi {
    
     public static void main(String args[]) {
     Thread t1 = new Thread(new Gija("Pirmas"));
     Thread t2 = new Thread(new Gija("Antras"));
     Thread t3 = new Thread(new Gija("Trečias"));
    
     t1.start();
     t2.start();
     t3.start();
    
     Langas langas = new Langas();
     }
     }
    
    package kmiSkaiciuoklis;
    
     import java.awt.FlowLayout;
     import java.awt.event.ActionEvent;
     import java.awt.event.ActionListener;
     import javax.swing.*;
    
     interface Interfeisas {
    
     public JLabel item1 = new JLabel("Masė: ");
     public JLabel item2 = new JLabel("Ūgis: ");
     public JTextField mase = new JTextField(10);
     public JTextField ugis = new JTextField(10);
     public JButton mygtukas = new JButton("Skaičiuoti");
     }
    
     public class Langas extends JFrame implements Interfeisas {
    
     public float indeksas;
     public String patarimas;
    
     public Langas() {
     super("KMI skaičiuoklė");
    
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     setSize(205, 180);
     setVisible(true);
    
     setLayout(new FlowLayout());
    
     item1.setToolTipText("Įveskite žmogaus masę kilogramais");
     add(item1);
    
     mase.setToolTipText("Iveskite žmogaus masę kilogramais");
     add(mase);
    
     item2.setToolTipText("Įveskite žmogaus ūgį centimetrais");
     add(item2);
    
     ugis.setToolTipText("Įveskite žmogaus ūgį centimetrais");
     add(ugis);
    
     add(mygtukas);
    
     HandlerClass handler = new HandlerClass();
     mygtukas.addActionListener( handler );
    
    
     }
    
     private class HandlerClass implements ActionListener {
    
     @Override
     public void actionPerformed(ActionEvent event) {
     if (event.getSource() == mygtukas) {
     //try {
     float u = Float.parseFloat(ugis.getText()), m = Float.parseFloat(mase.getText());
     indeksas = (float) Math.round(m / (u * u / 10000) * 1000) / 1000;
     if (indeksas >= 0 && indeksas <= 18); //System.out.println("tavo kmi per mažas");
     else if (indeksas > 18 && indeksas< 25); //System.out.println("tavo kmi normalus");
     else if (indeksas >= 25) //System.out.println("tavo kmi per didelis");
     JOptionPane.showMessageDialog(null, "Kūno masės indeksas yra " + indeksas + " " + patarimas, 
     "Apskaičiuotas KMI", JOptionPane.INFORMATION_MESSAGE);
    
     }
    
     }
     }
     }
    
     package kmiSkaiciuoklis;
     import java.util.*;
    
     /**
     *
     * @author home
     */
     public class Gija implements Runnable {
    
     String vardas;
     int sk;
     Failas f = new Failas();
     private int i;
     public ArrayList kmi;
     public Gija(String x) {
     vardas = x;
    
     }
    
     @Override
     public void run() {
     try {
     f.AtidarytiFaila();
     f.SkaitytiFaila();
     for (int i = 0; && i<f.al1.size(); i++){
     kmi.add(Math.round(f.al1.get(i) / ( f.al2.get(i) * f.al2.get(i)/ 10000) * 1000) / 1000);
     } 
     f.UzdarytiFaila();
     System.out.println(kmi);
     //System.out.printf("%s kmi yra %d\n", vardas, kmi);
     Thread.sleep(kmi);
     System.out.printf("%s suskaiĨiuota \n", vardas);
     } catch (Exception e) {
     }
    
     }
     }
    
    
     package kmiSkaiciuoklis;
    
     /**
     *
     * @author home
     */
     import java.io.*;
     import java.util.*;
    
     public class Failas {
    
    
     private Scanner x;
     public ArrayList al1; 
     public ArrayList al2; 
     //-----------atidaro fail skaitymui--------- 
     public void AtidarytiFaila(){
     try
     {
     x = new Scanner(new File("C:\\Users\\home\\Desktop\\kmi\\src\\kmiSkaiciuoklis\\duomenys.txt")); 
     }
    
     catch (Exception e)
     {
     System.out.println ("neÄÆmanoma atidaryti failo");
    
     }}
     //--------skaito faila-----------
     public void SkaitytiFaila(){
     al1 = new ArrayList();
     al2 = new ArrayList();
     while (x.hasNext()){
     al1.add(x.next());
     al2.add(x.next()); 
     }
     System.out.println(al1);
     System.out.println(al2);
     }
     //-----------uzdaro faila----------
     public void UzdarytiFaila(){
     x.close();
     }
     }
    duomenys.txt
    64 198
    50 200
    45 169
    90 170
    28 100
    50 175
    75 165
    51 166
    56 165
    63 160
    99 190
    80 160
    96 155
    34 112
    Last edited by quad64bit; 05-21-2012 at 04:02 PM. Reason: Added code tags

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: need help with java program

    And?
    I assume you have a question.

    And please use [code] tags [/code] when posting code.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,298
    Rep Power
    20

    Default Re: need help with java program

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    zifkele is offline Member
    Join Date
    May 2012
    Posts
    3
    Rep Power
    0

    Default Re: need help with java program

    Quote Originally Posted by Tolls View Post
    And?
    I assume you have a question.

    And please use [code] tags [/code] when posting code.
    Java Code:
    package kmiSkaiciuoklis;
     import java.util.*;
    
     /**
     *
     * @author home
     */
     public class Gija implements Runnable {
    
     String vardas;
     int sk;
     Failas f = new Failas();
     private int i;
     public ArrayList kmi;
     public Gija(String x) {
     vardas = x;
    
     }
    
     @Override
     public void run() {
     try {
     f.AtidarytiFaila();
     f.SkaitytiFaila();
     for (int i = 0; && i<f.al1.size(); i++){
     kmi.add(Math.round(f.al1.get(i) / ( f.al2.get(i) * f.al2.get(i)/ 10000) * 1000) / 1000);
     } 
     f.UzdarytiFaila();
     System.out.println(kmi);
     //System.out.printf("%s kmi yra %d\n", vardas, kmi);
     Thread.sleep(kmi);
     System.out.printf("%s suskaiĨiuota \n", vardas);
     } catch (Exception e) {
     }
    
     }
     }
    this is my problem,
    Java Code:
    for (int i = 0; && i<f.al1.size(); i++){
     kmi.add(Math.round(f.al1.get(i) / ( f.al2.get(i) * f.al2.get(i)/ 10000) * 1000) / 1000);
    , it doesn't work
    Last edited by quad64bit; 05-21-2012 at 04:02 PM. Reason: Added code tags for readability

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: need help with java program

    I've added code tags to your posts which might encourage someone to take a look, but personally, if you don't take the 5 minutes to read DarrylBurke's links, I don't really want to take the 5 minutes to examine your code.

  6. #6
    zifkele is offline Member
    Join Date
    May 2012
    Posts
    3
    Rep Power
    0

    Default Re: need help with java program

    I just took the wrong tag switches, but I read it and i got it, ok?

  7. #7
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: need help with java program

    What does "it doen't work" mean?
    How is it not working?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: need help with java program

    Alright, fair enough. However, you still have not answered anyone -
    it doesn't work
    is not a question.

    You haven't told us what values you expect, what values you get, and how they are wrong.

Similar Threads

  1. Call one Java Program from another Java Program
    By rajpalparyani in forum New To Java
    Replies: 3
    Last Post: 02-14-2011, 04:13 AM
  2. Replies: 4
    Last Post: 07-30-2010, 12:25 PM
  3. execute java program within java program
    By popey in forum New To Java
    Replies: 2
    Last Post: 10-22-2009, 05:32 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

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