I am very new to java. I'm really having a tough go of trying to make this GUI function properly. The more I try to fix it, the worse it becomes...so much so that it will not function at all now. Can someone please help me. (I have asked my instructor on many occassions, however he refers me to the confusing text we are to use...and I am a visual learner.)
strDescription = JOptionPane.showInputDialog("Enter description of the object
");//input from user
strWeight = JOptionPane.showInputDialog("Enter weight of the object
");//input from user
weight = Double.parseDouble(strWeight);
wc.setWeight(weight);
wc.setDescription(strDescription);
do {
JOptionPane.showMessageDialog(null, "Please enter valid value for weight.
It should be between 0 and 99999","Inane Error", JOptionPane.ERROR_MESSAGE);//output
to user, error message
validData = false;
while (weight < 0 || weight < 99999) {//sets the parimeters for the error
message
validData = true;
}
if (validData = true){
continue;
JOptionPane.showMessageDialog(null, "The weight of on Mercury is: " +
wc.mercuryWeight(), "Result ", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, "The weight of on Earth is: " +
wc.earthWeight(), "Result ", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, "The weight of on the Moon is: " +
wc.moonWeight(), "Result ", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, "The weight of on Jupiter is: " +
wc.jupiterWeight(), "Result ", JOptionPane.PLAIN_MESSAGE);
}
public WeightCalculator {
public double earthWeight() {
return weight;
}
public double mercuryWeight() {
return weight * 0.378;
}
public double moonWeight() {
return weight * 0.166;
}
public double jupiterWeight() {
return weight * 2.364;
}
public String getDescription() {
return description;
}
public void setWeight(double weight) {
this.weight = weight;
}
public void setDescription(String description) {
this.description = description;
}
}
Select what you want to copy and in doing so you will keep the formatting when pasting it.
You do not have permission to post replies to topics in this board. If you want to join in with discussions and create new topics please register. If you want to register your own free account with us, please click here.