Skip to content

Instantly share code, notes, and snippets.

@iamricard
Created April 21, 2013 10:19
Show Gist options
  • Save iamricard/5429179 to your computer and use it in GitHub Desktop.
Save iamricard/5429179 to your computer and use it in GitHub Desktop.
personal_management
/*
author: @grumpylion
description: does the calculations with the punchcard variable as input
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
// for time calculations
public class calc_time {
// how many times did the employee punch in late
public byte late(byte [][] punchcard) {
byte late = 0; // late counter
for (byte i = 0; i < (punchcard.length); i++) {
if (punchcard[i][0] > 6) { // punch in later than 6
late++;
}
if (punchcard[i][0] == 6) {
if (punchcard[i][1] != 0 || punchcard[i][1] != 00) { // if not punch in o'clock
late++;
}
}
}
return late;
}
// how many times did the employee punch out early
public byte early(byte [][] punchcard) {
byte early = 0; // early counter
for (byte i = 0; i < (punchcard.length); i++) {
if (punchcard[i][2] < 14) { // punch out before 14
if (punchcard[i][3] != 0 || punchcard[i][3] != 00) { // if not punch out o'clock
early++;
}
}
}
return early;
}
// total minutes in the punch card
public int minutes(byte [][] punchcard) {
int min = 0, // total minutes
dmin = 0, // residual minutes
hmin; // minutes in an hour
byte dhours = 0; // daily hours
for (byte i = 0; i < (punchcard.length); i++) {
dhours = (byte)(punchcard[i][2] - punchcard[i][0]); // punch out hour - punch in hour = total hours in given day
hmin = dhours * 60; // total hours * 60 = hours to minutes
dmin = punchcard[i][3];
min = min + hmin; // previous minutes + today's minutes = total minutes
min = min + dmin; // previous minutes + residual minutes = total minutes
}
return min;
}
}
/*
* personalmanagement (main.java)
*
* @grumpylion
*
* Programa de control de personal (suponemos que el horario es de lunes a viernes e intensivo, de 6:00 a 14:00).
* Hay que calcular:
* 1.- Cuantos dias ha llegado tarde.
* 2.- Cuantos dias se ha ido antes.
* 3.- Cuantos minutos ha trabajado este mes.
*
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class main {
private static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
String input;
byte late_days = 0, // punch in late
early_days = 0; // punch out early
int t_min = 0; // minutes
boolean running = true, // keep on running the program
array_empty = true; // fill or not the array
time punchcard_fun = new time(); // allocates space for time.java
menu choice_fun = new menu(); // allocates space for menu.java
byte[][] punchcard = punchcard_fun.punchcard(); // assigns punchcard to the return of punchcard_fun
calc_time calc_fun = new calc_time(); // allocates space for calc_time.java
System.out.println("=== DISCLAIMER ===\nThis program assumes\nyou are not using\nabsurd hours as input\n=== END DISCLAIMER ==");
while (running) { // while running == true, will keep running the program
byte choice = choice_fun.choice();
switch (choice) {
case 1: late_days = calc_fun.late(punchcard);
System.out.println("\nDays punch in late: "+late_days+"\n");
break;
case 2: early_days = calc_fun.early(punchcard);
System.out.println("\nDays punched out early: "+early_days+"\n");
break;
case 3: t_min = calc_fun.minutes(punchcard);
System.out.println("\nTotal amount of minutes: "+t_min+"\n");
break;
case 4: running = false;
break;
default: System.out.println("Wrong input. Restarting.");
break;
}
}
}
}
/*
author: @grumpylion
description: prints out the menu, wait for user input, returns the input
*/
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class menu {
private static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
public byte choice() throws IOException {
String input; // input for stdin
byte choice; // choice variable
System.out.println("1 - Punch in late in # of days\n2 - Punch out early in # of days\n3 - Total # of minutes worked in the month\n4 - Exit");
input = stdin.readLine();
choice = Byte.parseByte(input);
return choice;
}
}
/*
author: @grumpylion
description: fills in the punch card
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class time {
private static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
// returns array of punch in and punch out times
public byte[][] punchcard() throws IOException {
String input;
byte days, // number of days
hour_in, // hour of punch in
minute_in, // minute of punch in
hour_out, // hour of punch out
minute_out; // minute of punch out
// number of working days that month
System.out.print("Total days:");
input = stdin.readLine();
days = Byte.parseByte(input);
// punchcard array
byte punch[][] = new byte[days][4];
// fills the punchcard
for (byte i = 0; i < days; i++) {
System.out.println("\n=== DAY "+(i+1)+" ===");
byte j = 0;
// asks for punch in hour
System.out.print("Punch in hour: ");
input = stdin.readLine();
hour_in = Byte.parseByte(input);
// inputs into the array
punch[i][j] = hour_in;
j++;
// asks for punch in minute
System.out.print("\nPunch in minute: ");
input = stdin.readLine();
minute_in = Byte.parseByte(input);
// inputs into the array
punch[i][j] = minute_in;
j++;
// asks for punch out hour
System.out.print("\nPunch out hour: ");
input = stdin.readLine();
hour_out = Byte.parseByte(input);
// inputs into the array
punch[i][j] = hour_out;
j++;
// asks for punch out hour
System.out.print("\nPunch out minute: ");
input = stdin.readLine();
minute_out = Byte.parseByte(input);
// inputs into the array
punch[i][j] = minute_out;
j++;
}
return punch;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment