Go to Post Why does kick off take so long to get here but ship date comes toooooooooo fast? - Steve W [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 05-11-2013, 23:16
bhumudar's Avatar
bhumudar bhumudar is offline
Mentor/Programming/Electrical
AKA: Bryant Humud-Arboleda
FRC #0714 (Panthera)
Team Role: Mentor
 
Join Date: Feb 2012
Rookie Year: 2008
Location: Newark
Posts: 50
bhumudar is on a distinguished road
Java Code Question (Method Calling)

Hi, I'm trying to learn java, and this is the first text-based programming language that I've gotten serious about. I am fairly proficient with labVIEW, so a lot of the syntax is new and kind of strange for me, but I digress. I have a particular question involving the following code. Also, if anyone could point me in the direction of any good learning resources for FRC java programming, that would be great. Thanks in advance!


Code:
package practicePackage;

class Planets {
	int moons;
	String name;
	
	Planets (String name, int moons) {
		this.name = name;
		this.moons = moons;
	}
	
	void display() {
		System.out.println(name + " has " + moons + " moons.");
	}
}

class SolarSystem {
	Planets planets[];
	
	SolarSystem() {
	
	planets = new Planets[9];
	planets[0] = new Planets("Mercury", 0);
	planets[1] = new Planets("Venus", 0);
	planets[2] = new Planets("Earth", 1);
	planets[3] = new Planets("Mars", 2);
	planets[4] = new Planets("Jupiter", 16);
	planets[5] = new Planets("Saturn", 18);
	planets[6] = new Planets("Uranus", 15);
	planets[7] = new Planets("Neptune", 8);
	planets[8] = new Planets("Pluto", 1);
	}
	void display() {
		for (int i = 0; i < planets.length; i++ ) {
			planets[i].display();
		}
	}
}

class MilkyWay {
	public static void main(String args[]) {
		SolarSystem solarSystem = new SolarSystem();
		solarSystem.display();
	}
}

Why/how is it that the display method in the SolarSystem class calls the display method in the Planets class? Why is it that it doesn't call in itself recursively?

If it helps, this is the output of the program.

Mercury has 0 moons.
Venus has 0 moons.
Earth has 1 moons.
Mars has 2 moons.
Jupiter has 16 moons.
Saturn has 18 moons.
Uranus has 15 moons.
Neptune has 8 moons.
Pluto has 1 moons.
__________________
Bryant Humud-Arboleda
Stevens Institute of Technology
B.A - Electrical Engineering 14'
Mentor - FRC 714 (2012-Present)
Student - FRC 714 (2009-2010)

2013 Bridgewater-Raritan Winners (Thanks 1676 & 3314)
2012 MAR Regional Championship Judges Award
2012 Mount Olive District Excellence in Engineering Award
2012 Chesapeake Regional Finalist (Thanks 2068 & 358)
2012 Hatsboro-Horsham District Gracious Professionalism Award
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:15.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi