# Exercises 1 and 2

## Exercises 1 and 2

Last edited by Miller on Sun May 15, 2016 12:18 pm; edited 2 times in total

Miller

Posts : 19
Join date : 2016-02-06

## Re: Exercises 1 and 2

My solution for the Gravity Calculator is.

Code:
`package javaapplication1;      public class JavaApplication1 {public static void main(String[] args) {    double gravity = -9.81; // Earth's gravity in m/s^2double initialVelocity = 0.0;double fallingTime = 10.0;double initialPosition = 0.0;double finalPosition = 0.0; finalPosition = 0.5*gravity*fallingTime*fallingTime + initialVelocity*fallingTime + initialPosition;System.out.println("What is the position of the object after " + fallingTime + "seconds?");  System.out.println("");      System.out.println("  - The position of the object is " + finalPosition + "");  }}`

Output is:

Code:
`What is the position of the object after 10.0seconds?  - The position of the object is -490.50000000000006`

Ivi

Posts : 41
Join date : 2016-02-06

## Re: Exercises 1 and 2

Code:
` public class FooCorporation {         public static void totalpay(int EmployeeNumber, double hoursWorked, double basePay) {        double pay = hoursWorked * basePay;        if (hoursWorked <= 40 && basePay >= 8.00) {                   System.out.println("Employee " + EmployeeNumber+ "s total pay is " + "\$" + pay);        }        else if (hoursWorked > 40 && hoursWorked <= 60 && basePay >=8.00){             double overTimepay = basePay * 1.5;            pay = pay + ((hoursWorked - 40) * overTimepay);            System.out.println("Employee " + EmployeeNumber+ "s total pay is " + "\$" + pay);        }        else {            System.out.println(" Error: The pay for Employee Number " + EmployeeNumber                     + " is breaking local labour laws!!!");        }    }    public static void main(String[] args) {        totalpay( 1, 35, 7.5);        totalpay( 2, 47, 8.20);        totalpay( 3, 73, 10.00);    }     }`

I like this solution. Good job Alex

Ivi

Posts : 41
Join date : 2016-02-06

## Re: Exercises 1 and 2

Here is my solution:

Code:
`class GravityCalculator {    public static void main(String[] arguments) {        double gravity = -9.81;  // Earth's gravity in m/s^2        double initialVelocity = 0.0;        double fallingTime = 10.0;        double initialPosition = 0.0;        double finalPosition = 0.0;        finalPosition = .5 * gravity * fallingTime * fallingTime + initialVelocity * fallingTime + initialPosition;        System.out.println("The object's position after " + fallingTime +                " seconds is " + finalPosition + " m.");    }} `

and for assignment 2:

Code:
`class FooCorporation{  public static void pay(double base_pay, int hours){    if (base_pay < 8.0){      System.out.println("Error: Base pay cannot be under minimum wage.");    } else if (hours > 60){      System.out.println("Error: Number of hours worked greater than 60.");    } else {      int overtime = 0;      if (hours > 40){        overtime = hours - 40;        hours = 40;      }      System.out.println("Employee Wages: \$" + ((hours * base_pay) + (overtime * base_pay * 1.5)));    }  }  public static void main(String[] args){    pay(7.50, 35);    pay(8.20, 47);    pay(10.0, 73);  }}`

Nickg

Posts : 2
Join date : 2016-05-15