# Converion question by new guy

• January 28th, 2010, 12:44 PM
jeremyt10
Converion question by new guy
Hey I am really new to java all together (few weeks) so bare with me, as my code might not be very good at all lol

anyways I needed to write a pretty simple staircase calculating program getting input from the user on height and length of a staircase, and then getting output on the rise and run and # of steps etc.

The final part of the program is where I am having trouble. I need to take a value which was converted from mm to inch and then convert that value into feet inch and 32nd of an inch. I think I am part way there although it seems like I am approaching it wrong in the way I am righting my code. Either way here is my code and the conversion I am trying should be highlighted below.

I should be getting 0 feet 2-26/32 inches and 1 feet 1-4/32 inches, WITH user input of 2000mm length and 500mm height I am getting or have gotten up to 0 feet 2/32inches and 1 feet 1/32 inches.

Thanks a lot for any help.

Code :

```//******************************************************************** import javax.swing.* ; import java.util.Date ;   /************************************************************_* Q3 Staircase Calculator * Purpose: To create a stair case calculator based on height * and length of available space.   * @author JT * @version 2010-Jan-27 ************************************************************_*/   public class ****{   /**...............................................................main * Required method. */   public static void main(String[] args) { final String length ; // length in mm final String height ; // height in mm     final double HEIGHTIN ; // Height in inches final double LENGTHIN ; // Length in inches   final int INISTEPS ; // initial estimated # of steps final double INIRISE ; // intial rise est.   final int FINALSTEPS ; // final # of steps final double FINALRISE ; // final rise final double FINALRUN ; // final run   final int RISECONVERSION1 ; // / 12 final int RISECONVERSION2 ; // % 12 final int RISECONVERSION3 ; // 32nds of an inch     final int RUNCONVERSION1 ; // / 12 final int RUNCONVERSION2 ; // %12 final int RUNCONVERSION3 ; // 32nds of an inch           /* Main Body */   /* Sec.1 : user inputs length and height and is shown the length and height back in inches. */   length = JOptionPane.showInputDialog(null, " Lets Design a Stair case...\n" + "Please enter the Length of Space available for the Staircase (in mm)") ;   LENGTHIN = Integer.parseInt(length) / 25.4 ;       height = (JOptionPane.showInputDialog(null," Next...\n" + "Please enter the Height the staircase has to cover (in mm)")) ;   HEIGHTIN = Double.parseDouble(height) / 25.4 ;       JOptionPane.showMessageDialog(null," Length = " + (length) + " mm \n" + "height = " + (height) + " mm \n" + "**Conversion**\n" + "Length in Inches = " + (LENGTHIN) + " inches\n" + "Height in Inches = " + (HEIGHTIN) + " inches") ;     /* Sec.2 : Following the conversion output above, the user is given output for their length and height, * the estimated # of steps, the initial rise estimate , final # of steps and then the final rise and run estimate     INISTEPS = (int)Math.floor(((LENGTHIN) + (HEIGHTIN)) / 17 ) * 100. /100. ;*/   INISTEPS = (int)Math.floor(((LENGTHIN) + (HEIGHTIN)) / 17 ) * 100 /100 ; INIRISE = (HEIGHTIN) / (INISTEPS + 1) ;   FINALSTEPS = (int)Math.round(((LENGTHIN) + (HEIGHTIN) - (INIRISE)) / 17 ) * 100 /100 ; FINALRISE = ((HEIGHTIN) / ((FINALSTEPS + 1. ))); FINALRUN = (LENGTHIN) / (FINALSTEPS) ; [B] RISECONVERSION1 = (int)((FINALRISE)/ 12) ; RISECONVERSION2 = (int)((FINALRISE) - (FINALRISE)% 12) ; RISECONVERSION3 = (int)(RISECONVERSION2) * 32 * 100 / 100 ;   RUNCONVERSION1 = (int)Math.floor((FINALRUN) / 12) ; RUNCONVERSION2 = (int)Math.floor((FINALRUN) % 12) ; RUNCONVERSION3 = ((int)((FINALRUN) - (RUNCONVERSION1)) * 32) *100 / 100 ;[/B]         JOptionPane.showMessageDialog(null,"Input Length: " + (length) + " mm \n" + "Input Height:" + (height) + "mm \n" + "Estimated number of steps: " + (INISTEPS) + "\n" + "Initial rise estimate: " + (INIRISE) + " inches \n" + "Final number of steps: " + (FINALSTEPS) + "\n" + "Final rise estimate: \t\t" + (RISECONVERSION1) + " feet " + (RISECONVERSION3) + "/32 inches \n" + "Final run estimate: \t\t" + (RUNCONVERSION1) + " feet " + (RUNCONVERSION2) + "/32 inches \n") ;     System.out.println("Input Length: \t\t\t" + (length) + " mm \n" + "Input Height: \t\t\t" + (height) + " mm \n" + "Estimated number of steps: \t" + (INISTEPS) + "\n" + "Initial rise estimate: \t\t" + (INIRISE) + " inches \n" + "Final number of steps: \t\t" + (FINALSTEPS) + "\n" + "Final rise estimate: \t\t" + (RISECONVERSION1) + " feet " + (RISECONVERSION3) + "/32 inches \n" + "Final run estimate: \t\t" + (RUNCONVERSION1) + " feet " + ((RUNCONVERSION2) + "/32 inches \n")) ;   /* For final rise and run est. Output: Convert the final rise and run values from inches (e.g., 14.623 inches) to feet, inches, and 32nds of an inch. To calculate feet and inches, take the integer part of the number of inches (the integer part of 14.623 inches is 14) and divide by 12, because there are 12 inches in a foot. The result of the division is the number of feet, and the remainder is the number of inches. So 14.623 inches is 1 foot 2 inches with 0.623 inches left over. To convert 0.623 inches to 32nds of an inch, multiply it by 32, and round to the nearest integer: 32×0.623=19.936, which rounds up to 20-32nds of an inch. Display the final output on System.out, but also show it to the user with */     /** Final Output **/   System.out.println("\n ******************* \n" + "Programmed by JT") ; System.out.println("Run " + new Date() ) ; System.out.println("*_* END OF PROGRAM *_^ \n" + " *******************") ; } //End of Main } // End of Class```
• January 29th, 2010, 12:41 AM
jeremyt10
Re: Converion question by new guy
I think i pretty much got it figured out.

Thanks
&
until next time
JT