Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44a0312
commit 0857874
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,104 @@ | |||
import java.text.DecimalFormat; | |||
import java.util.Scanner; | |||
|
|||
|
|||
public class Time24 { | |||
private int hour; | |||
private int minute; | |||
|
|||
|
|||
private void normalizeTime() | |||
{ | |||
int extraHours=minute/60; | |||
|
|||
minute%=60; | |||
hour=(hour+extraHours%24); | |||
} | |||
|
|||
public Time24() | |||
{ | |||
hour=0; | |||
minute=0; | |||
} | |||
|
|||
public Time24(int h, int m) | |||
{ | |||
hour=h; | |||
minute=m; | |||
normalizeTime(); | |||
} | |||
|
|||
public void addTime(int m) | |||
{ | |||
if (m<0) | |||
{ | |||
throw new IllegalArgumentException("Time24.setTime: "+ "argument must be a positive integer"); | |||
} | |||
|
|||
minute+=m; | |||
normalizeTime(); | |||
} | |||
|
|||
public Time24 interval(Time24 t) | |||
{ | |||
int currTime=hour*60+minute; | |||
int tTime=t.hour*60+t.minute; | |||
|
|||
if (tTime<currTime) | |||
tTime+=24*60; | |||
|
|||
return new Time24(0,tTime-currTime); | |||
} | |||
|
|||
public int getHour() | |||
{ | |||
Scanner input=new Scanner(System.in); | |||
return input.nextInt(); | |||
} | |||
|
|||
public int getMinute() | |||
{ | |||
Scanner input=new Scanner(System.in); | |||
return input.nextInt(); | |||
} | |||
|
|||
public void setTime(int h, int m) | |||
{ | |||
if (h<0||m<0) | |||
{ | |||
throw new IllegalArgumentException("Time24.setTime: "+"parameters must be positive integers"); | |||
} | |||
|
|||
this.hour=h; | |||
this.minute=m; | |||
|
|||
normalizeTime(); | |||
} | |||
|
|||
public String toString() | |||
{ | |||
DecimalFormat fmt=new DecimalFormat("00"); | |||
return new String(hour+":"+fmt.format(minute)); | |||
} | |||
|
|||
public static Time24 praseTime(String s) | |||
{ | |||
String hours=""; | |||
String minutes=""; | |||
|
|||
int k=0; | |||
while (s.charAt(k)!=':') | |||
{ | |||
hours=hours+s.charAt(0); | |||
k++; | |||
} | |||
k++; | |||
while (k<s.length()) | |||
{ | |||
minutes=minutes+s.charAt(k); | |||
k++; | |||
} | |||
|
|||
return new Time24(Integer.parseInt(hours),Integer.parseInt(minutes)); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
|
|||
public class TimeCard { | |||
private String workerID; | |||
private double payrate; | |||
private Time24 punchInTime, punchOutTime; | |||
|
|||
public TimeCard(String id, double pr, int punchInHour, int punchInMinute) | |||
{ | |||
workerID=id; | |||
payrate=pr; | |||
punchInTime.setTime(punchInHour, punchInMinute); | |||
} | |||
|
|||
public String payWorker(int punchOutHour, int punchOutMinute) | |||
{ | |||
punchOutTime.setTime(punchOutHour, punchOutMinute); | |||
Time24 result=punchOutTime.interval(punchInTime); | |||
return result.toString(); | |||
} | |||
} |