If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > Java BicycleGears While looping

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-20-09, 18:56
new-to-java new-to-java is offline
Registered User
 
Join Date: Jan 2009
Posts: 1
Java BicycleGears While looping

Write a program to read the bicycle wheel radius (a "double") the number of teeth on the front sprocket (an "int") and then to read repeatedly the number of teeth on a rear sprocket (an "int") and compute and print the effective radius until a value of zero is encountered.
At every calculation except the first, print the ratio of the newly computed effective radius to the previous effective radius.
MY problem is how i can use while loop in it to make it zero. well i m going to try different way to use while loop inside to get value zero and then get ratio to work. any help would be usefull.I m learning...as well so i will try just need guide line if its possible.

Thanks all for reading


public class BicycleGears {

public static void main(String[] argv)

{
double wheelRadius=0.0f;
float eftRadius=0.0f;
int frontSprocket=0;
int rearSprocket=0;
float pRadius=-0.0f;
double eftRadius1;
float ratio=0.00f;


//Prompt and read the number;
System.out.println ("Please enter the wheelRadius");
wheelRadius = UserInput.readDouble();
//produce an error message and end program
if(wheelRadius <= 0)
{
System.out.println("Error, invalid value");
System.exit(0);
}
//Prompt and read the number;
System.out.println("Please enter the frontSprocket");
frontSprocket = UserInput.readInt();
//produce an error message and end program

if(frontSprocket <= 0)
{
System.out.println("Error, invalid value");
System.exit(0);
}
//Prompt and read the number
System.out.println("Please enter the rearSprocket");
rearSprocket = UserInput.readInt();
//produce an error message and end program
if (rearSprocket <= 0)
{
System.out.println("Error, invalid value");
System.exit(0);
}


// calculation for radius
eftRadius1 = (wheelRadius*frontSprocket)/rearSprocket;

//print radius

----------------------------------error-----------------------------
do {
System.out.println("The effective radius for radius" + wheelRadius + "and sprockets" + frontSprocket + " and " + rearSprocket + " is " + eftRadius1 );

} while (eftRadius1 > 0);
System.out.println("The effective radius for radius" + wheelRadius + "and sprockets" + frontSprocket + " and " + rearSprocket + " is " + eftRadius1 );
eftRadius1--;
--------------------------error-----------------------------------------
its work fine & run up to zero value But its start my calculation from E.g ( The effective radius for radius 27.5 and sprockets 55 and 23 is 65.77 Right ) But its give me result from here
The effective radius for radius 27.5 and sprockets 55 and 23 is 42.77 ( Wrong )


//calculate and print ratio
ratio = eftRadius/pRadius;
System.out.println("ratio to previous " + ratio );
} // end of main

} // end class
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On