Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- //allows for user implementation of data
- public class HalfLifeProgram {
- //constructor
- public double InitialAmount;
- public double TimeElapsed;
- public double HalfLife;
- public double FinalAmount;
- public double exponentFraction;
- public double exponent;
- public double HalfLifeCalculator (double A, double t, double k){
- InitialAmount = A;
- TimeElapsed = t;
- HalfLife = k;
- exponentFraction = t/k;
- exponent = Math.pow(0.5, exponentFraction);
- FinalAmount = A*exponent;
- return FinalAmount;
- //this method runs the half life formula of P = A(.5)^(t/k)
- }
- public double truncate(double a, int b){
- double shortener = Math.pow(10, b);
- return Math.floor(shortener*a) / shortener;
- //this method truncates the long decimals of the end results
- //however after realizing how short/long some half lives are
- //I realized that the deeper decimal places are necessary
- //and thus, this method essentially does nothing for the
- //application
- }
- }
- public class Tester {
- public static void main(String[] args) {
- @SuppressWarnings("resource")
- //I'm not sure what this does but
- //Eclipse said to put this in
- Scanner input = new Scanner(System.in);
- HalfLifeProgram calculator = new HalfLifeProgram();
- double HalfLife;
- double InitialAmount;
- double TimeElapsed;
- double FinalAmount;
- double AmountDecayed;
- System.out.println("This program will calculate the the amount of");
- System.out.println("radioactive decay that occurs over an inputed amount of time");
- System.out.println();
- System.out.println("Please enter the name of your element");
- //asks for name of element then runs name through database
- //if name matches an element in the database, half life will be given
- //if not, user will be asked to input the half life manually
- String name;
- name = input.next();
- String newName;
- newName = name;
- //I know that many if-else statements is not the best
- //nor most efficient way to code this. I have yet to fully
- //understand how to implement the same system with the
- //usage of arrays but will be working on that in a future
- //version of this program.
- if(newName.equals("Technetium")){
- HalfLife = 1536650000;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Promethium")){
- HalfLife = 6351;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Polonium")){
- HalfLife = 37230;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }
- else if(newName.equals("Astatine")){
- HalfLife = .3375;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Radon")){
- HalfLife = 3.82;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Francium")){
- HalfLife = .0152777;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Radium")){
- HalfLife = 584000;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Actinium")){
- HalfLife = 7946.05;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Thorium")){
- HalfLife = 27521000;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Protactinium")){
- HalfLife = 11972000;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Uranium")){
- HalfLife = 8.541 * Math.pow(10, 6);
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Neptunium")){
- HalfLife = 781100000;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Plutonium")){
- HalfLife = 2.92 * Math.pow(10, 8);;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Americium")){
- HalfLife = 2690050 * Math.pow(10, 6);;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Curium")){
- HalfLife = 5.694 * Math.pow(10, 9);;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Berkelium")){
- HalfLife = 503700;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Californium")){
- HalfLife = 327770;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Einsteinium")){
- HalfLife = 471.7;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Fermium")){
- HalfLife = 100.5;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Mendelevium")){
- HalfLife = 51.5;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Nobelium")){
- HalfLife = .0402777777;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Lawrencium")){
- HalfLife = .166666666666;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Rutherfordium")){
- HalfLife = .5416666666666;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Dubnium")){
- HalfLife = 1.33333333333;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Seaborgium")){
- HalfLife = .001666666666;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Bohrium")){
- HalfLife = .000196759;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Hassium")){
- HalfLife = .000112268518;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Meitnerium")){
- HalfLife = .00000833333;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Darmstadtium")){
- HalfLife = .00012847222222;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Roentgenium")){
- HalfLife = .0003009259;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Copernicium")){
- HalfLife = .00033564074;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Ununtrium")){
- HalfLife = .00000555555555555;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Flerovium")){
- HalfLife = .00003067129;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Ununpentium")){
- HalfLife = .00001006944;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Livermorium")){
- HalfLife = .00000706018578;
- System.out.println("The half-life of " + newName + " is " + HalfLife);
- }else if(newName.equals("Ununoctium")){
- HalfLife = .00000020833333;
- }else{
- System.out.println("Element not found. Please enter the half-life of the element in days");
- //element is not in list of elements with already-known half lives
- HalfLife = input.nextDouble();
- HalfLife = (HalfLife * 100)/100;
- }
- System.out.println("Please enter the starting amount of the element in grams");
- //asks for the amount of element that the user begins with
- InitialAmount = input.nextDouble();
- InitialAmount = (InitialAmount*100)/100;
- System.out.println("Please enter the amount of time the element will decay for in days");
- //asks for the amount of the time the element will decay over
- TimeElapsed = input.nextDouble();
- TimeElapsed = (TimeElapsed * 100)/100;
- FinalAmount = (calculator.HalfLifeCalculator(InitialAmount, TimeElapsed,
- HalfLife) * 100)/100;
- AmountDecayed = (InitialAmount - FinalAmount); //determines amount decayed
- System.out.print("After " + TimeElapsed +" days, ");
- System.out.println(FinalAmount + " grams of " + name + " will remain.");
- System.out.println(AmountDecayed + " grams of " + name + " have decayed.");
- //outputs the end results in a nice, clean way
- }
- }
- //https://www.thoughtco.com/list-of-radioactive-elements-608644
- //Used for obtaining common radioactive elements and their half lives
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement