Tuesday, September 30, 2014

This program is Meter to Inches and Meter to Feet Converter , first, user must choose which converter they want. After that, user will be ask to enter the distance (in meter) that they want to convert to Inches or Feet. to stop this program user must enter 3.

Sample output:



Sample Source Code:

import java.util.Scanner;

 public class converter
  {
   public static void main(String[] args)
   {


    Scanner input = new Scanner(System.in);

    display_menu(); //call method to display menu

    System.out.print("\nEnter your choice:");
    int choice = input.nextInt();


    while(choice!=3)
    {
     if(choice>3||choice<1)
     {
      System.out.println("u enter invalid number");
     }
     else
     {

      System.out.print("Enter the distance in meters:");
     double meter = input.nextDouble(); //input from user for meters

     switch(choice)
      {
       case 1 : double answer = showInches(meter);  //call method to show inches
         System.out.println(+ meter+" meters is " +answer+ " inches"); //display answer
         break;

       case 2 : double answers = showFeet(meter);  //call method to show feet
         System.out.println(+meter+" meters is "+answers+" feet"); //display answer
         break;
      }
     }

     display_menu();   //call method to display menu

     System.out.print("\nEnter your choice:");
     choice = input.nextInt();  //Enter choice again

    }




    System.out.println("Thank you!");


   }

   public static double showInches(double meter)
   {
    double inches= meter * 39.37;

    return (inches); //formula to get inches
   }

   public static double showFeet(double meter)
   {
    double feet =meter * 3.281;
    return (feet); //formula to get feet
   }
   public static void display_menu()
   {
    System.out.println("\nConversion Program");
    System.out.println("1. Convert to inches");
    System.out.println("2. Convert to feet");
    System.out.println("3. Exit");
   }


}

Tagged:

0 comments:

Post a Comment

Zul Ameen Blog © 2013 | Powered by Blogger | Blogger Template by DesignCart.org