All Solutions to Java Exercises

View previous topic View next topic Go down

All Solutions to Java Exercises

Post by Ivi on Sat Feb 06, 2016 6:54 pm

Solutions in this forum will be posted after everyone decides to move on to another exercise.

Commenting in Java is done by typing. Comments do not interfere with the code and are there just to assist the individual writing the code.


/* (Opens comment)
* Asterisk For each line
*/ (Closes comment)


Exercise 1 Solution and Explanation


Code:


public class HelloWorld

{

public static void main(String[] args) /* A function is being declared  */

{
  
  System.out.println("Hello World."); /* System.out.println("Text") prints out text in the output file. The ";" is written to signify that a command line *has ended. */

}

}


Ivi
Admin

Posts : 41
Join date : 2016-02-06

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

Back to top Go down

Re: All Solutions to Java Exercises

Post by Miller on Wed Mar 09, 2016 12:43 am

https://www.dropbox.com/s/q284e72zm9tam0g/FooCorporation.java?dl=0

https://www.dropbox.com/s/aj9pp1jnk035a9w/GravityCalculator.java?dl=0

Miller
Admin

Posts : 19
Join date : 2016-02-06

View user profile

Back to top Go down

Re: All Solutions to Java Exercises

Post by Miller 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);
    }
    
}


Miller
Admin

Posts : 19
Join date : 2016-02-06

View user profile

Back to top Go down

Re: All Solutions to Java Exercises

Post by Sponsored content


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