Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Converion question by new guy

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

    //********************************************************************
    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: 320.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
    Last edited by helloworld922; January 28th, 2010 at 08:13 PM. Reason: Please use [code] tags!


  2. #2
    Junior Member
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Converion question by new guy

    I think i pretty much got it figured out.

    Thanks
    &
    until next time
    JT