Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Lab6 {
- public static void main(String[] args) {
- // Question 1
- int x= 15;
- sentence(x, 42);
- int y = x-5;
- sentence(y, x+y);
- frontBack(1234);
- System.out.println(); // this is to print a newline for readability purposes
- // Question 3
- System.out.println(pay(4, 11));
- }
- // Question 1
- public static void sentence(int num1, int num2) {
- System.out.println(num1 + " " + num2);
- }
- // Question 2
- public static void frontBack(int num) {
- int tempDigit;
- while (num > 0) {
- tempDigit = num % 10;
- System.out.print(tempDigit);
- num = num / 10;
- }
- }
- // Question 3
- public static double pay(double rate, int hoursWorked) {
- double overTimePay = (hoursWorked - 8) * 1.5;
- // Using ternary operation below
- return (overTimePay == 0) ? (hoursWorked * rate) : (rate * (overTimePay + 8));
- /* LONG VERSION BELOW, uncomment if you want to use this instead but do not forget to
- delete the line of code above.
- double overTimePay = (hoursWorked - 8) * 1.5;
- double takeHomePay;
- if (salary <= 0 || hoursWorked <= 0) {
- takeHomePay = 0;
- } else {
- if (hoursWorked <= 8) {
- takeHomePay = salary * hoursWorked;
- } else {
- overTimePay = (hoursWorked - 8) * 1.5;
- takeHomePay = salary * (overTimePay + 8);
- }
- }
- return takeHomePay;
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment