Last active
August 29, 2015 14:08
-
-
Save au5ton/d2c5c5f8b4f680a60fce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Scanner; | |
public class Chemistry | |
{ | |
static Scanner console = new Scanner(System.in); | |
public static void main(String[] args) | |
{ | |
for(;;) | |
{ | |
System.out.print(">> "); | |
String str = console.nextLine(); | |
String[] a = str.split(","); | |
System.out.println(Arrays.toString(a)); | |
try | |
{ | |
String mode = a[0]; | |
double[] d = {Double.parseDouble(a[1]),Double.parseDouble(a[2])}; | |
System.out.print("\n"); | |
if(mode.equals("w2e")) | |
{ | |
System.out.println(wavelengthToEnergy( f(d[0],d[1]) )); | |
} | |
else if(mode.equals("w2f")) | |
{ | |
System.out.println(wavelengthToFrequency( f(d[0],d[1]) )); | |
} | |
else if(mode.equals("f2e")) | |
{ | |
System.out.println(frequencyToEnergy( f(d[0],d[1]) )); | |
} | |
} | |
catch(Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
} | |
} | |
public static final double c = (3.0)*(double)Math.pow(10,8); //Speed of light | |
public static final double h = (6.626)*(double)Math.pow(10,-34); //Plank's constant | |
public static double f(double dec, double exp) | |
{ | |
return (dec)*(double)Math.pow(10,exp); | |
} | |
public static double wavelengthToEnergy(double w) | |
{ | |
return frequencyToEnergy(wavelengthToFrequency(w)); | |
} | |
public static double wavelengthToFrequency(double w) | |
{ | |
return c/w; | |
} | |
public static double frequencyToEnergy(double f) | |
{ | |
return f*h; | |
} | |
} |
Author
au5ton
commented
Oct 24, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment