Created
January 27, 2012 18:35
-
-
Save genecyber/1690209 to your computer and use it in GitHub Desktop.
Baby Code With Test
This file contains hidden or 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
package code.family.additions; | |
import java.util.Calendar; | |
import java.util.Date; | |
public class BabyCode extends Code { | |
public Date DueDate; | |
public BabyCode(Code mother, Code father) { | |
super(); | |
Utility utils = new Utility(); | |
_genes = utils.join(mother.GetReproductiveGenes(), father.GetReproductiveGenes()); | |
CalculateDueDate(mother.GetOvulationDate()); | |
} | |
protected void CalculateDueDate(Calendar date) { | |
date.add(Calendar.DAY_OF_WEEK,266); | |
DueDate = new Date(date.getTimeInMillis()); | |
} | |
} |
This file contains hidden or 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
package code.family.additions; | |
import static org.junit.Assert.*; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class BabyCodeTests { | |
private BabyCode newBaby; | |
private Code father; | |
private Code mother; | |
@Before | |
public void setup() { | |
father = new Code("Shannon Code"); | |
mother = new Code("Dawn Code"); | |
} | |
@Test | |
public void BabyIsNotNull() throws ParseException { | |
mother.SetOvulationDate(new SimpleDateFormat("MM/dd/yyyy").parse("11/14/2011")); | |
newBaby = new BabyCode(mother,father); | |
assertNotNull(newBaby.DueDate); | |
} | |
} |
This file contains hidden or 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
package code.family.additions; | |
import java.text.ParseException; | |
import java.util.Calendar; | |
import java.util.Date; | |
public class Code { | |
private String _name; | |
public Code() {} | |
public Code(String name) {_name = name;} | |
protected Date _ovulationDate; | |
protected String[] _genes; | |
public String[] GetReproductiveGenes() { | |
return new String[]{"A", "T", "G", "C"}; | |
} | |
public void SetOvulationDate(Date date) throws ParseException { | |
_ovulationDate = date; | |
} | |
public Calendar GetOvulationDate() { | |
Calendar date = Calendar.getInstance(); | |
date.set(Calendar.DAY_OF_MONTH, _ovulationDate.getDate()); | |
date.set(Calendar.MONTH, _ovulationDate.getMonth()); | |
date.set(Calendar.YEAR, _ovulationDate.getYear()); | |
return date; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Congratulations, even if overdue :)