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: Two ArrayLists don't cycle thru formula

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

    Default Two ArrayLists don't cycle thru formula

    Hi!
    I want to create a loop
    which takes the top number from each array
    and plugs it in to a formula
    all the way through the arraylist.

    One array has 12 temperatures in F, such as 89.1 and so forth
    The other array has 12 relative humidities.

    I've gotten it down to the loop and the formula, but it doesn't work. I think I am missing something simple.
    The formula is for the so-called Heat Index.

     
    /**
     * Write a description of class HeatIndex here.
     *
     * @author (your name)
     * @version (a version number or a date)
     */
     
    import java.util.ArrayList;
    import java.io.File;
    import java.io.IOException;
    import java.util.Scanner;
    public class HeatIndex{
    public static void main(String [] args) throws IOException
    {
       //  int index = 0;
         double [] KeyWestTemp = new double[12];
         int [] KeyWestHumid = new int[12];
         File KeyWestTempFile = new File("KeyWestTemp.txt");
         File KeyWestHumidFile = new File("KeyWestHumid.txt");
         Scanner inFile1 = new Scanner(KeyWestTempFile);
         Scanner inFile2 = new Scanner(KeyWestHumidFile);
      // Print to file Thing
     
     
          ArrayList<Double> Temp = new ArrayList<>();
          while (inFile1.hasNext()) {
            Temp.add(inFile1.nextDouble());
        }
        System.out.println(Temp);
     
        ArrayList<Integer> Hume = new ArrayList<>();
          while (inFile2.hasNext()) {
            Hume.add(inFile2.nextInt());
        }
        System.out.println(Hume);
     
        for(String number: Hume) //?
        {
         number * heatIndex;  // have to figure out the correct way to multiply things within a loop.
        }
     
     // In the formula below,the values should be drawn, one by one, from the two arrays. and it should give twelve 
    //results, because there are twelve humidity values and twelve temperature values. Any help would be great. 
     
       for 
     
     
       double heatIndex = -42.379 + 2.0490153*"Temp" + 10.14333127*"Hume" - 0.22475541*"Temp"*"Hume"-6.8783*10^3*"Temp"^2 - 5.481717*10^-2*"Hume"^2 + 8.5282*10^-4*"Temp"*"Hume"^2 - 1.99*10^-6*"Temp"^2*"Hume"^2
     
       Temp
     
     //    for(int Gooba : KeyWestTemp)
    //{
    //     System.out.println(Gooba);
    //}
     
     
          //  inFile1.close();   
    }
    }
    Last edited by Norm; January 2nd, 2019 at 06:42 AM. Reason: Fixed code tags

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Two ArrayLists don't cycle thru formula

    it doesn't work
    Please explain.
    Are there error messages? Please copy the full text and paste it here.
    Is the output incorrect? Copy and paste the output here and explain what is wrong with it.

    Fixed the code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Quadratic formula
    By sevengreen7 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 3rd, 2014, 04:34 PM
  2. Mistake in formula?
    By UndersKore in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 9th, 2014, 11:51 AM
  3. [SOLVED] ArrayLists - Getting index of parameters of objects of ArrayLists.
    By mwebb in forum Object Oriented Programming
    Replies: 1
    Last Post: February 16th, 2012, 07:39 PM

Tags for this Thread