Results 1 to 3 of 3
  1. #1
    noobie_nate is offline Member
    Join Date
    Jun 2013
    Posts
    4
    Rep Power
    0

    Default methods question

    Hello, I am trying to create a program that asks for the type of shape, and then calculates the area of that shape. I think I am on the right track but I am not sure. I can't get the program to continue on to the circle() method.

    package methods;

    import static java.lang.System.*;
    import java.util.Scanner;
    import java.math.*;

    public class areaOfShape {

    private static Scanner kb = new Scanner(System.in);
    private static double area;
    private static double temp;

    public static void circle() {
    out.print("What is the radius of the circle? ");
    double radius = kb.nextDouble();
    temp = Math.PI * Math.pow(radius, 2);
    area = temp;
    out.print(area);
    }

    public static void main(String args[]) {
    out.print("Pick a shape to find area of: ");
    String pickShape = kb.next();

    if (pickShape == "circle") {
    circle();
    }

    out.print("The area of a " + pickShape + " is: " + area);
    }
    }

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,596
    Rep Power
    5

    Default Re: methods question

    Use the equals() method of the String class to check if two Strings are equal. And that's not only true for String objects but for all object types by the way.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    noobie_nate is offline Member
    Join Date
    Jun 2013
    Posts
    4
    Rep Power
    0

    Default Re: methods question

    Awesome that works!! Thank you sir :)

Similar Threads

  1. Question on methods
    By MW130 in forum New To Java
    Replies: 17
    Last Post: 01-07-2013, 10:00 AM
  2. Question about arrays and methods
    By BenH in forum New To Java
    Replies: 3
    Last Post: 01-31-2012, 02:45 AM
  3. Question on HashTable, and methods.
    By fatabass in forum New To Java
    Replies: 16
    Last Post: 01-30-2012, 03:13 PM
  4. Question concerning methods
    By jim01 in forum New To Java
    Replies: 6
    Last Post: 05-18-2011, 02:46 PM
  5. 2 methods with same name Question
    By dienesh77 in forum New To Java
    Replies: 4
    Last Post: 03-22-2011, 01:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •