Advertisement
Guest User

Untitled

a guest
Jun 5th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.38 KB | None | 0 0
  1. import java.util.Scanner;
  2. //allows for user implementation of data
  3.  
  4.  
  5.  
  6. public class HalfLifeProgram {
  7. //constructor
  8. public double InitialAmount;
  9. public double TimeElapsed;
  10. public double HalfLife;
  11. public double FinalAmount;
  12. public double exponentFraction;
  13. public double exponent;
  14.  
  15.  
  16.  
  17. public double HalfLifeCalculator (double A, double t, double k){
  18. InitialAmount = A;
  19. TimeElapsed = t;
  20. HalfLife = k;
  21. exponentFraction = t/k;
  22. exponent = Math.pow(0.5, exponentFraction);
  23.  
  24. FinalAmount = A*exponent;
  25.  
  26. return FinalAmount;
  27. //this method runs the half life formula of P = A(.5)^(t/k)
  28.  
  29. }
  30. public double truncate(double a, int b){
  31.  
  32. double shortener = Math.pow(10, b);
  33. return Math.floor(shortener*a) / shortener;
  34.  
  35. //this method truncates the long decimals of the end results
  36. //however after realizing how short/long some half lives are
  37. //I realized that the deeper decimal places are necessary
  38. //and thus, this method essentially does nothing for the
  39. //application
  40. }
  41.  
  42. }
  43.  
  44. public class Tester {
  45.  
  46. public static void main(String[] args) {
  47. @SuppressWarnings("resource")
  48. //I'm not sure what this does but
  49. //Eclipse said to put this in
  50. Scanner input = new Scanner(System.in);
  51.  
  52. HalfLifeProgram calculator = new HalfLifeProgram();
  53. double HalfLife;
  54. double InitialAmount;
  55. double TimeElapsed;
  56. double FinalAmount;
  57. double AmountDecayed;
  58.  
  59. System.out.println("This program will calculate the the amount of");
  60. System.out.println("radioactive decay that occurs over an inputed amount of time");
  61. System.out.println();
  62.  
  63. System.out.println("Please enter the name of your element");
  64. //asks for name of element then runs name through database
  65. //if name matches an element in the database, half life will be given
  66. //if not, user will be asked to input the half life manually
  67. String name;
  68.  
  69. name = input.next();
  70. String newName;
  71. newName = name;
  72. //I know that many if-else statements is not the best
  73. //nor most efficient way to code this. I have yet to fully
  74. //understand how to implement the same system with the
  75. //usage of arrays but will be working on that in a future
  76. //version of this program.
  77. if(newName.equals("Technetium")){
  78. HalfLife = 1536650000;
  79. System.out.println("The half-life of " + newName + " is " + HalfLife);
  80. }else if(newName.equals("Promethium")){
  81. HalfLife = 6351;
  82. System.out.println("The half-life of " + newName + " is " + HalfLife);
  83. }else if(newName.equals("Polonium")){
  84. HalfLife = 37230;
  85. System.out.println("The half-life of " + newName + " is " + HalfLife);
  86. }
  87. else if(newName.equals("Astatine")){
  88. HalfLife = .3375;
  89. System.out.println("The half-life of " + newName + " is " + HalfLife);
  90. }else if(newName.equals("Radon")){
  91. HalfLife = 3.82;
  92. System.out.println("The half-life of " + newName + " is " + HalfLife);
  93. }else if(newName.equals("Francium")){
  94. HalfLife = .0152777;
  95. System.out.println("The half-life of " + newName + " is " + HalfLife);
  96. }else if(newName.equals("Radium")){
  97. HalfLife = 584000;
  98. System.out.println("The half-life of " + newName + " is " + HalfLife);
  99. }else if(newName.equals("Actinium")){
  100. HalfLife = 7946.05;
  101. System.out.println("The half-life of " + newName + " is " + HalfLife);
  102. }else if(newName.equals("Thorium")){
  103. HalfLife = 27521000;
  104. System.out.println("The half-life of " + newName + " is " + HalfLife);
  105. }else if(newName.equals("Protactinium")){
  106. HalfLife = 11972000;
  107. System.out.println("The half-life of " + newName + " is " + HalfLife);
  108. }else if(newName.equals("Uranium")){
  109. HalfLife = 8.541 * Math.pow(10, 6);
  110. System.out.println("The half-life of " + newName + " is " + HalfLife);
  111. }else if(newName.equals("Neptunium")){
  112. HalfLife = 781100000;
  113. System.out.println("The half-life of " + newName + " is " + HalfLife);
  114. }else if(newName.equals("Plutonium")){
  115. HalfLife = 2.92 * Math.pow(10, 8);;
  116. System.out.println("The half-life of " + newName + " is " + HalfLife);
  117. }else if(newName.equals("Americium")){
  118. HalfLife = 2690050 * Math.pow(10, 6);;
  119. System.out.println("The half-life of " + newName + " is " + HalfLife);
  120. }else if(newName.equals("Curium")){
  121. HalfLife = 5.694 * Math.pow(10, 9);;
  122. System.out.println("The half-life of " + newName + " is " + HalfLife);
  123. }else if(newName.equals("Berkelium")){
  124. HalfLife = 503700;
  125. System.out.println("The half-life of " + newName + " is " + HalfLife);
  126. }else if(newName.equals("Californium")){
  127. HalfLife = 327770;
  128. System.out.println("The half-life of " + newName + " is " + HalfLife);
  129. }else if(newName.equals("Einsteinium")){
  130. HalfLife = 471.7;
  131. System.out.println("The half-life of " + newName + " is " + HalfLife);
  132. }else if(newName.equals("Fermium")){
  133. HalfLife = 100.5;
  134. System.out.println("The half-life of " + newName + " is " + HalfLife);
  135. }else if(newName.equals("Mendelevium")){
  136. HalfLife = 51.5;
  137. System.out.println("The half-life of " + newName + " is " + HalfLife);
  138. }else if(newName.equals("Nobelium")){
  139. HalfLife = .0402777777;
  140. System.out.println("The half-life of " + newName + " is " + HalfLife);
  141. }else if(newName.equals("Lawrencium")){
  142. HalfLife = .166666666666;
  143. System.out.println("The half-life of " + newName + " is " + HalfLife);
  144. }else if(newName.equals("Rutherfordium")){
  145. HalfLife = .5416666666666;
  146. System.out.println("The half-life of " + newName + " is " + HalfLife);
  147. }else if(newName.equals("Dubnium")){
  148. HalfLife = 1.33333333333;
  149. System.out.println("The half-life of " + newName + " is " + HalfLife);
  150. }else if(newName.equals("Seaborgium")){
  151. HalfLife = .001666666666;
  152. System.out.println("The half-life of " + newName + " is " + HalfLife);
  153. }else if(newName.equals("Bohrium")){
  154. HalfLife = .000196759;
  155. System.out.println("The half-life of " + newName + " is " + HalfLife);
  156. }else if(newName.equals("Hassium")){
  157. HalfLife = .000112268518;
  158. System.out.println("The half-life of " + newName + " is " + HalfLife);
  159. }else if(newName.equals("Meitnerium")){
  160. HalfLife = .00000833333;
  161. System.out.println("The half-life of " + newName + " is " + HalfLife);
  162. }else if(newName.equals("Darmstadtium")){
  163. HalfLife = .00012847222222;
  164. System.out.println("The half-life of " + newName + " is " + HalfLife);
  165. }else if(newName.equals("Roentgenium")){
  166. HalfLife = .0003009259;
  167. System.out.println("The half-life of " + newName + " is " + HalfLife);
  168. }else if(newName.equals("Copernicium")){
  169. HalfLife = .00033564074;
  170. System.out.println("The half-life of " + newName + " is " + HalfLife);
  171. }else if(newName.equals("Ununtrium")){
  172. HalfLife = .00000555555555555;
  173. System.out.println("The half-life of " + newName + " is " + HalfLife);
  174. }else if(newName.equals("Flerovium")){
  175. HalfLife = .00003067129;
  176. System.out.println("The half-life of " + newName + " is " + HalfLife);
  177. }else if(newName.equals("Ununpentium")){
  178. HalfLife = .00001006944;
  179. System.out.println("The half-life of " + newName + " is " + HalfLife);
  180. }else if(newName.equals("Livermorium")){
  181. HalfLife = .00000706018578;
  182. System.out.println("The half-life of " + newName + " is " + HalfLife);
  183.  
  184. }else if(newName.equals("Ununoctium")){
  185. HalfLife = .00000020833333;
  186.  
  187. }else{
  188. System.out.println("Element not found. Please enter the half-life of the element in days");
  189. //element is not in list of elements with already-known half lives
  190. HalfLife = input.nextDouble();
  191. HalfLife = (HalfLife * 100)/100;
  192. }
  193.  
  194. System.out.println("Please enter the starting amount of the element in grams");
  195. //asks for the amount of element that the user begins with
  196. InitialAmount = input.nextDouble();
  197. InitialAmount = (InitialAmount*100)/100;
  198.  
  199.  
  200. System.out.println("Please enter the amount of time the element will decay for in days");
  201. //asks for the amount of the time the element will decay over
  202. TimeElapsed = input.nextDouble();
  203. TimeElapsed = (TimeElapsed * 100)/100;
  204. FinalAmount = (calculator.HalfLifeCalculator(InitialAmount, TimeElapsed,
  205. HalfLife) * 100)/100;
  206.  
  207. AmountDecayed = (InitialAmount - FinalAmount); //determines amount decayed
  208.  
  209. System.out.print("After " + TimeElapsed +" days, ");
  210. System.out.println(FinalAmount + " grams of " + name + " will remain.");
  211. System.out.println(AmountDecayed + " grams of " + name + " have decayed.");
  212. //outputs the end results in a nice, clean way
  213.  
  214. }
  215.  
  216. }
  217.  
  218. //https://www.thoughtco.com/list-of-radioactive-elements-608644
  219. //Used for obtaining common radioactive elements and their half lives
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement