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

Thread: JAVA OOP- Driver and Methods will not play nice together- WHY?!?!

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Location
    United States
    Posts
    16
    My Mood
    Lurking
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default JAVA OOP- Driver and Methods will not play nice together- WHY?!?!

    Once again, OOP is determined to keep me up all night

    Here are my methods
    /****************************************************************
    * Pyramid.java
    * Jenn Stanek
    *
    * This program models the calculations for the height,
    * volume and surface aresa of a tetrahedron simulation program.
    ***************************************************************/
     
    import java.util.Scanner;
     
    public class Pyramid
    {
    	Scanner stdIn = new Scanner(System.in);
    	private double edge;           // pyramid's common edge value
    	 //*****************************************************************
    	 // prompts user for edge value and assigns it to the edge instance variable
    	   public void initialize()
    	  {
    	  System.out.println("Enter a value for the pyramid's edges: ");
    	  edge = stdIn.nextDouble();
    	  System.out.printf("Edge length = %d.3/n", edge);
          }
     
    //*****************************************************************
     
       public void setEdge()
         {
    		this.edge = edge;
         }  // end setEdge
     
    //*****************************************************************
     
        public void printPyramidData()  // calculates and prints pyramid data
        {
    		double height = ((Math.sqrt(2/3))*edge);
    		System.out.printf ("Height = %d.3", height);
    		double volume =((Math.sqrt(2))/12)*(Math.pow(edge,3));
    		System.out.printf ("Volume = %d.3", volume);
    		double surfaceArea =(Math.sqrt(3))*(Math.pow(edge,2));
    		System.out.printf ("Surface Area = %d.3", surfaceArea);
    	}
     
     
    //******************************************************************
     
    } // end class Pyramid


    They have to work with this driver
    /***************************************
    * PyramidDriver.java
    * John Dean
    *
    * This is the driver for the Pyramid class.
    ***************************************/
     
    public class PyramidDriver
    {
      public static void main(String[] args)
      {
        Pyramid pyramid;
        pyramid = new Pyramid();
     
        pyramid.initialize();
        pyramid.printPyramidData();
        pyramid.setEdge(4);
        pyramid.printPyramidData();
      } // end main
    } // end class PyramidDriver


    And I get this error
    C:\Users\Jennifer\Documents\school\PyramidDriver.java:17: error: method setEdge in class Pyramid cannot be applied to given types;
        pyramid.setEdge(4);
               ^
      required: no arguments
      found: int
      reason: actual and formal argument lists differ in length
    1 error
     
    Tool completed with exit code 1

    I'm not sure why it won't go back to the setEdge Method. I haven't seen this type of error before and I can't find it in my book. Any help to point me in the right direction would be appreciated.


  2. #2
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: JAVA OOP- Driver and Methods will not play nice together- WHY?!?!

    you used the argument 4 when that method requires no arguments

    public void setEdge()
    {
    this.edge = edge;
    } // end setEdge

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Location
    United States
    Posts
    16
    My Mood
    Lurking
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JAVA OOP- Driver and Methods will not play nice together- WHY?!?!

    I need it to pass the argument of 4 the second time around in order to accurate calculate the total surface area. You first need to calculate the dimensions of one triangle and then the four inside edges. The first time around, it should use the user entered values, but the second time around, it needs to use the 4. I can't get it to work both ways.

    --- Update ---

    I was able to fix it by changing it to public void setEdge(double edge) but now I get this error when running

    Enter a value for the pyramid's edges:
    3
    Edge length = Exception in thread "main" java.util.IllegalFormatConversionExcept
    ion: d != java.lang.Double
    at java.util.Formatter$FormatSpecifier.failConversion (Formatter.java:404
    5)
    at java.util.Formatter$FormatSpecifier.printInteger(F ormatter.java:2748)

    at java.util.Formatter$FormatSpecifier.print(Formatte r.java:2702)
    at java.util.Formatter.format(Formatter.java:2488)
    at java.io.PrintStream.format(PrintStream.java:970)
    at java.io.PrintStream.printf(PrintStream.java:871)
    at Pyramid.initialize(Pyramid.java:21)
    at PyramidDriver.main(PyramidDriver.java:15)
    Press any key to continue . . .

    --- Update ---

    I've also updated my doubles to floats to accomadate the %f but I'm still getting the error and not sure why

  4. #4
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: JAVA OOP- Driver and Methods will not play nice together- WHY?!?!

    can you update that code so it has all the changes you have made so far?

  5. #5
    Junior Member
    Join Date
    Jul 2013
    Location
    United States
    Posts
    16
    My Mood
    Lurking
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JAVA OOP- Driver and Methods will not play nice together- WHY?!?!

    I was able to fix the issues. I was mixing the double and float names for the same variables, I had a mistake in my code where I was doing interger division, and I had named a variable twice (that issue took me the longest to find). I may have made one or two other mistakes that I can't quite remember, but I was able to find them after compiling my program about 50 times.

  6. #6
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: JAVA OOP- Driver and Methods will not play nice together- WHY?!?!

    excellent! happy to hear you could work through the problems

Similar Threads

  1. Need some nice sites to learn Java
    By java in forum Java Theory & Questions
    Replies: 32
    Last Post: April 5th, 2021, 10:46 AM
  2. [SOLVED] Why does OOP hate me so much- can not get my driver to work
    By kissyfurs in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 14th, 2013, 08:15 PM
  3. Basic OOP having trouble determining how to handle methods
    By Nikkon2131 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 21st, 2011, 06:15 PM
  4. Super Friendly & Nice Java Forum!
    By friendly_jessie21 in forum Member Introductions
    Replies: 2
    Last Post: February 5th, 2011, 03:28 PM