Iteration Mini Lab - The Solar System
Iteration is useful, as it allows us to go through a list of items very quickly. We can easily store a list of things in an array and then call each of the elements with a simple line of code rather than having to write the entire thing again. All in all, Iteration just makes life a lot easier.
public class SolarSystem{
String [][] solarsystem;
public SolarSystem(){
solarsystem = new String[][]{
{
" ,MMM8&&&. ",
" _...MMMMM88&&&&..._ ",
" .::'''MMMMM88&&&&&&'''::. ",
":: MMMMM88&&&&&& ::",
"'::....MMMMM88&&&&&&....::'",
" `''''MMMMM88&&&&''''` ",
" 'MMM8&&&' "
},
{
" _____ ",
" ,-:` \\;',`'-, ",
" .'-;_,; ':-;_,'. ",
" /; '/ , _`.-\\ ",
"| '`. (` /` ` \\`| ",
"|:. `\\`-. \\_ / |",
"| ( `, .`\\ ;'| ",
" \\ | .' `-'/ ",
" `. ;/ .' ",
" `'-._____. "
},
{
" .::.",
" .:' .:",
" ,MMM8&&&.:' .:'",
" MMMMM88&&&& .:' ",
" MMMMM88&&&&&&:' ",
" MMMMM88&&&&&& ",
" .:MMMMM88&&&&&& ",
" .:' MMMMM88&&&& ",
".:' .:'MMM8&&&' ",
":' .:' ",
"'::' "
},
{
" _.._ ",
" .' .-'` ",
" / / ",
" | | ",
" \\ '.___.;",
" '._ _.' ",
" `` "
}
};
}
public void print(){
System.out.println(" ");
System.out.println("The Solar System");
int solarSystemCount = solarsystem.length;
for (int i = solarSystemCount; i > 0; i--){
System.out.println(i + " Planets left to go..");
for (int col = 0; col < solarsystem[0].length; col++){
for (int row = 0; row < i; row++){
System.out.print(solarsystem[row][col] + "\t");
}
System.out.println();
}
System.out.println("The Sun ate a planet whole");
System.out.println("We say RUN RUN RUN FROM THE SUN");
System.out.println("\n--------------------------------------\n");
solarSystemCount -= 1;
}
System.out.println("No more planets in space :( \n");
System.out.println("--------------------------------------");
System.out.println(" THE END ");
}
public static void main(String[] args){
new SolarSystem().print();
}
}
SolarSystem.main(null);