SHOW:
|
|
- or go back to the newest paste.
| 1 | - | import java.util.*; |
| 1 | + | |
| 2 | - | import java.lang.*; |
| 2 | + | public class TimeSheet {
|
| 3 | ||
| 4 | - | public class TestTimeSheet {
|
| 4 | + | public int location; // work location |
| 5 | public int locationID; //an ID for location | |
| 6 | - | /** |
| 6 | + | public double rate, workHours, finalPayment; |
| 7 | - | * @param args |
| 7 | + | public String times[] = new String[15]; |
| 8 | - | */ |
| 8 | + | |
| 9 | - | public static void main(String[] args) {
|
| 9 | + | //set the rate based on input and set locationID here |
| 10 | - | // TODO Auto-generated method stub |
| 10 | + | public void setRate(int loc) {
|
| 11 | - | /*String s1 = "John, Susie, Mark, Jack, Jill"; |
| 11 | + | |
| 12 | - | String [] charArray; |
| 12 | + | if(loc >= 500) // 500-599 |
| 13 | - | charArray = s1.split(",");
|
| 13 | + | { rate = 8.0; locationID = 5; }
|
| 14 | - | System.out.println(charArray[1]);*/ |
| 14 | + | else if (loc >= 400) //400-499 |
| 15 | { rate = 13.50; locationID = 4; }
| |
| 16 | - | Scanner input = new Scanner(System.in); |
| 16 | + | else if (loc >= 300) //300-399 |
| 17 | - | //========================================== |
| 17 | + | { rate = 9.25; locationID = 3; }
|
| 18 | else if (loc >= 200) //200-299 | |
| 19 | - | int location; |
| 19 | + | { rate = 7.50; locationID = 2; }
|
| 20 | - | double rate; |
| 20 | + | else if (loc >= 100) //100-199 |
| 21 | - | String times[] = new String[15]; |
| 21 | + | { rate = 10; locationID = 1; }
|
| 22 | ||
| 23 | - | times = input.nextLine().replace(" ", "").split(",");
|
| 23 | + | |
| 24 | - | location = Integer.parseInt(times[0]); |
| 24 | + | |
| 25 | public void Paycheck() {
| |
| 26 | - | //if ( (100 <= location) && (location <= 199) ) {
|
| 26 | + | |
| 27 | - | // rate = 10.0; |
| 27 | + | double totalWeeklyHours = 0.0; //for locations where rate is based on total weekly hours |
| 28 | - | // else if () |
| 28 | + | |
| 29 | - | if(location >= 500) |
| 29 | + | if (locationID < 4) //loop only for locationID = 1, 2, or 3 |
| 30 | - | rate = 8.0; |
| 30 | + | // for 4 and 5, the calculation is quite different |
| 31 | - | else if (location >= 400) |
| 31 | + | {
|
| 32 | - | rate = 13.50; |
| 32 | + | for(int i = 1; i < times.length; i=i+2) {
|
| 33 | - | else if (location >= 300) |
| 33 | + | workHours = code2Time(times[i+1]) - code2Time(times[i]); |
| 34 | - | rate = 9.25; |
| 34 | + | totalWeeklyHours += workHours; |
| 35 | - | else if (location >= 200) |
| 35 | + | } |
| 36 | - | rate = 9.25; |
| 36 | + | |
| 37 | - | else if (location >= 100) |
| 37 | + | |
| 38 | - | rate = 10; |
| 38 | + | finalPayment = calculatePay(locationID, totalWeeklyHours); |
| 39 | System.out.println(); | |
| 40 | System.out.println("Paycheck amount is $" + finalPayment);
| |
| 41 | ||
| 42 | } | |
| 43 | ||
| 44 | - | for(int i = 0; i < times.length; i++) {
|
| 44 | + | private double calculatePay(int loc, double hours) {
|
| 45 | - | //System.out.print(" " + times[i]);
|
| 45 | + | |
| 46 | - | //System.out.println(i + ":" + times[i]); |
| 46 | + | double payment = 0.0; |
| 47 | ||
| 48 | //based on location, calculation is different | |
| 49 | switch (loc) {
| |
| 50 | ||
| 51 | case 1: | |
| 52 | //$10.00 per hour with time and a half for any hours over 30 for the week. | |
| 53 | if (hours < 30) {
| |
| 54 | payment = hours * rate; | |
| 55 | } | |
| 56 | else {
| |
| 57 | payment = 30 * rate + (hours - 30) * rate * 1.5; | |
| 58 | } | |
| 59 | break; | |
| 60 | case 2: | |
| 61 | // $7.50 per hour with double time for hours worked over 40 for the week. | |
| 62 | if (hours < 40) {
| |
| 63 | payment = hours * rate; | |
| 64 | } | |
| 65 | else {
| |
| 66 | payment = 40 * rate + (hours - 40) * rate * 2; | |
| 67 | } | |
| 68 | break; | |
| 69 | case 3: | |
| 70 | // $9.25 for the first 20 hours and $10.50 for the rest. | |
| 71 | if (hours <= 20) {
| |
| 72 | payment = hours * rate; | |
| 73 | } | |
| 74 | else {
| |
| 75 | payment = 20 * rate + (hours - 20) * 10.50; | |
| 76 | } | |
| 77 | break; | |
| 78 | case 4: | |
| 79 | // $13.50 per hour on Sundays (day 1) and Saturdays (day 7) and $6.75 otherwise. | |
| 80 | // to do code here | |
| 81 | break; | |
| 82 | ||
| 83 | case 5: //the calculation of hours is done independently here | |
| 84 | // $8.00 per hour for the first 6 hours per day and $12.00 per hour after that. | |
| 85 | ||
| 86 | double subAmount = 0.0; | |
| 87 | ||
| 88 | for(int i = 1; i < times.length; i=i+2) {
| |
| 89 | workHours = code2Time(times[i+1]) - code2Time(times[i]); | |
| 90 | ||
| 91 | if(workHours <= 6) {
| |
| 92 | subAmount += workHours * rate; | |
| 93 | } | |
| 94 | else {
| |
| 95 | subAmount += 6.0 * rate + (workHours - 6) * 12.0; | |
| 96 | } | |
| 97 | } | |
| 98 | ||
| 99 | payment = subAmount; | |
| 100 | break; | |
| 101 | } | |
| 102 | ||
| 103 | ||
| 104 | return payment; | |
| 105 | } | |
| 106 | ||
| 107 | //code below converts code to hours worked | |
| 108 | private double code2Time(String code) {
| |
| 109 | double hoursWorked = 0; | |
| 110 | code = code.toUpperCase(); | |
| 111 | ||
| 112 | if (code.equals("1")) hoursWorked = 0.0;
| |
| 113 | if (code.equals("2")) hoursWorked = 0.5;
| |
| 114 | if (code.equals("3")) hoursWorked = 1.0;
| |
| 115 | if (code.equals("4")) hoursWorked = 1.5;
| |
| 116 | if (code.equals("5")) hoursWorked = 2.0;
| |
| 117 | if (code.equals("6")) hoursWorked = 2.5;
| |
| 118 | if (code.equals("7")) hoursWorked = 3.0;
| |
| 119 | if (code.equals("8")) hoursWorked = 3.5;
| |
| 120 | if (code.equals("9")) hoursWorked = 4.0;
| |
| 121 | if (code.equals("A")) hoursWorked = 4.5;
| |
| 122 | if (code.equals("B")) hoursWorked = 5.0;
| |
| 123 | if (code.equals("C")) hoursWorked = 5.5;
| |
| 124 | if (code.equals("D")) hoursWorked = 6.0;
| |
| 125 | if (code.equals("E")) hoursWorked = 6.5;
| |
| 126 | if (code.equals("F")) hoursWorked = 7.0;
| |
| 127 | if (code.equals("G")) hoursWorked = 7.5;
| |
| 128 | if (code.equals("H")) hoursWorked = 8.0;
| |
| 129 | ||
| 130 | return hoursWorked; | |
| 131 | } | |
| 132 | ||
| 133 | } |