Results 1 to 6 of 6

Thread: Quick help

  1. #1
    Qwertypoiuy is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default Quick help

    I spent some time on the sun website reading about classes, but I can't seem to find what I'm looking for.

    I got a quick introduction to classes when I used Visual Basic 6 for about a week. I'd like to use classes in Java the same way. I'm trying to do something like this:

    d=5;
    for (b=.25; b<10; b=b+1/4) {
    findangle(b); }
    System.out.println(angle) // which is shown just below

    //then somewhere (this is where I'm lost)

    class findangle(b as double) {
    angle=arccos(d/(2*b)); }




    Do I need to write class "findangle" in a separate .java file in the same folder? How would that class look, would it have a main? Is there way to have it in the same file? (I guess it's like defining a "Math." function, but I'm still not 100% how they work.)
    It seems like the one line "angle=....." could just as easily be put into the "for" statement, but I have so many little statements like this the code gets jumbled very quickly. Is there a better way of organizing the program than using classes?

    Thanks,
    James

  2. #2
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    ok If i am current in interepreting your question.

    are you asking wether the for loop ? and the findangle method to be in the same class.?

    This is not the correct way of writing the java class.
    Java Code:
    d=5;
    for (b=.25; b<10; b=b+1/4) {
    findangle(b); }
    System.out.println(angle) // which is shown just below
    
    //then somewhere (this is where I'm lost)
    
    class findangle(b as double) {
    angle=arccos(d/(2*b)); }
    heres crude replica of your code.

    Java Code:
    class structure
    {
        private double angle;
    
               void findangle(double b) 
               {
                    angle=arccos(d/(2*b)); // use math library.
               }
    
               public  void calculation()
               {
                    int d=5;
                    for (b=.25; b<10; b=b+1/4) 
                    {
                         findangle(b); 
                    }
                    System.out.println(angle) // which is shown just below
               }
    }

  3. #3
    Qwertypoiuy is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default

    Sorry, I think what I was trying to ask is how can I write a quick subroutine in Java?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    You just need to call the static method in the Math class that finds that inverse of the cosine, I believe that it's Math.acos(double angleInRadians). But more importantly, you should go through a Java book or the Sun tutorial as you're making several very basic errors here that will be corrected with diligent study.

  5. #5
    Qwertypoiuy is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default

    That was just kind of an example. I've been leafing through a book but it only talks about subroutines in the context of objects, which I'm not interested in.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Qwertypoiuy View Post
    That was just kind of an example. I've been leafing through a book but it only talks about subroutines in the context of objects, which I'm not interested in.
    If you really want to learn Java, you'd best learn about Objects and ll. I'd recommend that at this stage, rather than leafing through the book, you go through it from the beginning, and in order.

    Best of luck!

Similar Threads

  1. Quick and Easy Job.
    By Scottyb in forum Jobs Offered
    Replies: 3
    Last Post: 08-11-2009, 04:48 PM
  2. Hello everyone! quick question.
    By irishhokie in forum New To Java
    Replies: 5
    Last Post: 04-03-2009, 05:13 AM
  3. Quick reg. expression help
    By RR_QQ in forum New To Java
    Replies: 4
    Last Post: 02-10-2009, 08:51 PM
  4. Need help quick!
    By Manikyr in forum New To Java
    Replies: 11
    Last Post: 01-28-2009, 05:08 AM
  5. One last quick question
    By jigglywiggly in forum New To Java
    Replies: 7
    Last Post: 01-26-2009, 09:53 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
  •