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 3 of 3

Thread: Implementing an example into my code

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Implementing an example into my code

    import javax.swing.JOptionPane;

    public class ReverseNumbers
    {
    private static final int MAX = 10;

    public static void main(String[] args)
    {
    int numbers[] = new int[MAX];
    String input;
    String output;

    for (int i=0; i<numbers.length; i++)
    {
    input = JOptionPane.showInputDialog(null, "Enter integer #"+(i+1)+": ");
    numbers[i] = Integer.parseInt(input);
    }

    output = "The numbers entered in reverse order are:";
    for (int i=numbers.length-1; i>=0; i--)
    output += "\n"+numbers[i];

    JOptionPane.showMessageDialog(null, output);
    }
    }


    ^^^ This is the code to which I need to implement into what I already have... I'm a complete beginner so I do not quite know
    how to do this... Any feedback is appreciated. Below is what I have already..


    //************************************************** ***********************************************
    //* Program calculates BMI for individuals who weigh between 60 to 400 pounds and 48 to 96 inches *
    //* This program will create an array of individuals. *
    //************************************************** ***********************************************

    //
    import javax.swing.JOptionPane;


    // Name the class
    public class BMI4
    {
    public static void main (String[] args)
    {
    // Declare the variables
    String firstName;
    String lastName;
    int weight;
    double height;
    BMICalculator2[] bmiObjects;
    String BMIRating = "Normal";
    String input;
    int numberOfPeople;


    input = JOptionPane.showInputDialog(null, "How many people do you want to calculate BMI?", "Number of People",
    JOptionPane.QUESTION_MESSAGE);
    numberOfPeople = Integer.parseInt(input);
    bmiObjects = new BMICalculator2[numberOfPeople];

    for (int count=0; count<bmiObjects.length; count++)


    {
    // IMPROVE THIS USING Count AS WAS DONE WITH i IN ReverseNumbers.java
    firstName = JOptionPane.showInputDialog(null, "Please enter your first name: ");


    lastName = JOptionPane.showInputDialog(null, "Please enter your last name: ");

    weight = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter your weight in lbs (Weight must be between 60-400lbs): "));

    // Validate correct weight entry
    while (weight < 60 || weight > 400)
    {
    weight = Integer.parseInt(JOptionPane.showInputDialog(null,
    "Weight must be between the range of 60 to 400 lbs. Please enter a valid weight."));
    }

    height = Double.parseDouble(JOptionPane.showInputDialog(nul l,
    "Enter your height in inches (Height must be between the range of 48 to 96 inches. Please enter a valid height."));

    // Validate correct height entry
    while (height < 48 || height > 96)
    {
    height = Double.parseDouble(JOptionPane.showInputDialog(nul l,
    "Height must be between the range of 48 to 96 inches Please enter a valid height."));
    }

    bmiObjects[count] = new BMICalculator2(firstName, lastName, weight, height);
    } // for

    for (int count=0; count<bmiObjects.length; count++)
    {
    // Output information
    JOptionPane.showMessageDialog(null, bmiObjects[count], "BMI Calculation #"+(count+1), JOptionPane.INFORMATION_MESSAGE);
    } // for
    } // main
    } // class


  2. #2
    Member
    Join Date
    Sep 2013
    Posts
    68
    My Mood
    Confused
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: Implementing an example into my code

    Welcome to the forum. Please format your code.

    This is the code to which I need to implement into what I already have
    didn't understand what do you want to do.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Implementing an example into my code

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly per the above link.

    It looks like you're adopting someone else's code as your own, and you'll have difficulty finding someone here to help you with that. If there's something else going on, then you should provide some background.

Similar Threads

  1. implementing KeyListener
    By FARGORE in forum AWT / Java Swing
    Replies: 1
    Last Post: October 18th, 2012, 08:32 AM
  2. Implementing a Driver to following code
    By Twoacross in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 11th, 2011, 11:17 PM
  3. Replies: 5
    Last Post: September 17th, 2011, 09:05 PM
  4. Implementing Semaphores
    By bananasplitkids in forum Threads
    Replies: 1
    Last Post: March 27th, 2010, 04:35 AM
  5. Implementing HTML tags in Java Source Code
    By bookface in forum Java Theory & Questions
    Replies: 4
    Last Post: March 19th, 2010, 09:29 PM