Question
The problem concerns the "effective radius" of a bicycle gear. The required formula i
explained below. i need to Write a program to read:

``````the wheel radius (use a "double" as variable type);
the number of teeth on the front sprocket (a "long");
the number of teeth on the rear sprocket (a "long");
``````

.....and compute and print the so called ‘effective radius’.

Method
The effective radius of a bicycle gear is calculated from the radius of the wheel, and the number of teeth on the front and rear chain sprockets, as follows:

``````Effective radius = radius * teeth on the front sprocket / teeth on the rear sprocket.
``````

We suggest that you read the three items of input data, calculate the result and store in a "double" variable, and then print it. You have five (5) submissions.

Typical Input
27.5 30 15

Typical Output
The effective radius for radius 2E.5 and sprockets 30 and 15 is 55.0

``````// Find effective radius
public class BicycleGears {

public static void main(String[] argv) {

long frontsprocket;
long rearsprocket;

effectiveRadius = wheelradius * frontsprocke / rearsprocket ;  // ( Is that right ? )
Blue J giving me error

System.out.println("front sprocket");
System.out.println("rear sprocket");
System.out.println("nThe effective radius for radius : " + Effective radius +"and sprockets " + frontsprocket );  // print

} // end of main

} // end class
``````

Last time been advised used books i did. now i am stuck nothing online to reff to that example :(

Edited by pritaeas: Fixed formatting

3
Contributors
7
Replies
9
Views
9 Years
Discussion Span
Last Post by BestJewSinceJC
``effectiveRadius = wheelradius * frontsprocke / rearsprocket ; // ( Is that right ? )``

Yes, that looks right except for the typo. You are getting an error (in addition to the typo) because you are using variables that aren't initialized yet. Read in the values, THEN calculate using the formula.

``````public class BicycleGears {

public static void main(String[] argv)

{
int frontSprocket=0;
int rearSprocket=0;
float ratio=0.00f;

//produce an error message and end program
{
System.out.println("Error, invalid value");
System.exit(0);
}
//produce an error message and end program

if(frontSprocket <= 0)
{
System.out.println("Error, invalid value");
System.exit(0);
}
//produce an error message and end program
if (rearSprocket <= 0)
{
System.out.println("Error, invalid value");
System.exit(0);
}

+ frontSprocket + " and " + rearSprocket + " is " + eftRadius1 );
//calculate and print ratio
} // end of main

} // end class
``````

Edited by pritaeas: Fixed formatting

Post the error message.

``wheelRadius = UserInput.readDouble(); (Now getting error here )``

What is UserInput? I don't see it in the Java SE documentation. Is it a class provided by Sun? Is it a class you wrote? NetBeans doesn't recognize it as a class. If it's a class variable in a class that you wrote and it isn't static, keep in mind that you are in main, which is a static function and so you can't use your non-static class variables.

Whoops! I didn't see THIS thread before responding to this thread. It's amazing that you would ask for help AFTER posting that.

I fix it working fine :)

``````*/

public static void main(String[] argv) {

int frontSprockets=0;
int rearSprockets=0;