All Solutions to Java Exercises
2 posters
Page 1 of 1
All Solutions to Java Exercises
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)
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. */
}
}
Re: All Solutions to Java Exercises
- 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
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|