In this tutorial, I will show you how to create a menu-driven program to convert feet to the inch and vice versa using Java programming language. I hope you will like my program.
My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
Program Listing
/**
* @author Jake Rodriguez Pomperada,MAED-IT, MIT
* www.jakerpomperada.com www.jakerpompomperada.blogspot.com
* jakerpomperada@gmail.com
* Bacolod City, Negros Occidental Philippines
*
*/
import java.util.Scanner;
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class Feet_Inch {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.CEILING);
System.out.println();
System.out.println("===== Feet To Inch Conversion in Java =====");
System.out.println();
System.out.println("[1] Feet to Inch Conversion");
System.out.println("[2] Inch To Feet Conversion");
System.out.println();
System.out.print("Selection your option : ");
int ch= scan.nextInt();
if (ch==1)
{
System.out.println();
System.out.print("Give Feet Value : ");
double feet = scan.nextDouble();
double inch = feet*12;
System.out.println();
System.out.println("The feet(s) equivalues is "+df.format(inch));
}
else if (ch==2)
{
System.out.println();
System.out.print("Give Inch Value : ");
double inch = scan.nextDouble();
double feet= inch/12;
System.out.println();
System.out.println("The feet(s) equivalues is "+df.format(feet));
}
else
{
System.out.println("Invalid Option. Please Try Again.");
}
System.out.println();
System.out.println("===== END OF PROGRAM =====");
System.out.println();
}
}
No comments:
Post a Comment