Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- *
- * @author orice1157
- */
- public class FinalExam_Rice {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- Scanner scan = new Scanner(System.in);
- double kilometers = getValidKM();
- double miles = calculateMiles(kilometers);
- String repeat = "Yes";
- while (repeat.equalsIgnoreCase("YES")) {
- getValidKM();
- calculateMiles(kilometers);
- displayResults(kilometers, miles);
- System.out.print("Enter \"YES\" to convert another number--> ");
- repeat = scan.nextLine();
- }
- }
- public static double getValidKM()
- {
- Scanner scan = new Scanner(System.in);
- double km;
- do {
- System.out.print("Enter a number of Kilometers greater than 0--> ");
- km = scan.nextDouble();
- }while (km < 0);
- return km;
- }
- public static double calculateMiles(double km)
- {
- double m = km * 0.62137119;
- return m;
- }
- public static void displayResults(double km, double m)
- {
- System.out.println(km + " kilometers is equivalent to " + m + " miles.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement