Metric Makes the World Go Round
| Posted in Java , JOptionPane , Variable Types | Posted on 5:56 PM
I'm always a fan of European things. Most often this means cars & food. The metric system though... is something I could take or leave. Like most Americans I don't have a natural sense of how far a kilometer is or how heavy a kilogram weighs. Either of these has to be converted into something in the Standard measurement before anything meaningful can be understood. Thank god for Java.
This is a program which will convert a length in feet into a length in meters.
/*
* This is a simple program to convert feet into meters. Feet are entered
* as a double value, converted into meters as a double value, and then output.
* In/out dialogs are generated using the swing JOptionPane class.
*/
package feet2meters;
import javax.swing.JOptionPane;
/**
* @author Neil
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//prompt the user to enter the number of feet to be converted
//and store as a string value
String stringFeet = JOptionPane.showInputDialog (null,
"Enter the number of feet to be converted to meters",
"Feet2Meters!", JOptionPane.QUESTION_MESSAGE);
//convert feet string value into a double variable
double feet = Double.parseDouble(stringFeet);
//initialize meters as double variable and calculate value
double meters = feet * 0.305;
//display number of meters calculated from feet given
JOptionPane.showMessageDialog(null, feet + " feet is equal to " +
meters + " meters.", "Feet2Meters!",
JOptionPane.QUESTION_MESSAGE);
}
}
* This is a simple program to convert feet into meters. Feet are entered
* as a double value, converted into meters as a double value, and then output.
* In/out dialogs are generated using the swing JOptionPane class.
*/
package feet2meters;
import javax.swing.JOptionPane;
/**
* @author Neil
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//prompt the user to enter the number of feet to be converted
//and store as a string value
String stringFeet = JOptionPane.showInputDialog (null,
"Enter the number of feet to be converted to meters",
"Feet2Meters!", JOptionPane.QUESTION_MESSAGE);
//convert feet string value into a double variable
double feet = Double.parseDouble(stringFeet);
//initialize meters as double variable and calculate value
double meters = feet * 0.305;
//display number of meters calculated from feet given
JOptionPane.showMessageDialog(null, feet + " feet is equal to " +
meters + " meters.", "Feet2Meters!",
JOptionPane.QUESTION_MESSAGE);
}
}
Comments Posted (0)
Post a Comment