• Post Reply Bookmark Topic Watch Topic
  • New Topic

Circle Tutorial Question  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot figure out how to set up the main for my application to pass the radius input from a user into my circle class. I am using a ConsolValidator script to stop any bad input and need a 2nd class file to send me back data about the circle's radius. Any help would be appreciated.



 
Greenhorn
Posts: 18
Android Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Well you can can create a method which gets input through System.Console() to pass values And then apply ConsoleValidator to check for if it is bad input or not.
 
Nicholas Decrescenzo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thanks for the reply. I thought that's what I was doing here:

double getRadius = ConsoleValidator.getDouble("Enter radius: ");

The variable getRadius is where I'm getting stuck. Just need a small push to begin understanding the proper way about sending the data to the class file.

 
Greenhorn
Posts: 16
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi nickyt,

There is a method in your Circle class that sets the radius and accepts a double as its argument. You could pass the radius entered by the user (that you have stored in a variable called getRadius) into this method of the Circle class.

Jon
 
Nicholas Decrescenzo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Greenhorn! I tried this but Netbeans gives me an error warning:

double c.getRadius = ConsoleValidator.getDouble("Enter radius: ");

How do you mean?
 
Sheriff
Posts: 11495
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nicholas Decrescenzo wrote:I tried this but Netbeans gives me an error warning:

double c.getRadius = ConsoleValidator.getDouble("Enter radius: ");


getRadius in the Circle class is a method. You can't assign a value to a method. You can only invoke/call methods.

Your Circle class has a setRadius method. Do you know what that does?
 
Nicholas Decrescenzo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing the getRadius method doesn't do anything yet. I put that unfinished method there.
 
Junilu Lacar
Sheriff
Posts: 11495
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:Your Circle class has a setRadius method. Do you know what that does?


Nicholas, please read my question again very carefully. Pay attention to the method name that I mentioned. Both the getRadius and setRadius methods you showed are complete. Nothing more to add to them as far as what you are trying to do is concerned. If you don't think they're complete yet, it makes me wonder how you came up with this code... did you write it or was it provided to you?
 
Nicholas Decrescenzo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote the code from the examples I received. This is our first lab getting and setting as well as using object / class scenario. I stated that the get radius method probably doesn't do anything because I'm still ignorant what these get & sets do. I'm eager to learn but still a beginner. I typed out the first 15 lines and then used the Netbeans insert code 'get & set' tool.

Now the getArea & getCIrcumference methods I updated and didn't add or change the getRadius method is why I replied that way. Since my getRadius method is okay, I'll try and invoke it but still unsure why I have setArea. After this lab I assume to understand.
 
Junilu Lacar
Sheriff
Posts: 11495
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, Nicholas, let me put it this way: The getArea method uses two values to calculate the area: Math.PI and radius. Math.PI is a constant value. So the only other value left that can change that will affect the calculation for the area of a circle is radius. Are you tracking so far?

Can you find the specific line in your code where the variable radius is getting assigned a value? When and how is this line executed? When you can answer these questions, then you should be able to figure out how to get your code to calculate the area of any Circle with a given radius.

If you still can't answer these questions, then your problem is a lack of understanding of Java language basics. Go to the Java Tutorials and read up on the basics of classes, getters, setters, and working with variables.

(Note: Technically, there are two lines in your code where the variable radius gets assigned a value. There is only one line where a value is explicitly assigned. Find that line and you will find the answer)
 
Ashwin Soni
Greenhorn
Posts: 18
Android Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Nicholas Decrescenzo
Your both classes Circle and CalculateCircle are seems to be perfect but according to me there may problem in ConsoleValidator as it is not passing value quite well to the main class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!