Support Forums

Full Version: Java Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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
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
Thank you too. I'll show him.