Advertisement
Guest User

Penny Squashing

a guest
Mar 21st, 2013
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.91 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package pennystack;
  6.  
  7. /**
  8.  *
  9.  * @author Andrew
  10.  */
  11. public class PennyStack {
  12.    
  13.     private static class Penny{
  14.         public double thickness, height;//Thickness in inches; height in altitude above sea level of the bottom of the coin, measured in inches
  15.         public double stress;//Stress at the bottom of this penny, in psi
  16.     }
  17.  
  18.     /**
  19.      * @param args the command line arguments
  20.      */
  21.     public static void main(String[] args) {
  22.         Penny[] thePennies = new Penny[16172452];
  23.         thePennies[0] = new Penny();//initialize first penny
  24.         thePennies[0].thickness = .056;
  25.         thePennies[0].stress = 0;
  26.         for(int i = 1; i<thePennies.length; i++)//initialize other pennies
  27.         {
  28.             thePennies[i] = new Penny();
  29.             thePennies[i].thickness = .056;
  30.             thePennies[i].height = thePennies[i-1].height + thePennies[i-1].thickness;
  31.             thePennies[i].stress = 0;
  32.         }
  33.        
  34.         double error = 1;//error in the height of the top of the tower
  35.         while(error>.1){
  36.             double lastHeight = thePennies[16172451].height + thePennies[16172451].thickness;
  37.             System.out.println(lastHeight);
  38.             thePennies[16172451].stress = 0;
  39.             for(int i = thePennies.length-2; i>=0; i--)
  40.             {
  41.                 thePennies[i].stress = thePennies[i+1].stress + getWeight(thePennies[i])/getArea(thePennies[i]);
  42.                 thePennies[i].thickness = getThickness(thePennies[i]);
  43.             }
  44.            
  45.             for(int i = 1; i<thePennies.length; i++)
  46.             {
  47.                 thePennies[i].height = thePennies[i-1].height + thePennies[i-1].thickness;
  48.             }
  49.            
  50.             error = Math.abs(lastHeight - (thePennies[16172451].height + thePennies[16172451].thickness));
  51.         }
  52.         System.out.println(getWeight(thePennies[16172451]));
  53.         System.out.println(getWeight(thePennies[0]));
  54.        
  55.     }
  56.    
  57.     public static double getThickness(Penny p)
  58.     {
  59.         return .056-.000000175*p.stress;
  60.     }
  61.    
  62.     public static double getArea(Penny p)//a more dedicated programmer could find the dependence on area, but that is beyond the linearization of compression we started with.
  63.     {
  64.         double r = .374;
  65.         return Math.PI * r * r;
  66.     }
  67.    
  68.     public static final double m = 0.0025;//weight of a penny, in kg
  69.     public static final double M = Double.parseDouble("5.97219E24");//Mass of the earth, in slugs
  70.     public static final double G = Double.parseDouble("6.67398E-11");//Gravitaional constant of the universe, in m^3 kg^-1 s^-2
  71.     public static final double Re = 6371000;//radius of the earth, in meters
  72.     public static double getWeight(Penny p)
  73.     {
  74.         return (G * M * m / Math.pow(Re + (p.height*.0254), 2))* 0.224808943 ;
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement