CARI Infonet

 Forgot password?
 Register

ADVERTISEMENT

12Next
Return to list New
View: 4554|Reply: 23

Minta tlg sape yg pro jaVA...

[Copy link]
Post time 7-7-2011 09:57 PM | Show all posts |Read mode
Assalam... Kwn2.. minta tlg tgk per ag masalah coding aq nie.. Nk kira BMI, pengiraan mcm xbtl ja.. pas2 aq xblh nk papar kesemua input yg aq masukkan 2 semua sekali, cuma blh papar satu kali ja.. minta tlg tgk kn ape kesilapannya... Nie coding yang aq dh wat...



import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public class BMI {


public double B, weight,height;


BMI()
{


weight = 0.00;

height = 0.00;




}


public void kiraBMI(double w,double h,String nama)
{


weight = w;

height = h;






B = weight/(height*height);


DecimalFormat fmt = new DecimalFormat("#.##");



JOptionPane.showMessageDialog(null, " BMI " + nama + " ialah : " + fmt.format(B));





}


public static void main(String[] args)
{



BMI B1 = new BMI();


String bilStr = JOptionPane.showInputDialog(null, "Sila masukkan bilangan pengguna : ");

int bil = Integer.parseInt(bilStr);


for(int a = 1; a<=bil; a++) {


String nama = JOptionPane.showInputDialog(null, " Sila masukkan Nama anda : ");


String weightStr = JOptionPane.showInputDialog(null, "Sila Masukkan Berat anda (KG) : ");

double w1 = Double.parseDouble(weightStr);



String heightStr = JOptionPane.showInputDialog(null, "Sila Masukkan Tinggi anda (CM) : ");

double h1 = Double.parseDouble(heightStr);


B1.kiraBMI(w1,h1,nama);






}






System.exit(0);

}

}
Reply

Use magic Report


ADVERTISEMENT


Post time 7-7-2011 10:47 PM | Show all posts
x boleh ker nko upload code java ke dalam code tag dlm advanced mode atau upload ke mana2 file server?
ni contoh code tag

  1. {
  2. huhu
  3. }
Copy the Code
Reply

Use magic Report

 Author| Post time 7-7-2011 11:31 PM | Show all posts
  1. import javax.swing.JOptionPane;
  2. import java.text.DecimalFormat;

  3. public class BMI {

  4.         public double B, weight,height;

  5.         BMI()        {

  6.         weight = 0.00;
  7.         height = 0.00;
  8.        

  9.         }

  10.         public void kiraBMI(double w,double h,String nama)        {

  11.                         weight = w;
  12.                         height = h;

  13.                
  14.        
  15.                         B = weight/(height*height);

  16.                         DecimalFormat fmt = new DecimalFormat("#.##");
  17.                
  18.                         JOptionPane.showMessageDialog(null, " BMI " + nama + " ialah : " + fmt.format(B));

  19.                        

  20.                         }

  21.         public static void main(String[] args)        {
  22.                        
  23.                         BMI B1 = new BMI();

  24.                         String bilStr = JOptionPane.showInputDialog(null, "Sila masukkan bilangan pengguna : ");
  25.                         int bil = Integer.parseInt(bilStr);

  26.                 for(int a = 1; a<=bil; a++) {

  27.                         String nama = JOptionPane.showInputDialog(null, " Sila masukkan Nama anda : ");

  28.                         String weightStr = JOptionPane.showInputDialog(null, "Sila Masukkan Berat anda (KG) : ");
  29.                         double w1 = Double.parseDouble(weightStr);
  30.                
  31.                         String heightStr = JOptionPane.showInputDialog(null, "Sila Masukkan Tinggi anda (CM) : ");
  32.                         double h1 = Double.parseDouble(heightStr);

  33.                         B1.kiraBMI(w1,h1,nama);

  34.                        
  35.                        
  36.                 }
  37.                
  38.                

  39.         System.exit(0);
  40.         }

  41. }
Copy the Code
Reply

Use magic Report

Post time 8-7-2011 12:58 AM | Show all posts
Papar 2 kali ? Saya tak faham..tp apa saya tgk mmg diolog box tu yang papar data. lau nak papar  jelah 2 kali.
  1. JOptionPane.showMessageDialog(null, " BMI " + nama + " ialah : " + fmt.format(B));
Copy the Code
Reply

Use magic Report

 Author| Post time 8-7-2011 01:27 AM | Show all posts
Reply 4# pengodam


   saya nk paparkan balik semua maklumat yang dimasukkan apabila aturcara FOR habis dilakukan.
Reply

Use magic Report

Post time 8-7-2011 07:19 PM | Show all posts
cari kod ni :
  1. for(int a = 1; a<=bil; a++) {

  2.                         String nama = JOptionPane.showInputDialog(null, " Sila masukkan Nama anda : ");

  3.                         String weightStr = JOptionPane.showInputDialog(null, "Sila Masukkan Berat anda (KG) : ");
  4.                         double w1 = Double.parseDouble(weightStr);
  5.                
  6.                         String heightStr = JOptionPane.showInputDialog(null, "Sila Masukkan Tinggi anda (CM) : ");
  7.                         double h1 = Double.parseDouble(heightStr);

  8.                         B1.kiraBMI(w1,h1,nama);

  9.                        
  10.                        
  11.                 }
Copy the Code
kemudian tambahkan kod ni dibawah kod diatas:
  1. JOptionPane.showMessageDialog(null, " Nama anda :" + nama + " /nBerat : "+w1+"/nTinggi:"+h1);
Copy the Code
Reply

Use magic Report

Follow Us
 Author| Post time 9-7-2011 01:50 AM | Show all posts
Reply 6# pengodam


   jap, aq cuba dlu...
Reply

Use magic Report

 Author| Post time 9-7-2011 02:02 AM | Show all posts
Reply 7# DjKiller


   coding yg ko bg 2, tuk papar semua data yg org pertama masukkan kn? bila dh kira BMI kn? aq nk semua maklumat yang dimasukkan dipaparkan.. kalo da 4 org masukkan data mereka, last sekali empat2 maklumat tersebt dipaparkn... pas2 ko dh cuba pengiraan... rase coding 2 xbtl la.. agak2 da silp x?
Reply

Use magic Report


ADVERTISEMENT


Post time 10-7-2011 12:19 AM | Show all posts
kau print kan je balik pembolehubah weight,height. (kau dah declarekan tp tak gunakan sepenuhnya. Untuk nama dan bmi tu, buat lah mcm weight,height tuh.dan pegang nilai .

wat simple & clean mcmni je (bukan ditulis oleh saya) :
  1. mport java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import javax.swing.event.*;

  5. ////////////////////////////////////////////////////////////// class BMI
  6. class BMI extends JFrame {
  7.     //=============================================== static method main
  8.     public static void main(String[] args) {
  9.         BMI window = new BMI();
  10.         window.setVisible(true);
  11.     }

  12.     //=============================================== instance variables
  13.     // Declare and initialize instance variables that are
  14.     // referred to when the program is running.
  15.     private JTextField _mField   = new JTextField(4);  // height
  16.     private JTextField _kgField  = new JTextField(4);  // weight
  17.     private JTextField _bmiField = new JTextField(4);  // BMI

  18.     //====================================================== constructor
  19.     public BMI() {
  20.         //... Create button and add action listener.
  21.         JButton bmiButton = new JButton("Compute BMI");
  22.         bmiButton.addActionListener(new BMIListener());

  23.         //... Set layout and add components.
  24.         JPanel content = new JPanel();
  25.         content.setLayout(new FlowLayout());
  26.         content.add(new JLabel("Weight in kilograms"));
  27.         content.add(_kgField);
  28.         content.add(new JLabel("Height in meters"));
  29.         content.add(_mField);
  30.         content.add(bmiButton);
  31.         content.add(new JLabel("Your BMI is"));
  32.         content.add(_bmiField);

  33.         //... Set the window characteristics.
  34.         setContentPane(content);
  35.         setTitle("Body Mass Index");
  36.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  37.         pack();                          // Do layout.
  38.         setLocationRelativeTo(null);     // Center window.
  39.     }

  40.     //////////////////////////////////////////// inner class BMIListener
  41.     // Inner class is used to access components.
  42.     // BMI is converted to int to eliminate excess "accuracy".
  43.     private class BMIListener implements ActionListener {
  44.         public void actionPerformed(ActionEvent e) {
  45.             double kilograms = Double.parseDouble(_kgField.getText());
  46.             double meters    = Double.parseDouble(_mField.getText());
  47.             int    bmi       = (int)computeBMI(kilograms, meters);
  48.             _bmiField.setText("" + bmi);
  49.         }
  50.     }

  51.     //=========================================== logic method computeBMI
  52.     public static double computeBMI(double weight, double height) {
  53.         return weight / (height * height);
  54.     }
  55. }
Copy the Code
Reply

Use magic Report

 Author| Post time 10-7-2011 01:52 AM | Show all posts
Reply 9# pengodam


   pape pun thnks for helping..
Reply

Use magic Report

Post time 10-7-2011 09:28 PM | Show all posts
Sesama. Takde hal... loveU
Reply

Use magic Report

 Author| Post time 10-7-2011 11:22 PM | Show all posts
Reply 11# pengodam


   orait.. cnfrm hebat sal java kn nie..
Reply

Use magic Report

Post time 11-7-2011 08:31 PM | Show all posts
pegi ler berguru ngan dier  
Reply

Use magic Report

 Author| Post time 11-7-2011 11:00 PM | Show all posts
Reply 13# JohnDeSouza
tnggu hang lambt sgt.... hahha~
Reply

Use magic Report

Post time 15-7-2011 05:15 PM | Show all posts
busy maaa
Reply

Use magic Report

 Author| Post time 15-7-2011 06:19 PM | Show all posts
Reply 15# JohnDeSouza


   Dh yg hebat bz ja, sush ar nk berguru.... hahaha~pape pun settle sudah aturcara 2, aq duk edit2 mana yang ptt ja.. cuma nk papar kesemua data yg masuk ja xdapt2.. hmmm
Reply

Use magic Report


ADVERTISEMENT


Post time 18-7-2011 12:19 AM | Show all posts
hehehe
pi masuk sini maaa.banyak otai.gud luck.

www.putera.com

www.ittutor.net
Reply

Use magic Report

Post time 30-7-2011 08:21 AM | Show all posts
hehehe
pi masuk sini maaa.banyak otai.gud luck.
JohnDeSouza Post at 18-7-2011 00:19


Tapi, 2 forum tu dah tak semeriah dlu. skrg pun host depa duk problem je,
Reply

Use magic Report

Post time 4-8-2011 07:42 AM | Show all posts
Reply  JohnDeSouza


   Dh yg hebat bz ja, sush ar nk berguru.... hahaha~pape pun settle sudah a ...
DjKiller Post at 15-7-2011 18:19



    pe kata u hold the data in array.. so t u called array tu je la.. sy x pro java.. but konsep logik programming sy faham.. im more on PHP, Cold Fusion and .net.. wish u all d best k..
Reply

Use magic Report

 Author| Post time 5-8-2011 12:29 AM | Show all posts
Reply 19# annadellia
pHp hebat la nie ek..
blh la t minx tlg2 sikit.. hehehe~anyway prob java 2 dh settle dh.. nie dh dapt soklan baru ag.. mencabar sikt ar.

kot2 t da org yg leh tlg gak.. hahaha~
Reply

Use magic Report

12Next
Return to list New
You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CARI Infonet

29-4-2024 05:59 PM GMT+8 , Processed in 0.086816 second(s), 46 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list