import java.util.Scanner;
import javax.swing.JOptionPane;
public class SpeedCalculatorVelocityCalculator {
public static void main(String[] args) {
…
You're not starting any decision making here… you're just gathering input.
Technically, you're dealing with speed, not velocity. Velocity comprises a speed and a direction.
import java.util.Scanner;
public class SpeedCalculatorVelocityCalculator {
private static int askInt(Scanner scanner, String prompt) {
System.out.print(prompt);
return scanner.nextInt();
}
private static double askDouble(Scanner scanner, String prompt) {
System.out.print(prompt);
return scanner.nextDouble();
}
public static void main(String args[]) {
System.out.println("What are you trying to calculate?");
Scanner input = new Scanner(System.in);
int menuChoice = askInt(input,
"Press:\n" +
"3 for speedvelocity (m/s)\n" +
"2 for distance (m)\n" +
"1 for time (s):\n");
System.out.println();
double dist, speed, time;
switch (menuChoice) {
case 1: // Solving for time
speedvelocity = askDouble(input, "Please enter the speedvelocity in m/s: ");
dist = askDouble(input, "Please enter the distance in m: ");
time = dist / speed;velocity;
System.out.printf("Time equals %s seconds.\n", time);
break;
case 2: // Solving for distance
speedvelocity = askDouble(input, "Please enter the speedvelocity in m/s: ");
time = askDouble(input, "Please enter the time in s: ");
dist = speedvelocity * time;
System.out.printf("Distance equals %s meters.\n", dist);
break;
case 3: // Solving for speedvelocity
time = askDouble(input, "Please enter the time in s: ");
dist = askDouble(input, "Please enter the distance in m: ");
speedvelocity = dist / time;
System.out.printf("Speed equals %s m/s.\n", speedvelocity);
break;
default:
System.out.println("Please enter something I, a computer, can understand.");
}
}
}