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

Thread: ()Method cannot be applied to ()

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default ()Method cannot be applied to ()

    So, after two days of trying to figure out the problem, I've decided to come to the experts for advice. Here is my code:

    import java.util.Scanner;
     
    public class Quiz7
    {
    	public static void main(String[] args)
    	{
    			String radius;
    			Scanner keyboard = new Scanner(System.in);
    			String programName;
    			String dueDate;
    			System.out.print("What is the name of the program? ");
    			programName=keyboard.nextLine();
    			System.out.print("What is the due date of the program? ");
    			dueDate=keyboard.nextLine();
    			int iMenuInput = 0;
    			final double PI = 3.1416f;
    			displayMyInfo(programName, dueDate);
    			menu();	
    			AreaCircle();
     
     
    			}//end of main
     
    	public static void displayMyInfo(String programName, String dueDate)
    	{
    			System.out.print("The program name is" +programName);
    			System.out.print("The due date of the program is" +dueDate);
    	}//end of displayMyInfo
     
     
    	public static int menu()
    	{
    		Scanner kb2 = new Scanner(System.in);
    		int iMenuInput;
    		System.out.print("* * * * * * * * M E N U * * * * * * * *");
    		System.out.print("\n\n1>   Area of a circle");
    		System.out.print("\n2>    Circumference of a circle");
    		System.out.print("\n3>    Area of a rectangle");
    		System.out.print("\n4>   Perimeter of a rectangle");
    		System.out.print("\n5>    Volume of a box");
    		System.out.print("\n6>    Volume of a cone");
    		System.out.print("Enter your choice ");
    		iMenuInput=kb2.nextInt();
    		System.out.print ("  OR 2, OR 3, OR 4, ETC");
    		return iMenuInput;
    	}//end of menu
     
    	public static double AreaCircle(int radius)
    	{
    		final double PI = 3.1416f;
    		double dAreaCircle;
     
    		dAreaCircle = PI * radius * radius;
     
    		return dAreaCircle;
     
    	}//end of areaCircle
     
    	public static double circumference(int radius)
    	{
    		final double PI = 3.1416f;
    		float fCircumference;
    		fCircumference = (float)(2 * PI * radius);
    		return fCircumference;
    	}//end of circumference
     
    	public static int areaRectangle(int length, int width)
    	{
    		int iAreaRectangle;
    		iAreaRectangle = length * width;
    		return iAreaRectangle;
    	}//end of areaRectangle
     
    	public static int perimeterRectangle(int length, int width)
    	{
    		int iPerimeterRectangle;
    		iPerimeterRectangle = 2 *(length * width);
    		return iPerimeterRectangle;
    	}//end of perimeterRectangle
     
    	public static int volumeBox(int length, int width, int height)
    	{
    		int iVolumeBox;
    		iVolumeBox = length * width * height;
    		return iVolumeBox;
    	}//end of volumeBox
     
    	public static double volumeCone(int radius, int height)
    	{
    		final double PI = 3.1416f;
    		float fVolumeCone;
    		fVolumeCone = (float)(PI*radius*radius*radius*height)/3.0f;
    		return fVolumeCone;
    	}//end of volumeCone
     
     
     
     
     
     
    }//end of Quiz7

    The problem seems to lie on line 19, with the error: AreaCircle(int) in Quiz7 cannot be applied to ()
    AreaCircle();

    Thanks for your help in advance!


  2. #2
    Member
    Join Date
    Mar 2011
    Posts
    66
    My Mood
    Relaxed
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: ()Method cannot be applied to ()

    I don't have that much Java experience but what the error is saying is that the method needs an int in the () of the method. Your instance method is:
    	public static double AreaCircle(int radius)   //specifically the (int radius) parameter
    	{
    		final double PI = 3.1416f;
    		double dAreaCircle;
     
    		dAreaCircle = PI * radius * radius;
     
    		return dAreaCircle;
     
    	}//end of areaCircle
    Basically, you need to put an integer into your method because you set a parameter for it. I'm pretty sure AreaCircle(); =/= AreaCircle(parameter(s)); since adding parameters would make them separate methods, despite having the same name.

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: ()Method cannot be applied to ()

    So, on line 19, I need to specify that it is an integer in the parentheses?

  4. #4
    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: ()Method cannot be applied to ()

    Yep. Your AreaCircle() method (which should be areaCircle(), btw) takes a single int argument. When you call the method, you have to provide that parameter.
    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!

  5. #5
    Junior Member
    Join Date
    Oct 2011
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: ()Method cannot be applied to ()

    Alright, thank you. It is now telling me that I am missing a .class on the same line. How would I go about fixing this. And thank you again for your quick replies.

  6. #6
    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: ()Method cannot be applied to ()

    Quote Originally Posted by CrimsonFlash View Post
    Alright, thank you. It is now telling me that I am missing a .class on the same line. How would I go about fixing this. And thank you again for your quick replies.
    We can't really help you without being able to see your code. Make sure all your braces and parenthesis match.
    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!

  7. #7
    Member
    Join Date
    Mar 2011
    Posts
    66
    My Mood
    Relaxed
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: ()Method cannot be applied to ()

    Quote Originally Posted by CrimsonFlash View Post
    So, on line 19, I need to specify that it is an integer in the parentheses?
    Well, pretty much, I think. In your case, since you wanted the method to calculate the area of a circle given a radius, when you call it, it basically wants an integer (or radius), to use in the calculation. Since you call the method using AreaCircle(); the program is looking for a method called AreaCircle() with no parameter instead of the AreaCircle(int radius). So when you do call the method, you have to either put a specific value or you can use a variable for a user inputted integer.

    Example:
    int x = 0;
    AreaCircle(x);
    //or it would be
    AreaCircle(0);
    but for your situation, I'd recommend setting an int variable to equal a user input, kind of like how you did in your menu method.

    *ahh KevinWorkman answered because I was so slow
    *anyways, it's pretty much what he said

  8. #8
    Junior Member
    Join Date
    Oct 2011
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: ()Method cannot be applied to ()

    import java.util.Scanner;
     
    public class Quiz7
    {
    	public static void main(String[] args)
    	{
    			String radius;
    			Scanner keyboard = new Scanner(System.in);
    			String programName;
    			String dueDate;
    			System.out.print("What is the name of the program? ");
    			programName=keyboard.nextLine();
    			System.out.print("What is the due date of the program? ");
    			dueDate=keyboard.nextLine();
    			int iMenuInput = 0;
    			final double PI = 3.1416f;
    			displayMyInfo(programName, dueDate);
    			menu();	
    			areaCircle(int);
     
     
    	}//end of main
     
    	public static void displayMyInfo(String programName, String dueDate)
    	{
    			System.out.print("The program name is" +programName);
    			System.out.print("The due date of the program is" +dueDate);
    	}//end of displayMyInfo
     
     
    	public static int menu()
    	{
    		Scanner kb2 = new Scanner(System.in);
    		int iMenuInput;
    		System.out.print("* * * * * * * * M E N U * * * * * * * *");
    		System.out.print("\n\n1>   Area of a circle");
    		System.out.print("\n2>    Circumference of a circle");
    		System.out.print("\n3>    Area of a rectangle");
    		System.out.print("\n4>   Perimeter of a rectangle");
    		System.out.print("\n5>    Volume of a box");
    		System.out.print("\n6>    Volume of a cone");
    		System.out.print("Enter your choice ");
    		iMenuInput=kb2.nextInt();
    		System.out.print ("  OR 2, OR 3, OR 4, ETC");
    		return iMenuInput;
    	}//end of menu
     
    	public static double areaCircle(int radius)
    	{
    		final double PI = 3.1416f;
    		double dAreaCircle;
     
    		dAreaCircle = PI * radius * radius;
     
    		return dAreaCircle;
     
    	}//end of areaCircle
     
    	public static double circumference(int radius)
    	{
    		final double PI = 3.1416f;
    		float fCircumference;
    		fCircumference = (float)(2 * PI * radius);
    		return fCircumference;
    	}//end of circumference
     
    	public static int areaRectangle(int length, int width)
    	{
    		int iAreaRectangle;
    		iAreaRectangle = length * width;
    		return iAreaRectangle;
    	}//end of areaRectangle
     
    	public static int perimeterRectangle(int length, int width)
    	{
    		int iPerimeterRectangle;
    		iPerimeterRectangle = 2 *(length * width);
    		return iPerimeterRectangle;
    	}//end of perimeterRectangle
     
    	public static int volumeBox(int length, int width, int height)
    	{
    		int iVolumeBox;
    		iVolumeBox = length * width * height;
    		return iVolumeBox;
    	}//end of volumeBox
     
    	public static double volumeCone(int radius, int height)
    	{
    		final double PI = 3.1416f;
    		float fVolumeCone;
    		fVolumeCone = (float)(PI*radius*radius*radius*height)/3.0f;
    		return fVolumeCone;
    	}//end of volumeCone
     
     
     
     
     
     
    }//end of Quiz7

    As Kevin requested, here is my code. Thanks

  9. #9
    Junior Member
    Join Date
    Oct 2011
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: ()Method cannot be applied to ()

    In our Java class, we are working with UML statements, so I have to stick to calling the methods like that. Unless I'm missing something, of course.

  10. #10
    Member
    Join Date
    Mar 2011
    Posts
    66
    My Mood
    Relaxed
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: ()Method cannot be applied to ()

    Do you think you could paste the error message? Also, for the areaCircle(int); I didn't mean to literally put "int" in there but to put an integer value, either an int variable or value like in my previous post.

  11. #11
    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: ()Method cannot be applied to ()

    And what line is your error on?

    Edit- Now I'm the one that's too slow. Actinistia got it right. Maybe I should just butt out. :p
    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!

Similar Threads

  1. Java Error cannot be applied to (java.lang.String), phone book entry program.
    By iceyferrara in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 23rd, 2011, 06:32 AM
  2. Operator % cannot be applied to java.lang.String,int?
    By javarum in forum Java Theory & Questions
    Replies: 8
    Last Post: July 12th, 2011, 08:06 PM
  3. lookandfeel() cannot be applied to JFrame?
    By emigrant in forum AWT / Java Swing
    Replies: 1
    Last Post: February 15th, 2010, 12:05 PM
  4. Inputs not being applied.
    By Norflok669 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 15th, 2010, 01:25 AM
  5. [SOLVED] Facing java error "cannot be applied to (java.lang.String)"
    By tazjaime in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 23rd, 2009, 10:19 AM