Exercises 1 and 2

View previous topic View next topic Go down

Exercises 1 and 2

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

http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-092-introduction-to-programming-in-java-january-iap-2010/assignments/MIT6_092IAP10_assn01.pdf

http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-092-introduction-to-programming-in-java-january-iap-2010/assignments/MIT6_092IAP10_assn02.pdf

here are the two assignments they are a bit weird.




*****Warning Do not Proceed Any further if you havent completed these assignments yet ******* Any concerns or questions pm me.


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

Miller
Admin

Posts : 19
Join date : 2016-02-06

View user profile

Back to top Go down

Re: Exercises 1 and 2

Post by Ivi on 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
Admin

Posts : 41
Join date : 2016-02-06

View user profile http://website-lab.forum-board.net

Back to top Go down

Re: Exercises 1 and 2

Post by Ivi on 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
Admin

Posts : 41
Join date : 2016-02-06

View user profile http://website-lab.forum-board.net

Back to top Go down

Re: Exercises 1 and 2

Post by Nickg on 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

View user profile

Back to top Go down

Re: Exercises 1 and 2

Post by Sponsored content Today at 1:04 pm


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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