1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- /**
- * <https://y.st./>
- * Copyright © 2017 Alex Yst <mailto:copyright@y.st>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org./licenses/>.
- **/
- $xhtml = array(
- 'title' => 'GravityCalculator.java',
- 'subtitle' => 'Written in <span title="Programming 1">CS 1102</span> of <a href="http://www.uopeople.edu/">University of the People</a>, finalised on 2017-04-12',
- 'copyright year' => '2017',
- 'body' => <<<END
- <h2>Source code:</h2>
- <blockquote>
- <pre><code>/*
- * Copyright (C) 2017 Alex Yst
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package gravitycalculator;
- import java.io.*;
- /**
- *
- * @author Alex Yst
- */
- public class GravityCalculator {
- public static void main(String[] arguments) {
- double gravity =-9.81; // Earth's gravity in m/s^2
- double initialVelocity = 0.0; // starting velocity of the object
- double fallingTime = 10.0; // time in seconds that the object falls
- double initialPosition = 1000.0; // Starting position in meters, the calculation will determine the ending position in meters
- /*
- In this equasion, we multiply by fallingTime twice. Why? Because we need to
- square it. Java lacks an operator for exponentiation, and calling a function to
- do it seems like overkill.
- ...
- For the record though, if we wanted to use the function to do this, Math.pow()
- would be a good candidate.
- */
- double finalPosition = 0.5*gravity*fallingTime*fallingTime+initialVelocity*fallingTime+initialPosition;
- System.out.println("The object's position after " + fallingTime +" seconds is "+finalPosition + " m.");
- }
- }</code></pre>
- </blockquote>
- <h2>Output:</h2>
- <blockquote>
- <pre>run:
- The object's position after 10.0 seconds is 509.49999999999994 m.
- BUILD SUCCESSFUL (total time: 1 second)</pre>
- </blockquote>
- END
- );
|