Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: calling method question.

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default calling method question.

    *i am having trouble with calling methods and need to grasp the concept in order to pass a class.
    the program was supposed to collect from the user their systolic, diastolic, ldl and hdl and then the compute ratio method
    was supposed to calculate the ratio of ldl/hdl. and im not sure what's wrong.

    import javax.swing.JOptionPane;
    import java.util.Scanner;
    public class checkup
    {
    public static void main(String[] args)
    {
    String name;
    int patientnumber=335;
    int systolic = 85;
    int diastolic=120;
    int ldl=30;
    int hdl=60;
    public int getsystolic()
    {
    return systolic;
    }
    public int getdiastolic()
    {
    return diastolic;
    }
    public int getldl()
    {
    return ldl;
    }
    public int gethdl()
    {
    return hdl;
    }
    Scanner inputDevice = new Scanner(System.in);

    System.out.print("Please enter your systolic >>");
    systolic = inputDevice.nextInt();

    System.out.print("Please enter your diastolic >>");
    diastolic = inputDevice.nextInt();

    System.out.print("Please enter your ldl >>");
    ldl = inputDevice.nextInt();

    System.out.print("Please enter your hdl >>");
    hdl = inputDevice.nextInt();

    }

    public static int computeRatio(int ldl, int hdl)
    {

    int result=0;
    result = ldl/hdl;
    return result;

    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,233
    Thanks
    52
    Thanked 2,296 Times in 2,267 Posts

    Default Re: calling method question.

    im not sure what's wrong.
    Can you describe "what's wrong"? If you are getting error messages, copy the full text and paste it here.
    If the program's results are wrong, post the results and add some comments saying what is wrong and what the results should be.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: calling method question.

    I can't see where you are calling the computeRatio() method from main.

  4. #4
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: calling method question.

    Quote Originally Posted by Starstreak View Post
    I can't see where you are calling the computeRatio() method from main.
    I apologize I am new to this. and here are the errors.
    and my instructor is not being very helpful.


    ----jGRASP exec: javac -g checkup.java
    checkup.java:43: illegal start of expression
    public int getsystolic()
    ^
    checkup.java:43: ';' expected
    public int getsystolic()
    ^
    checkup.java:48: illegal start of expression
    public int getdiastolic()
    ^
    checkup.java:48: ';' expected
    public int getdiastolic()
    ^
    checkup.java:52: illegal start of expression
    public int getldl()
    ^
    checkup.java:52: ';' expected
    public int getldl()
    ^
    checkup.java:56: illegal start of expression
    public int gethdl()
    ^
    checkup.java:56: ';' expected
    public int gethdl()
    ^
    8 errors



    So where exactly do i need to call the method. outside of both of the classes.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,233
    Thanks
    52
    Thanked 2,296 Times in 2,267 Posts

    Default Re: calling method question.

    First you need to correct the compiler errors. Check that all the {}s are properly paired and in the correct locations.
    The compiler has gotten lost at line 43.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Method not calling?
    By NTWolf1220 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 20th, 2013, 11:04 AM
  2. calling this method
    By antnas in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 2nd, 2012, 01:32 PM
  3. Calling another method on my code
    By Caliichick in forum Java Theory & Questions
    Replies: 3
    Last Post: June 12th, 2012, 05:01 PM
  4. [SOLVED] method calling
    By javapenguin in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 4th, 2010, 01:43 AM
  5. Help Calling Method From Another Class
    By CheekySpoon in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 15th, 2010, 09:24 AM