Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java Help
#1
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?
Reply
#2
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
My SMF Modifications:
http://anthony.vibrantvps.com/smf
Reply
#3
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
Reply
#4
Thank you too. I'll show him.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  why java haphazard 8 1,757 12-12-2011, 03:23 AM
Last Post: RDCA
  Need Java help from java expert. Blazin 2 2,093 09-07-2011, 02:43 PM
Last Post: AceInfinity
  Java help php 1 1,033 04-06-2010, 06:41 AM
Last Post: php
  Java Problem for real java programmer Testgamma1 10 5,142 03-14-2010, 09:08 AM
Last Post: uber1337
  How do i get java Mozz 4 1,586 02-13-2010, 12:29 PM
Last Post: Mozz

Forum Jump:


Users browsing this thread: 2 Guest(s)