Results 1 to 6 of 6
  1. #1
    illinit is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default Java, if statement calling class

    Hi everyone.
    I would like to know if it's possible to call a class with the if statement.

    I'm making a Shape viewing app, and I need to make few classes.
    If it's a Square or Circle, I have to call a method that has the same width and height ( I can put inputs for width and height and make shape), so I need to call the Square.java and Circle.java using that statement.

    If it's not Square or Circle, I need to be able to change the width and height, so all other classes goes through the else method.
    width = w;
    height = h;

    Any hint on what to put on (**here**) please?
    So it's like, if (Square.java , Circle.java) { ...
    }{else (Other shapes.java){...}

    Thanks.


    if(**here**){
    int square = compare(w,h);
    width = square;
    height = square;
    }else{
    width = w;
    height = h;
    }


    **
    public int compare(int w, int h){
    if(w >= h){
    return w;
    }else{
    return h;
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default

    Don't double post. Your other thread has been deleted.

    db

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default

    Start here: The Java™ Tutorials

    db

  4. #4
    illinit is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    Sorry, I didn't know where to put this thread.
    Anyway.. I've been searching for the if statement methods.. But there isn't one that specifies my answer..

    I guess it's just an easy code such as.. ms.Circle.java or something.. but I couldn't get an answer :(.

    Any experts that has an answer please?

    if ( **Circle.java and Square.java **) then do this,

    else ( **All other shapes**), then do this..

    Thanks.
    Last edited by illinit; 08-25-2011 at 12:56 PM.

  5. #5
    Join Date
    Aug 2011
    Location
    salt Lake City, Utah
    Posts
    10
    Rep Power
    0

    Default

    It appears that you're asking, "How does one determine the type of an object, given each object is a Shape and there are multiple implementations, each being Square, Circle, Rectangle, Octagon, and Trapezoid? And when I know that how do I ensure that I do one thing when the Shape is a Square or a Circle, and something completely different when it is any other Shape?" Is this correct?
    Last edited by nathandelane; 08-25-2011 at 10:42 PM. Reason: Restated it a little clearing for a newbie.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    Not sure what you mean by an "if statement methods"
    methods belong to classes.
    if ( **Circle.java and Square.java **)
    What condition do you want to test here? The code within the () of an if statement must evaluate to a boolean value of true or false. You can write as many subconditions as you want there and connect then with various boolean operators like and and or.

Similar Threads

  1. Calling Methods in switch Statement
    By borth92 in forum New To Java
    Replies: 7
    Last Post: 12-09-2010, 09:14 AM
  2. Repaint calling Statement Doesn't Work in my code ?
    By nitin_daviet88 in forum CLDC and MIDP
    Replies: 2
    Last Post: 07-24-2010, 03:09 PM
  3. Calling a variable from a different java class
    By jdiesel in forum New To Java
    Replies: 4
    Last Post: 01-09-2009, 01:12 AM
  4. excecuting a jar file by calling a java class
    By Lavanya.vitria in forum Advanced Java
    Replies: 1
    Last Post: 12-13-2008, 12:11 PM
  5. calling a java class from html
    By Ed in forum Advanced Java
    Replies: 1
    Last Post: 07-08-2007, 12:58 AM

Tags for this Thread

Posting Permissions

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