Question: How would I turn this into a runable Java code? import javax.swing.JOptionPane; public class JOptionPaneConverter { public static void main(String[] args) { int x =
How would I turn this into a runable Java code?
import javax.swing.JOptionPane; public class JOptionPaneConverter { public static void main(String[] args) { int x = 0; double result, result1, result2; String Inch = "Inch", Foot = "Foot", Yard = "Yard"; String name = JOptionPane.showInputDialog("What is your name: "); String message = String.format("Welcome %s, to the Measurment Converter Program ", name); /*inputs name in %s*/ JOptionPane.showMessageDialog(null, message); //displays the String format message String measuement = JOptionPane.showInputDialog("Which measuement do you wish to convert: " + Inch + ", " + Foot); x = Integer.parseInt(JOptionPane.showInputDialog("Insert Amount: ")); double result = Inch double result1 = Foot if (measuement == "Inch") { JOptionPane.showMessageDialog(null, "Amount of of " + x + " converted to " + Inch + " is: "); JOptionPane.showMessageDialog(null, result + " inches are equal to : Centimeters : " + Double.toString(centimeters) + " Meters : " + Double.toString(meters) + " Feet : " + Double.toString(feet) + " Yards : " + Double.toString(yards) + " Kilometers : " + Double.toString(kilometers) + " "; } if (measuement == "Foot") { JOptionPane.showMessageDialog(null, "Amount of " + x + " converted to " + Foot + " is: "); JOptionPane.showMessageDialog(null, result1 + Meters : " + Double.toString(meters) + " Yard : " + Double.toString(yards) + " Kilometers : " + Double.toString(kilometers) + " Miles : " + Double.toString(miles)+" "; } //Inch Converstions double centimeters = Inch*(2.54); double meters = Inch*(0.0254); double feet = Inch*(0.0833333); double yards = Inch*(0.0277778); double kilometers = Inch*(0.000254); //Foot convertions double meters = Foot*(0.3048); double kilometers = Foot*(0.0003048); double yards = Foot*(0.333333); double miles = Foot*(0.000189394); } }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
