Created
February 20, 2013 12:51
-
-
Save jabby/4995327 to your computer and use it in GitHub Desktop.
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 fr.jabbytechs; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class Avion { | |
private String nomPrototype; | |
private List<Integer> sequence = new ArrayList<Integer>(); | |
private int altitudeMax; | |
private int volEnAltitudeMax; | |
public Avion(String nomPrototype) { | |
this.nomPrototype = nomPrototype; | |
} | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
Avion prototype = new Avion("Virgon Express"); | |
prototype.calculerSequenceVol(); | |
System.out.println(prototype.toString()); | |
} | |
private void calculerSequenceVol() { | |
// Calcul de la valeur du prototype | |
char[] nomProto = this.nomPrototype.toCharArray(); | |
int valeurPrototype = 0; | |
for (char c : nomProto) { | |
valeurPrototype += c; | |
} | |
int altitude = valeurPrototype; | |
altitudeMax = valeurPrototype; | |
int volEnAltitude = 0; | |
sequence.add(altitude); | |
while (altitude != 1) { | |
if ((altitude % 2) == 0) { | |
altitude /= 2; | |
} else { | |
altitude *= 3; | |
altitude++; | |
} | |
altitudeMax = altitudeMax < altitude ? altitude : altitudeMax; | |
if (altitude >= valeurPrototype) { | |
volEnAltitude++; | |
volEnAltitudeMax = volEnAltitude > volEnAltitudeMax ? volEnAltitude : volEnAltitudeMax; | |
} else { | |
volEnAltitude = 0; | |
} | |
sequence.add(altitude); | |
} | |
} | |
@Override | |
public String toString() { | |
return new StringBuffer().append("Temps de vol : ").append(sequence.size()) | |
.append("\nVol en altitude : ").append(volEnAltitudeMax) | |
.append("\nAltitude max : ").append(altitudeMax) | |
.append("\n").append(sequence.toString()).toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment