Home Java Java-tips 45examples 20components InchesToCm A program which converts feet and inches to centimeters.

Ask Questions?

View Latest Questions

Advertisement


 
 

A program which converts feet and inches to centimeters.
Posted on: July 22, 2006 at 12:00 AM
Write a program which converts feet and inches to centimeters.

Java: Exercise - InchesToCm

Write a program which converts feet and inches to centimeters.

In this application we will write code for converting feet and inches into centimeters.

Application will have following components:

  • Text field for entering feet
  • Text field for entering inches
  • and the "=" button
  • Text field to display the converted value in centimeters

When you run the example it will show the Swing GUI where user can perform conversion.

 

Following screen shot shows how the interface will look like.

 

The interface should look like the following.

Assumptions, constraints, etc

  • This is an open-book/notes exercise.
  • The "=" button should cause the conversion to be made.
  • There are 2.54 centimeters per inch.
  • The window close box should terminate the program.
  • If there is an error in converting either of the input numbers, put the message "ERROR" in the output field. Hint: this requires using try...catch.
  • This must be an application, not an applet.
  • You should use double for the numbers.
  • You do not have to format the output in any special way (ie, you can use the default number to string conversion.
Copyleft 2004 Fred Swartz MIT License, Last update: 2004-04-25
Advertisement


DMCA.com