()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:
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!
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:
Code java:
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.
Re: ()Method cannot be applied to ()
So, on line 19, I need to specify that it is an integer in the parentheses?
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.
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.
Re: ()Method cannot be applied to ()
Quote:
Originally Posted by
CrimsonFlash
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.
Re: ()Method cannot be applied to ()
Quote:
Originally Posted by
CrimsonFlash
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:
Code java:
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
Re: ()Method cannot be applied to ()
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(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
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.
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.
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