Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class Task_2_3 {
- public static void main(String[] args) {
- DecimalFormat df = new DecimalFormat("0.#####");
- Scanner input = new Scanner(System.in);
- Task_2_3 myApp = new Task_2_3();
- boolean exit = false;
- System.out.println("--- Welcome to the conversion center ---");
- do {
- System.out.printf("%n1) Kilograms to pounds%n2) Pounds to kilograms%n3) Meters to feet%n4) Feet to meters%n5) Exit%n%n");
- System.out.println("Please enter your choice");
- int choice = input.nextInt();
- if (choice == 1) {
- System.out.println("Please enter your number in Kilograms");
- double K = input.nextInt();
- double res = myApp.KtoP(K);
- System.out.printf("Your converted number is: ");
- System.out.print(df.format(res));
- System.out.printf(" Pounds");
- try {
- Thread.sleep(2500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- } else if (choice == 2) {
- System.out.println("Please enter your number in Pounds");
- double P = input.nextDouble();
- double res = myApp.PtoK(P);
- System.out.printf("Your converted number is: ");
- System.out.print(df.format(res));
- System.out.printf(" Kilograms");
- try {
- Thread.sleep(2500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- } else if (choice == 3) {
- System.out.println("Please enter your number in Meters");
- double M = input.nextDouble();
- double res = myApp.MtoF(M);
- System.out.printf("Your converted number is: ");
- System.out.print(df.format(res));
- System.out.printf(" Feet");
- try {
- Thread.sleep(2500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- } else if (choice == 4) {
- System.out.println("Please enter your number in Feet");
- double F = input.nextDouble();
- double res = myApp.FtoM(F);
- System.out.printf("Your converted number is: ");
- System.out.print(df.format(res));
- System.out.printf(" Meters");
- try {
- Thread.sleep(2500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- } else if (choice == 5) {
- exit = true;
- System.out.println("Goodbye!");
- } else {
- System.out.println("Error! Wrong input! Please enter a correct option");
- }
- } while (!exit);
- }
- private double MtoF(double a) {
- return a * 3.28084;
- }
- private double FtoM(double a) {
- return a * 0.3048;
- }
- private double KtoP(double a) {
- return a * 2.20462;
- }
- private double PtoK(double a) {
- return a * 0.453592;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement