lbfb's Profile User Rating: -----

Reputation: 6 Worker
Group:
Members
Active Posts:
31 (0.03 per day)
Joined:
23-February 12
Profile Views:
378
Last Active:
User is offline Feb 07 2013 11:07 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   lbfb has not set their status

Posts I've Made

  1. In Topic: fraction math

    Posted 2 Feb 2013

    I have had a quick look at the code now, but I am not sure that I actually understand what you are trying to do.


    In your four methods for adding, subtracting . . . the fractions, you try to return two values. I am not 100% sure here, but I don't think that you can return two values in Java (unless you use an array, or a Pair Object). But I don't see why you don't just complete the calculation in the method and return a single value anyway. I would have thought that the addFraction method would look something like this:
    public static int addFraction (int num1, int den1, int num2, int den2) {
          int result = (num1*den2/den1*den2) + (num2*den1/den2*den1);
          return result;
    }
    
    

    My maths could be wrong, but I think that would give you what you need.

    oops sorry Burakaltr - I didn't mean to jump in on your answer.

    And jwhiteknight, I just realised that result shouldn't be an integer in my code snippet.
  2. In Topic: fraction math

    Posted 2 Feb 2013

    without looking at your code I can see that you called the fourth variable den2 when you originally declared it, but afterwards it is called dem2.
  3. In Topic: Problem using array.

    Posted 1 Feb 2013

    Sorry - I should have added that if you start the loop at zero (int i = 0) then you will likely need to set an[i] = i + 1. Otherwise your output will start at zero and end at 25.
  4. In Topic: Problem using array.

    Posted 1 Feb 2013

    when you create the array you have a series of variables an[0], an[1], an[2], etc. What are the values of these at the start of the loop? Because you have only set the first variable with an[0] = 1, the others are either null or zero. In the loop all you are doing is increasing the value of each of these by 1 - so over and over again you are setting an[1] = 1, then an[2] = 1, etc. You are not actually accumulating the values anywhere. There are a few ways to do what you want, but the simplest is probably just to add the value of i in the loop to the value of the variable itself (I think you will have to leave out the line where you set the value of an[0] to 1 also).
  5. In Topic: A Main Class?

    Posted 1 Feb 2013

    None of your code actually asks for any input. What you could do is to add some code like this inside your main method ;
    System.out.println("Please enter your height");
    	 Scanner scanner = new Scanner(System.in);
             double yourheight = scanner.nextDouble();
             System.out.println("Please enter your weight");
             Scanner scanner1 = new Scanner(System.in);
             double yourweight = scanner1.nextDouble();
             double yourBMI = calcBMI(yourweight, yourheight);
             System.out.println("Your BMI is " + yourBMI);
    
    


    (you will have to change your calcBMI method to accept height and weigh as parameters). When you run the code, it should has for height, then weight and then output the calculated BMI. Obviously you will want to do more than this, but this should get you started. Also, you should look up how to use try-catch to ensure you get the input you need from the users.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

lbfb hasn't added any friends yet.

Comments

lbfb has no profile comments yet. Why not say hello?