Click here to Skip to main content
15,741,407 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello, i need a bit of assistance on a problem statement.
•Create a class A with the main method
•Create class b in the same work space
•In class B, create a static method that doesn’t return any value called ay that has thee double arguments i.e. Pi, radius and height. The method should print out the volume of a cylinder (Pi*R^2*H)
•In class A access the pi variable in class B and set it equal to 3.142
•Still in class A write a set of statements that will allow the user to input a value and set it equal to the variable radius. Repeat the same set of statements and set the new inputted value to the variable height in class B.
•Call the method ay in the main method.

Let me show you till where i reached:
i need to know how to access variable Pi in class A and set it to 3.142. That is the challenge i am having

What I have tried:

package six;

class A {
	public static void main(String[] args) {
		// TODO Auto-generated method stub

 class B{
	public static void ay (double Pi, double Radius, double Height){
Updated 17-Jun-18 21:45pm
[no name] 17-Jun-18 12:49pm    
Not that this help, but it is crazy to read about it: Pi - Wikipedia[^] Most probably I would never have read this without your question:laugh:
CPallini 18-Jun-18 2:56am    
As per your requirements, class B has no pi member. That is: are you sure you reported the requirements correctly?

need to know how to access variable Pi in class A and set it to 3.142

B.ay(3.142, 10.0, 10.0);
Share this answer
Member 13865935 17-Jun-18 10:59am    
yes but i still get an error saying ay cannot be resolved or is not a field. also who is the values of radius and height to 10.0 because they do require user to enter value. and in the second last bullet on my question says to repeat in class B.. kindly help me out understand that. I will be greatful!
You need to write the remainder of class A first. Use a Scanner to get user input, and save the variable values. Create a variable in class B called Pi that can be accessed from outside. You can get more ideas from Trail: Learning the Java Language (The Java™ Tutorials)[^].
Share this answer
Your main function will be something like below
public static void main(String[] args) {
	loop(more to process) {
		read radius
		read height
                call B.ay(pi, radius, height);
		do you want to process more?

That's going to be your algorithm
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900