Skip to content

Commit

Permalink
Add java folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mbazhlekova committed Feb 24, 2018
1 parent 61501ff commit 199abb6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions java/cat-years-dog-years.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* I have a cat and a dog.
I got them at the same time as kitten/puppy. That was humanYears years ago.
Return their respective ages now as [humanYears,catYears,dogYears]
NOTES:
humanYears >= 1
Cat Years
15 cat years for first year
+9 cat years for second year
+4 cat years for each year after that
Dog Years
15 dog years for first year
+9 dog years for second year
+5 dog years for each year after that */

public static int[] humanYearsCatYearsDogYears(final int humanYears) {
int catAge;
int dogAge;
if (humanYears == 1) {
catAge = 15;
dogAge = 15;
}
else if (humanYears == 2) {
catAge = 15 + 9;
dogAge = 15 + 9;
}
else {
catAge = (15 + 9 + (4 * (humanYears - 2)));
dogAge = (15 + 9 + (5 * (humanYears - 2)));
}
return new int[]{humanYears,catAge,dogAge};
}

0 comments on commit 199abb6

Please sign in to comment.