Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
[JAVA] Converter Script
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Hindi" data-source="post: 258067" data-attributes="member: 26187"><p>So what this script does, is asks you for a value in foot and converts to almost anything, CM,MM,Inch etc</p><p></p><p>[PHP]import java.util.Scanner;</p><p>import javax.swing.JOptionPane;</p><p></p><p></p><p>public class Converter {</p><p> </p><p> Scanner alright = new Scanner(System.in);</p><p> </p><p> public static void cm() {</p><p> String a = JOptionPane.showInputDialog("Enter the Value (FOOT) : ");</p><p> </p><p> int x = Integer.parseInt(a);</p><p> double ans = x * 30.48;</p><p> </p><p> JOptionPane.showMessageDialog(null,"The conversion from foot to cm is : " + ans,"FT TO CM",JOptionPane.PLAIN_MESSAGE);</p><p> }</p><p> </p><p> public static void mm() {</p><p> String a = JOptionPane.showInputDialog("Enter the Value (FOOT) : ");</p><p> </p><p> int x = Integer.parseInt(a);</p><p> double ans = x * 304.8;</p><p> </p><p> JOptionPane.showMessageDialog(null,"The conversion from foot to mm is : " + ans,"FT TO MM",JOptionPane.PLAIN_MESSAGE);</p><p> }</p><p> public static void inch() {</p><p> String a = JOptionPane.showInputDialog("Enter the Value (FOOT) : ");</p><p> </p><p> int x = Integer.parseInt(a);</p><p> double ans = x * 12;</p><p> </p><p> JOptionPane.showMessageDialog(null,"The conversion from foot to Inch is : " + ans,"FT TO Inch",JOptionPane.PLAIN_MESSAGE);</p><p> }</p><p> public static void meter() {</p><p> String a = JOptionPane.showInputDialog("Enter the Value (FOOT) : ");</p><p> </p><p> int x = Integer.parseInt(a);</p><p> double ans = x * 0.3048;</p><p> </p><p> JOptionPane.showMessageDialog(null,"The conversion from foot to Meter is : " + ans,"FT TO Meter",JOptionPane.PLAIN_MESSAGE);</p><p> }</p><p> public static void yard() {</p><p> String a = JOptionPane.showInputDialog("Enter the Value (FOOT) : ");</p><p> </p><p> int x = Integer.parseInt(a);</p><p> double ans = x * 0.333333;</p><p> </p><p> JOptionPane.showMessageDialog(null,"The conversion from foot to Yard is : " + ans,"FT TO Yard",JOptionPane.PLAIN_MESSAGE);</p><p> }</p><p> public static void nauticalmile() {</p><p> String a = JOptionPane.showInputDialog("Enter the Value (FOOT) : ");</p><p> </p><p> int x = Integer.parseInt(a);</p><p> double ans = x * 0.000164579;</p><p> </p><p> JOptionPane.showMessageDialog(null,"The conversion from foot to Nautical Mile is : " + ans,"FT TO Nautical Mile",JOptionPane.PLAIN_MESSAGE);</p><p> }</p><p> public static void main(String args[])</p><p> {</p><p> String choice = JOptionPane.showInputDialog("Select what do you want to convert Foot to (CM,MM,INCH,METER,YARD,NAUTICALMILE");</p><p> switch (choice)</p><p> {</p><p> case "CM":</p><p> case "Centimeter":</p><p> case "CENTIMETER":</p><p> Converter.cm();</p><p> break;</p><p> case "MM":</p><p> case "Milimeter":</p><p> case "MILIMETER":</p><p> Converter.mm();</p><p> break;</p><p> case "Inch":</p><p> case "INCH":</p><p> Converter.inch();</p><p> break;</p><p> case "Meter":</p><p> case "METER":</p><p> case "meter":</p><p> Converter.meter();</p><p> break;</p><p> case "Yard":</p><p> case "YARD":</p><p> Converter.yard();</p><p> break;</p><p> case "NM":</p><p> case "NauticalMile":</p><p> case "NAUTICALMILE":</p><p> Converter.nauticalmile();</p><p> break;</p><p> default:</p><p> JOptionPane.showMessageDialog(null,"Please select appropriate choice", "ERROR",JOptionPane.ERROR_MESSAGE);</p><p> </p><p> </p><p> }</p><p> }</p><p></p><p>}[/PHP]</p><p></p><p>I was lazy to write this ( It was my assignment for Uni ) but @[USER=6113]Macemore[/USER] kept me company aw <img src="/styles/default/xenforo/smilies/emojione/inlove.png" class="smilie" loading="lazy" alt="<3_<3" title="Love <3_<3" data-shortname="<3_<3" /></p></blockquote><p></p>
[QUOTE="Hindi, post: 258067, member: 26187"] So what this script does, is asks you for a value in foot and converts to almost anything, CM,MM,Inch etc [PHP]import java.util.Scanner; import javax.swing.JOptionPane; public class Converter { Scanner alright = new Scanner(System.in); public static void cm() { String a = JOptionPane.showInputDialog("Enter the Value (FOOT) : "); int x = Integer.parseInt(a); double ans = x * 30.48; JOptionPane.showMessageDialog(null,"The conversion from foot to cm is : " + ans,"FT TO CM",JOptionPane.PLAIN_MESSAGE); } public static void mm() { String a = JOptionPane.showInputDialog("Enter the Value (FOOT) : "); int x = Integer.parseInt(a); double ans = x * 304.8; JOptionPane.showMessageDialog(null,"The conversion from foot to mm is : " + ans,"FT TO MM",JOptionPane.PLAIN_MESSAGE); } public static void inch() { String a = JOptionPane.showInputDialog("Enter the Value (FOOT) : "); int x = Integer.parseInt(a); double ans = x * 12; JOptionPane.showMessageDialog(null,"The conversion from foot to Inch is : " + ans,"FT TO Inch",JOptionPane.PLAIN_MESSAGE); } public static void meter() { String a = JOptionPane.showInputDialog("Enter the Value (FOOT) : "); int x = Integer.parseInt(a); double ans = x * 0.3048; JOptionPane.showMessageDialog(null,"The conversion from foot to Meter is : " + ans,"FT TO Meter",JOptionPane.PLAIN_MESSAGE); } public static void yard() { String a = JOptionPane.showInputDialog("Enter the Value (FOOT) : "); int x = Integer.parseInt(a); double ans = x * 0.333333; JOptionPane.showMessageDialog(null,"The conversion from foot to Yard is : " + ans,"FT TO Yard",JOptionPane.PLAIN_MESSAGE); } public static void nauticalmile() { String a = JOptionPane.showInputDialog("Enter the Value (FOOT) : "); int x = Integer.parseInt(a); double ans = x * 0.000164579; JOptionPane.showMessageDialog(null,"The conversion from foot to Nautical Mile is : " + ans,"FT TO Nautical Mile",JOptionPane.PLAIN_MESSAGE); } public static void main(String args[]) { String choice = JOptionPane.showInputDialog("Select what do you want to convert Foot to (CM,MM,INCH,METER,YARD,NAUTICALMILE"); switch (choice) { case "CM": case "Centimeter": case "CENTIMETER": Converter.cm(); break; case "MM": case "Milimeter": case "MILIMETER": Converter.mm(); break; case "Inch": case "INCH": Converter.inch(); break; case "Meter": case "METER": case "meter": Converter.meter(); break; case "Yard": case "YARD": Converter.yard(); break; case "NM": case "NauticalMile": case "NAUTICALMILE": Converter.nauticalmile(); break; default: JOptionPane.showMessageDialog(null,"Please select appropriate choice", "ERROR",JOptionPane.ERROR_MESSAGE); } } }[/PHP] I was lazy to write this ( It was my assignment for Uni ) but @[USER=6113]Macemore[/USER] kept me company aw <3_<3 [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
[JAVA] Converter Script
Top