hey guys, just need a quick tip on something!

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2007
Posts: 9
Reputation: AceAtch is an unknown quantity at this point 
Solved Threads: 0
AceAtch AceAtch is offline Offline
Newbie Poster

hey guys, just need a quick tip on something!

 
0
  #1
Nov 5th, 2008
Hi all, I have an assignment to hand in tomorrow for programming and would appreciate any help that is given. I have done a couple of years programming with VB but java is like on a completely level compared to it.
Ok, so basically I have to program an application that will have a constructor to create a circle with a unit radius. The method will then return
- The radius
- The area
- The circumference
- The total area of the object and another circle
- The total circumference of the object and another circle

I’ve practically finished with the program but keeps giving me 1 error at the end that I can’t seem to solve.
My code for the method is here:
  1. //Circle
  2. //An application that can create a circle using the radius given from the user and to calculate the
  3. //area, circumference of it and to display it to the user.
  4.  
  5. import java.io.*;
  6. public class Circle {
  7. public int radiusInt;
  8. public String radiusStringInput;
  9. public void main(String[] args) throws IOException {
  10.  
  11. // Create BufferedReader instance to enable input from keyboard
  12. InputStreamReader input = new InputStreamReader(System.in);
  13. BufferedReader keyboardInput = new BufferedReader(input);
  14.  
  15. System.out.println("please enter the radius:");
  16. radiusStringInput = keyboardInput.readLine();
  17. radiusInt = Integer.parseInt(radiusStringInput);
  18. }
  19. public Circle(int x, int y,int r){
  20. r = radiusInt;
  21. x = radiusInt *2;
  22. y= radiusInt * 2;
  23. }
  24. public int radiusInt(){
  25. radiusInt = radiusInt;
  26. return (radiusInt);
  27. }
  28. public Double getCircumference(){
  29. Double Circ = 2 * 3.14 * radiusInt;
  30. return (Circ);
  31. }
  32. public Double getArea(){
  33. double Area = 3.14 * radiusInt * radiusInt;
  34. return (Area);
  35. }
  36. }
  37. [B]My code for the constructor is here:[/B]
  38. import java.io.*;
  39. public class CircleApp {
  40. public static void main(String[] args) {
  41. Circle Circle = new Circle(Circle.radiusInt);
  42. System.out.println("Circumference is " + Circle.getCircumference());
  43. System.out.println("The Area is:" + Circle.getArea());
  44. System.out.println("The Radius is:" + Circle.radiusInt);
  45. int radiusB = 5;
  46. Circle CircleB = new Circle(radiusB);
  47. double circleTotalArea = 3.14* radiusB * radiusB;
  48. double circleTotalCircumference = 2 * 3.14 * radiusB;
  49. System.out.println("Circumference is " + Circle.getCircumference());
  50. System.out.println("The Area is:" + Circle.getArea());
  51. System.out.println("The Radius is:" + Circle.radiusInt);
  52. System.out.println("The Total Area is:" + circleTotalArea);
  53. System.out.println("The Circumference is:" + circleTotalCircumference);
  54. }
  55. }
Last edited by cscgal; Nov 5th, 2008 at 7:32 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,162
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 138
dickersonka dickersonka is offline Offline
Veteran Poster

Re: hey guys, just need a quick tip on something!

 
0
  #2
Nov 5th, 2008
please put code in code tags, and what is the error?
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,515
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 523
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: hey guys, just need a quick tip on something!

 
0
  #3
Nov 5th, 2008
And what is that error? It should indicate the nature of the problem and the line number on which it occurs.

One thing I would point out is the missing parenthesis on this method call Circle.radiusInt
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 9
Reputation: AceAtch is an unknown quantity at this point 
Solved Threads: 0
AceAtch AceAtch is offline Offline
Newbie Poster

Re: hey guys, just need a quick tip on something!

 
0
  #4
Nov 5th, 2008
sorry my bad, its this part here from top of the constructor code

public class CircleApp {

public static void main(String[] args) {


Circle Circle = new Circle (Circle.radiusInt);
Error is: cannot find symbol


System.out.println("Circumference is " + Circle.getCircumference());
System.out.println("The Area is:" + Circle.getArea());
System.out.println("The Radius is:" + Circle.radiusInt);

I've added and edited it so many times just can't seem to get this one right. it needs to take the value of the radius to create a circle and as far as i know this is the method of doing it.
Last edited by AceAtch; Nov 5th, 2008 at 4:17 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,162
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 138
dickersonka dickersonka is offline Offline
Veteran Poster

Re: hey guys, just need a quick tip on something!

 
0
  #5
Nov 5th, 2008
then just as ezzaral stated its the radiusint getter

also i would suggest you to name it as

  1. public int getRadiusInt()

just as your other ones have been named
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,658
Reputation: BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold 
Solved Threads: 206
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: hey guys, just need a quick tip on something!

 
0
  #6
Nov 5th, 2008
What they suggested above isn't your problem (well, it is a problem, but its not your error). Your problem is that you can't name your variable with the class name. Circle Circle is invalid because Circle is the class name. The word after the first Circle should be your variable name, which cannot be the name of a class or a reserved word (such as int). For example, you could use

Circle myCircle = new Circle();


However, you should also consider the fact that your code is confusing. You have a variable named radiusInt and you also have a method named radiusInt(). This won't confuse the compiler, since the compiler knows methods are called with parentheses, but it will confuse people. Method names should be descriptive, for example, a method that returns your radiusInt should be called getRadiusInt, like the guy above me said.
Last edited by BestJewSinceJC; Nov 5th, 2008 at 4:23 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,515
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 523
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: hey guys, just need a quick tip on something!

 
0
  #7
Nov 5th, 2008
Yeah, I didn't even look at that line. The declaration is invalid and even if that is fixed, you can't use a method on that object in it's constructor call - because it doesn't exist yet.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,658
Reputation: BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold 
Solved Threads: 206
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: hey guys, just need a quick tip on something!

 
0
  #8
Nov 5th, 2008
I didn't even notice that, good catch Ezzaral. Also, AceAtch, take a look at the comments I put for your constructor.

  1. public Circle(int x, int y,int r){
  2. r = radiusInt; //This makes r have the value that was in radiusInt
  3. x = radiusInt *2; //this makes x have 2 * the value that was in radiusInt
  4. y= radiusInt * 2; //this makes y have 2 * the value that was in radiusInt
  5.  
  6.  
  7. //You probably meant to do this:
  8. radiusInt = r;
  9.  
  10. //The other code you have doesn't make any sense, since 'Circle' doesn't have any
  11. //variables other than radiusInt
  12.  
  13. }


I don't think you're understanding the basic idea of how things work. I'll write something real quick to try to help you out. Then, you can try to apply the ideas I give you to your own code.
Last edited by BestJewSinceJC; Nov 5th, 2008 at 4:29 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,658
Reputation: BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold 
Solved Threads: 206
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: hey guys, just need a quick tip on something!

 
0
  #9
Nov 5th, 2008
  1. public class Rectangle{
  2. private int height;
  3. private int width;
  4.  
  5. public static void main(String[] args){
  6.  
  7. Rectangle rect = new Rectangle(1, 5);
  8. System.out.println(rect.getWidth()); // prints 5
  9. rect.setWidth(3);
  10. System.out.println(rect.getWidth()); //prints 3
  11.  
  12.  
  13. }
  14.  
  15.  
  16. public int getWidth(){
  17. return width;
  18. }
  19.  
  20. public int getHeight(){
  21. return height;
  22. }
  23.  
  24. public void setWidth(int wdth){
  25. this.width = wdth;
  26. }
  27.  
  28. //Calling this method creates a new Rectangle object,
  29. //which will have its height and width set to the h and w
  30. //you pass in.
  31. public Rectangle(int h, int w){
  32. height = h;
  33. width = w;
  34. }
  35.  
  36. /**Note, this method has the SAME method header as the method below
  37. *and the compiler will NOT let you declare the same method twice.
  38. *However, this method does the exact same thing as the one above.
  39. *The reason? Because when you want to create an object, you
  40. *use a constructor (like this one). Where I have this.height,
  41. *saying 'this' means I am referring to the height variable of
  42. *the object I am creating, NOT the height that got passed in (the one in parens).
  43. */
  44. public Rectangle(int height, int width){
  45. this.height = height;
  46. this.width = width;
  47. }
  48.  
  49.  
  50. }
Last edited by BestJewSinceJC; Nov 5th, 2008 at 4:39 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 9
Reputation: AceAtch is an unknown quantity at this point 
Solved Threads: 0
AceAtch AceAtch is offline Offline
Newbie Poster

Re: hey guys, just need a quick tip on something!

 
0
  #10
Nov 5th, 2008
thanks for the replys! i have changed all of my variables to "myCircle" instead but it still get stuck on that very same line, also i have created a "getradius" public integer. which hasnt helped much.. :/
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum


Views: 1573 | Replies: 29
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC