Bicyclists can calculate their speed if the gear size and cadence is known. Gear size refers to the effective diameter of the wheel. Gear size multiplied by pi (3.14) gives the distance travelled with one turn of the pedals. Cadence refers to the number of pedal revolutions per minute (rpm). The speed in miles per hour is calculated by the following:
This is a program that calculates the speed for a gear size of 100 inches and a cadence of 90 rpm. This would be considered a high cadence and a maximum gear size for a typical bicycle. In writing your program, don’t forget that the expression 1/12 will result in 0, because both 1 and 12 are integers, and when the integer division is performed, the fractional part is discarded.
Program:
// BicyclistSpeed
public class BicyclistSpeed
{
public static double PI = 3.14;
public static void main(String[] args)
{
double gearSizeInInches = 100.0;
double cadenceInRPM = 90.0;
double speedInMPH = gearSizeInInches * PI * (1.0 / 12.0)
* (1.0 / 5280.0) * cadenceInRPM * (60.0 / 1.0);
System.out.println("Gear size in inches : " + gearSizeInInches);
System.out.println("Cadence in RPM : " + cadenceInRPM);
System.out.println("Bicyclist speed in MPH: " + speedInMPH);
}
}
Output:
Gear size in inches : 100.0
Cadence in RPM : 90.0
Bicyclist speed in MPH: 26.761363636363633
answer of question 6 in 6th edition of this book!
import java.util.Scanner;
import java.lang.Math;
public class Review1 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter your principal amount of yout money: ");
double p = keyboard.nextDouble();
System.out.println("Enter the initial interest rate in decimal form: ");
double r = keyboard.nextDouble();
System.out.println("Enter the number of years: ");
int t = keyboard.nextInt();
System.out.println("Enter the number of times interest is compounded per unit 't': ");
/* If interest is compounded yearly,then n = 1;
* if semi-annually, then n = 2;
* quarterly, then n = 4; monthly, then n = 12;
* weekly, then n = 52; daily, then n = 365;
* and so forth, regardless of the number of years involved.
*/
int n = keyboard.nextInt();
double simpleInterst = (p*r*t);
double compoundInterest = (p*(Math.pow((1+r/n), n*t))) - p;
System.out.println("the simple interest is: " + simpleInterst + "\n");
System.out.println("the compund interest is: " + compoundInterest);
keyboard.close();
}
}
Post the discussion to improve the above solution.