Results 1 to 11 of 11
Thread: Cannot Find Symbol
- 03-30-2011, 01:03 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 10
- Rep Power
- 0
Cannot Find Symbol
I'm trying to finish this assignment and I have one little issue I cant get to go away
import java.util.Scanner;
final class Circle
{
Scanner stdIn = new Scanner (System.in);
private double diameter;
private double radius;
private double circumfrence;
private double pi = 3.14159;
public Circle(int newRadius, int newCircumfrence)
{
setRadius(newRadius);
}
public int getRadius()
{
System.out.println("Please Enter a positive number for the Radius");
radius = stdIn.nextInt( );
return (int) (double) radius;
}
public int getCircumfrence()
{
return (int) (double) (pi*2*radius);
}
public void setRadius(double newRadius)
{
radius = newRadius;
}
public void setCircumfrence(int newCircumfrence, int Circumfrence)
{
Circumfrence = newCircumfrence;
}
public double getArea()
{
return pi*(radius*radius);
}
public double getDiameter()
{
return radius*2;
}
}
public class CircleDemo
{
public static void main(String args[])
{
int circle = 0;
Circle circ = new Circle(); //ERROR HERE
System.out.println("Area is: " + circ.getArea());
System.out.println("Cicumfrence is: " + circ.getCircumfrence());
System.out.println("Diameter is: " + circ.getDiameter());
}
}
Just above on the line Circle Circ = new circle();
Netbeans says:
Cannot Find Symbol
Symbol: Constructor Circle()
location: class circle
I'm new to this type of thing, and frankly, I suck. :(
Any Suggestions to how I get rid of this and get it to compile?
- 03-30-2011, 01:06 AM #2
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 3
In your Circle constructor you require 2 ints as parameters. When you tried creating a Circle object you didn't supply the required parameters.
- 03-30-2011, 01:12 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 10
- Rep Power
- 0
- 03-30-2011, 01:14 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
The default constructor is supplied by the compiler if you don't provide any constructors. The second you provide a constructor the compiler stops providing a default constructor. You are attempting to create a circle with a default constructor that doesn't actually exist.
A default constructor is one that does not take any arguments.
- 03-30-2011, 01:17 AM #5
Member
- Join Date
- Mar 2011
- Posts
- 10
- Rep Power
- 0
- 03-30-2011, 01:19 AM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
If you don't know what I said I suggest you read your text book or the java tutorials. What I said was not very advanced. Read up on what a constructor is and what I said should make more sense, if it doesn't make more sense after some reading, come back and let me know and I will help you out.
- 03-30-2011, 01:30 AM #7
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 3
Ok, as Sunde said, I would advise you learn about object-oriented programming (considering Java is the most OO language and this is very important stuff.)
But let me show to you simply:
You made a constructor like this:
But when you called the constructor to create a new Circle object, you didn't supply the parameters you specified in your constructor (the two ints).Java Code:public Circle(int param1, int param2)
This is what you did:
Here is what you should be doing to satisfy the requirements of your constructor:Java Code:Circle c = new Circle();
Java Code:int a; int b; Circle c = new Circle(a, b);
- 03-30-2011, 01:48 AM #8
Member
- Join Date
- Mar 2011
- Posts
- 10
- Rep Power
- 0
Still can't get it to work. We just barely talked about OOP last class and I'm just confused. I just want exactly what I need to do to get this to work. I just wanted to try programming and I don't really understand or like it and am already planning on switching my major to something I do enjoy and understand.
I dont understand what you meant for satisfying the constructor. (the int a; int b; ) because I didn't type a Circle C = new Circle.
I see Public Circle (int newRadius, int newCircumfrence) in the top part and Circle circ = new circle() on the bottom part.
Sorry not trying to annoy or anything but I really picked the wrong thing for me to try.
EDIT: Hold on, I got it. Thanks for help.Last edited by Promisha; 03-30-2011 at 01:50 AM.
- 03-30-2011, 01:52 AM #9
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
It's not that hard, you can definitely understand it just google constructors and you should get a decent understanding. You need to code a new constructor which does not take any arguments or supply two arguments to the constructor at the bottom.
- 03-30-2011, 02:00 AM #10
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 3
- 03-30-2011, 02:11 AM #11
Similar Threads
-
Cannot find symbol
By Johanis in forum New To JavaReplies: 19Last Post: 11-04-2010, 08:13 PM -
Cannot find symbol
By SarahB in forum New To JavaReplies: 0Last Post: 03-06-2010, 03:03 PM -
Can not find symbol ???
By AliceNewbie in forum New To JavaReplies: 1Last Post: 02-17-2010, 01:44 AM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08:26 PM -
cannot find symbol symbol : class Item location: package platypos.services.order
By officialhopsof in forum New To JavaReplies: 3Last Post: 05-01-2008, 08:30 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks