binibiningtinamoran

Lab6

Oct 5th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. public class Lab6 {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         // Question 1
  6.         int x= 15;
  7.         sentence(x, 42);
  8.  
  9.         int y = x-5;
  10.         sentence(y, x+y);
  11.  
  12.         frontBack(1234);
  13.         System.out.println(); // this is to print a newline for readability purposes
  14.  
  15.         // Question 3
  16.         System.out.println(pay(4, 11));
  17.  
  18.     }
  19.  
  20.     // Question 1
  21.     public static void sentence(int num1, int num2) {
  22.         System.out.println(num1 + " " + num2);
  23.     }
  24.  
  25.     // Question 2
  26.     public static void frontBack(int num) {
  27.         int tempDigit;
  28.  
  29.         while (num > 0) {
  30.             tempDigit = num % 10;
  31.             System.out.print(tempDigit);
  32.             num = num / 10;
  33.         }
  34.     }
  35.  
  36.  
  37.     // Question 3
  38.     public static double pay(double rate, int hoursWorked) {
  39.         double overTimePay = (hoursWorked - 8) * 1.5;
  40.  
  41.         // Using ternary operation below
  42.         return (overTimePay == 0) ? (hoursWorked * rate) : (rate * (overTimePay + 8));
  43.  
  44.         /* LONG VERSION BELOW, uncomment if you want to use this instead but do not forget to
  45.         delete the line of code above.
  46.  
  47.         double overTimePay = (hoursWorked - 8) * 1.5;
  48.         double takeHomePay;
  49.  
  50.         if (salary <= 0 || hoursWorked <= 0) {
  51.             takeHomePay = 0;
  52.         } else {
  53.             if (hoursWorked <= 8) {
  54.                 takeHomePay = salary * hoursWorked;
  55.             } else {
  56.                 overTimePay = (hoursWorked - 8) * 1.5;
  57.                 takeHomePay = salary * (overTimePay + 8);
  58.             }
  59.         }
  60.         return takeHomePay;
  61.          */
  62.     }
  63.  
  64.  
  65.  
  66.  
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment