Skip to content

Instantly share code, notes, and snippets.

@Kwisses
Created February 27, 2017 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kwisses/8095ec605cf7cecc44bfafc4e63fcb3c to your computer and use it in GitHub Desktop.
Save Kwisses/8095ec605cf7cecc44bfafc4e63fcb3c to your computer and use it in GitHub Desktop.
[XtraJava] - CompletionDays
// Display number of days ahead/behind scheduled readings
class ReadCalc {
int days;
int pgs_per_day;
int current_days;
ReadCalc(int days, int pgs_per_day, int current_days) {
this.days = days;
this.pgs_per_day = pgs_per_day;
this.current_days = current_days;
}
double calc_total_pgs() {
return (double) days * pgs_per_day;
}
double calc_ahead_behind() {
return (double) current_days - (days * pgs_per_day);
}
boolean ahead() {
if(calc_ahead_behind() > 0) return true;
else return false;
}
}
class CompletionDays {
public static void main(String args[]) {
int total_days, pgs_per_day, current_pg;
double total_pgs, result;
boolean ahead;
total_days = 57;
pgs_per_day = 2;
current_pg = 134;
ReadCalc dc = new ReadCalc(total_days, pgs_per_day, current_pg);
total_pgs = dc.calc_total_pgs();
result = dc.calc_ahead_behind();
ahead = dc.ahead();
System.out.println("You should have read " + total_pgs +
" pages in " + total_days + " days.");
if(ahead) System.out.println("You are ahead " + result + " pgs.");
else {
result *= -1;
System.out.println("You are behind " + result + " pgs.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment