Website lab
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Exercises 1 and 2

3 posters

Go down

Exercises  1 and 2 Empty Exercises 1 and 2

Post by Miller Sun Feb 28, 2016 12:50 pm



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

Posts : 19
Join date : 2016-02-06

Back to top Go down

Exercises  1 and 2 Empty Re: Exercises 1 and 2

Post by Ivi Tue Mar 08, 2016 9:31 pm

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^2
double 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
Ivi
Admin

Posts : 41
Join date : 2016-02-06

https://website-lab.forumotion.com

Back to top Go down

Exercises  1 and 2 Empty Re: Exercises 1 and 2

Post by Ivi Wed Mar 09, 2016 12:47 am

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
Ivi
Admin

Posts : 41
Join date : 2016-02-06

https://website-lab.forumotion.com

Back to top Go down

Exercises  1 and 2 Empty Re: Exercises 1 and 2

Post by Nickg Fri May 20, 2016 11:51 pm

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

Back to top Go down

Exercises  1 and 2 Empty Re: Exercises 1 and 2

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum