Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partially done I02 #8

Merged
merged 3 commits into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Java/Intermediate_02 exoplanet leap years/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions Java/Intermediate_02 exoplanet leap years/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Intermediate_02 exoplanet leap years</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
49 changes: 49 additions & 0 deletions Java/Intermediate_02 exoplanet leap years/src/ExoPlanet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import java.util.Scanner;

public class ExoPlanet {

public static void main(String[] args){

System.out.println("Enter the number of fractions days a year this plant has.\n>> ");

Scanner Reader = new Scanner(System.in);
double days = Reader.nextDouble();
Reader.close();

ExoPlanet exo = new ExoPlanet(days);

int yearsPerLeap = exo.calcYearsPer();

String method = exo.addYear()? "add on" : "take off" ;
System.out.println( "A planet with "+ days +
" days a year, would need a to " + method + " an extra day every "+
yearsPerLeap + " years" );
}

private double days;

public ExoPlanet(double days) {
this.days = days;
}

public int calcYearsPer(){

int yearsPerLeap = 2;
int daysPerYear = (int) Math.floor(this.days);

while(yearsPerLeap*this.days <= yearsPerLeap*daysPerYear + 1){
yearsPerLeap++;
}

return yearsPerLeap-1;
}

public boolean addYear(){
if (Math.round(this.days)==Math.floor(this.days)){
return true;
}
else{
return false;
}
}
}
70 changes: 70 additions & 0 deletions Java/Intermediate_02 exoplanet leap years/src/ExoPlanet_Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import static org.junit.Assert.*;

import org.junit.Test;

public class ExoPlanet_Test {

/*
* Lots of references for space stuff
* https://www.universetoday.com/37507/years-of-the-planets/
* https://en.wikipedia.org/wiki/Planet
*
* Turns out no one seems to have complied a list of possible leap years
* for all the planets, or at least i couldn't find one.
*/

@Test
public void test_calcYearsPer_a() {

ExoPlanet exo = new ExoPlanet(100.25);
assertEquals(4,exo.calcYearsPer());
}

@Test
public void test_calcYearsPer_b() {

ExoPlanet exo = new ExoPlanet(100.33);
assertEquals(3,exo.calcYearsPer());
}


@Test
public void test_calcYearsPer_c() {

ExoPlanet exo = new ExoPlanet(100.001);
assertEquals(1000,exo.calcYearsPer());
}

/*
* REAL PLANET TESTS . . .
*/

// NOTE: Mercury is weird its day is longer than its year

// NOTE: a year on Venus is 1.92 venusian days

// NOTE: a year on Earth is 365.2422 days
@Test
public void test_calcYearsPer_earth() {

ExoPlanet exo = new ExoPlanet(365.2422);
assertEquals(4,exo.calcYearsPer());
}

// NOTE: a year on mars is 668.5991 martian days
// a proposed rule is if (year % 2 == 0 || year % 5 == 0)

// NOTE: a year on Jupiter us 10,475.8 jovian days

// NOTE: a year on Saturn is 24,491.07 Saturnian days
@Test
public void test_calcYearsPer_saturn() {

ExoPlanet exo = new ExoPlanet(24491.07);
assertEquals(14,exo.calcYearsPer());
}

// NOTE: a year on Uranus is 42,718 Uranian days

// NOTE: a year on Neptune is 89,666 Neptunian days
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ I'm using a list of problems from https://adriann.github.io/programming_problems
**ID**|**Task**|**Java**|**C#**|**python**
:-----:|:-----|:-----:|:-----:|:-----:
01| adds up to one hundred | :white_check_mark: | |
02| Exo planet leap years | | |
02| Exo planet leap years | partial | |
03| implement a data structure for graphs | | |
04| DOT representation of a graphs | | |
05| Morse code to english converter | | |
Expand Down