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

All Solutions to Java Exercises

2 posters

Go down

All Solutions to Java Exercises  Empty All Solutions to Java Exercises

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

Posts : 41
Join date : 2016-02-06

https://website-lab.forumotion.com

Back to top Go down

All Solutions to Java Exercises  Empty Re: All Solutions to Java Exercises

Post by Miller 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
Miller
Admin

Posts : 19
Join date : 2016-02-06

Back to top Go down

All Solutions to Java Exercises  Empty Re: All Solutions to Java Exercises

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