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 3 of 3

Thread: ...differ in length error; homework starter code not working.

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    46
    My Mood
    Asleep
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default ...differ in length error; homework starter code not working.

    This is NOT my code, but I'm supposed to use it to help me with completing the final thing. The problem is, when I compile it, I get an error saying that method calcGravity in class Gravity1 cannot be applied to given types; required: double[] found: double[],double[] reason: actual and formal argument lists differ in length. I haven't edited it yet, but I wanted to get this part fixed before I do so. Here's the whole starter code:

    import java.io.IOException;
    public class Gravity1
    {
        public static void main(String[] args) throws IOException 
        { 
           String[] names = {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"}; 
           double[] radii = {2439.7, 6051.9, 6378, 3402.5, 71492, 60270, 25562, 24774, 1195}; 
           double[] masses = {3.3022 * Math.pow(10,23), 4.8685 * Math.pow(10,24), 5.9736 * Math.pow(10,24), 6.4185 * Math.pow(10,23), 1.8986 * Math.pow(10,27), 5.6846 * Math.pow(10,26), 8.6810 * Math.pow(10,25), 1.0243 * Math.pow(10,26), 1.312 * Math.pow(10,22)}; 
     
           // alternate 
           //double [] mass = {3.30E23, 4.87E24, 5.97E24, 6.42E23, 1.90E27, 5.68E26, 8.68E25, 1.02E26, 1.27E22};
           double[] gravities = calcGravity(radii, masses);
     
           printResults(names, radii, masses, gravities); 
           printToFile(gravities); 
        } 
        //The return type for printResults is void because you are not returning anything. 
     
        //The return type for calcGravity is an array of doubles: 
        public static double [] calcGravity (double[] arrayDoubles){
            double earthGravity = 6.67 * Math.pow(10, -17) * massOfPlanet/ Math.pow(radiusOfPlanet, 2); //The general formula to find gravity: 
        }
        //where massOfPlanet and radiusOfPlanet are replaced in the above formula by array values. 
     
    }

    The line is pointing to double[] gravities = calcGravity(radii, masses);


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: ...differ in length error; homework starter code not working.

    What exactly do you expect to happen? The calcGravity method takes one argument- an array of doubles. You're trying to pass two different arrays into it.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    46
    My Mood
    Asleep
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: ...differ in length error; homework starter code not working.

    The goal of it is to calculate each planet in our solar system its surface gravity. Though, I'm not sure what double[] gravities = calcGravity(radii, masses); is supposed to be doing. I am supposed to recreate the formula for determining planet surface gravity which I thought would be assigned to double[] gravities. Perhaps I'm supposed to include the formula somewhere in gravities variable but you'r saying there's supposed to be one argument. Maybe I should make a new line assigning double[] calcGravity the formula for surface gravity instead.

Similar Threads

  1. Code working only on ide
    By xeyos in forum Java Networking
    Replies: 0
    Last Post: November 17th, 2011, 05:40 PM
  2. Replies: 2
    Last Post: September 14th, 2011, 11:58 PM
  3. My code is not working
    By mike2452 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 9th, 2011, 06:17 AM
  4. starter
    By Doyle Raymond in forum Java Servlet
    Replies: 2
    Last Post: July 10th, 2011, 10:27 PM
  5. logic error somewhere.. working with try & catch, simple array.. please help
    By basketball8533 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 9th, 2010, 12:40 PM