Support Forums
Java Help - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Java Programming (https://www.supportforums.net/forumdisplay.php?fid=22)
+---- Thread: Java Help (/showthread.php?tid=4417)



Java Help - Gone - 01-19-2010

A friend is having a problem.

Quote:
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class DescribingThePlanets2
{
public static void main(String args[])
{
int Planet;
int answerSquare;
int answerCube;
int num1;


String numOne =
JOptionPane.showInputDialog("Enter a number to be squared");

num1 = Integer.parseInt(numOne);

answerSquare = square(num1);
answerCube = cube(num1);
System.out.println("The squared value returned from the method is " + answerSquare);
System.out.println("The cubed value returned from the method is " + answerCube);

String strPlanet;

strPlanet = JOptionPane.showInputDialog("Enter a Number of a Planet Please ");
Planet = Integer.parseInt(strPlanet);

if(Planet <= 1)
{
System.out.println("Mercury");

}
else if(Planet <= 2)
{
System.out.println("Venus");
}
else if(Planet <= 3)
{
System.out.println("Earth");
}
else if(Planet <= 4)
{
System.out.println("Mars");
}
else if(Planet <= 5)
{
System.out.println("Jupiter");
}
else if(Planet <= 6)
{
System.out.println("Saturn");
}
else if(Planet <= 7)
{
System.out.println("Uranus");
}
else if(Planet <= 8)8)
{
System.out.println("Neptune");
}
else if(Planet <= 9)
{
System.out.println("Pluto");
}
}

public static int square(int number) //method declaration
{
return number number;
}

public static int cube(int number)
{
return number number * number;
}

}
"Its supposed to use Math.pow to find circumference,radius,and diamete"

In his own words. I know nothing about Java, so, i can't say, can you?


RE: Java Help - Project Evolution - 01-20-2010

Well here he doesnt seem to be using the Math class's pow() method. Also, tell him to use an ArrayList for the planets. :p


RE: Java Help - Qkyrie - 01-21-2010

boom boom pow
Code:
public static double pow(double a, double b)
  • Returns the value of the first argument raised to the power of the second argument.

Code:
public double square(double number)
{
return Math.pow(number, 2.0);
}
Same goes for all the other things you need ;-)

regards
Q


RE: Java Help - Gone - 01-21-2010

Thank you too. I'll show him.