Minta tlg sape yg pro jaVA...
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);
}
} x boleh ker nko upload code java ke dalam code tag dlm advanced mode atau upload ke mana2 file server?
ni contoh code tag
{
huhu
} 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);
}
} Papar 2 kali ? Saya tak faham..tp apa saya tgk mmg diolog box tu yang papar data. lau nak paparjelah 2 kali.JOptionPane.showMessageDialog(null, " BMI " + nama + " ialah : " + fmt.format(B)); Reply 4# pengodam
saya nk paparkan balik semua maklumat yang dimasukkan apabila aturcara FOR habis dilakukan. cari kod ni :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);
}kemudian tambahkan kod ni dibawah kod diatas:JOptionPane.showMessageDialog(null, " Nama anda :" + nama + " /nBerat : "+w1+"/nTinggi:"+h1); Reply 6# pengodam
jap, aq cuba dlu... :) 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? 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) :mport java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
////////////////////////////////////////////////////////////// class BMI
class BMI extends JFrame {
//=============================================== static method main
public static void main(String[] args) {
BMI window = new BMI();
window.setVisible(true);
}
//=============================================== instance variables
// Declare and initialize instance variables that are
// referred to when the program is running.
private JTextField _mField = new JTextField(4);// height
private JTextField _kgField= new JTextField(4);// weight
private JTextField _bmiField = new JTextField(4);// BMI
//====================================================== constructor
public BMI() {
//... Create button and add action listener.
JButton bmiButton = new JButton("Compute BMI");
bmiButton.addActionListener(new BMIListener());
//... Set layout and add components.
JPanel content = new JPanel();
content.setLayout(new FlowLayout());
content.add(new JLabel("Weight in kilograms"));
content.add(_kgField);
content.add(new JLabel("Height in meters"));
content.add(_mField);
content.add(bmiButton);
content.add(new JLabel("Your BMI is"));
content.add(_bmiField);
//... Set the window characteristics.
setContentPane(content);
setTitle("Body Mass Index");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack(); // Do layout.
setLocationRelativeTo(null); // Center window.
}
//////////////////////////////////////////// inner class BMIListener
// Inner class is used to access components.
// BMI is converted to int to eliminate excess "accuracy".
private class BMIListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
double kilograms = Double.parseDouble(_kgField.getText());
double meters = Double.parseDouble(_mField.getText());
int bmi = (int)computeBMI(kilograms, meters);
_bmiField.setText("" + bmi);
}
}
//=========================================== logic method computeBMI
public static double computeBMI(double weight, double height) {
return weight / (height * height);
}
} Reply 9# pengodam
pape pun thnks for helping.. :) Sesama. Takde hal... loveU Reply 11# pengodam
orait.. cnfrm hebat sal java kn nie.. :D pegi ler berguru ngan dier:lol: Reply 13# JohnDeSouza
tnggu hang lambt sgt.... hahha~ busy maaa :lol: 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 hehehe
pi masuk sini maaa.banyak otai.gud luck.
www.putera.com
www.ittutor.net hehehe
pi masuk sini maaa.banyak otai.gud luck.
JohnDeSouza Post at 18-7-2011 00:19 http://eforum.cari.com.my/images/common/back.gif
Tapi, 2 forum tu dah tak semeriah dlu. skrg pun host depa duk problem je, ReplyJohnDeSouza
Dh yg hebat bz ja, sush ar nk berguru.... hahaha~pape pun settle sudah a ...
DjKiller Post at 15-7-2011 18:19 http://forum.cari.com.my/images/common/back.gif
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 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~
Pages:
[1]
2