So for my course programming with java I want to exercise a bit. I made a project about planets. I got 4 planets with each of them contain information. I made a "constructor" class Planet:
public class Planet {
String name;
int number;
String color;
int width;
public Planet(String name){
this.name = name;
}
public void Number(int Number){
number = Number;
}
public void Color(String Color){
color = Color;
}
public void Width(int Width){
width = Width;
}
public void printPlanet(){
System.out.println("Name:"+ name );
System.out.println("Number:" + number );
System.out.println("Color:" + color );
System.out.println("Width:" + width);
}
}
and other classes (total = 4) of this type that represent the planets:
public class Earth {
public static void main(String args[]){
Planet earth = new Planet("Earth");
earth.Number(2);
earth.Color("Blue");
earth.Width(47000);
}
}
But now i want to create a simple file with simple code that outputs all the information of all the planets together. I know I can put all the codes from the planets files in one but it's too much and I want a simple file that contains one or two methods/constructors that outputs all the information. Thanks
staticinstances ofPlanetinside ofPlanet(yes you can do that) and just have all the existing planets saved there. (i.e.static Planet Mercury,static Planet Venus, etc). Then just access those.