Results 1 to 3 of 3

Thread: I need help...

  1. #1
    Join Date
    Apr 2009
    Posts
    3
    Rep Power
    0

    Question I need help...

    I'm new to java programming and I'm stuck on an assignment for my class...
    I've been working on this project for a while now and I'm getting kind of sick of it...I really need to turn it in though as soon as possible so can anyone help?
    I'm not sure if I can apply a boolean expression to a for-each loop in this program:

    public class HeatIndex
    {
    public static void main(String[] args)
    {
    String [] months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Annual"};
    double [] temp = {53.2, 56.7, 63.7, 69.7, 76.6, 81.8, 84.2, 84.2, 80.1, 72.3, 62.7, 55.2, 70.0};
    int [] humi = {70, 68, 66, 67, 69, 68, 65, 65, 67, 65, 67, 69, 68};
    double [] formula = new double[13];

    double t = 90;
    int r = 60;
    double pow1 = Math.pow(10, -2);
    double pow2 = Math.pow(10, -3);
    double pow3 = Math.pow(10, -4);
    double pow4 = Math.pow(10, -6);

    for(int x = 0; x < 13; x ++)
    {
    formula[x] = -42.379 + (2.04901523 * temp[x]) + (10.14333127 * humi[x]) - (0.22475541 * (temp[x] * humi[x])) - ((6.83783 * pow2) * (temp[x] * temp[x])) - ((5.481717 * pow1) * (humi[x] * humi[x])) + ((1.22874 * pow2) * ((temp[x] * temp[x]) * humi[x])) + ((8.5282 * pow3) * (temp[x] * (humi[x] * humi[x]))) - ((1.99 * pow4) * ((temp[x] * temp[x]) * (humi[x] * humi[x])));
    }

    String title1 = "What's the Heat Index For...";
    String title2 = "Victoria, Texas";
    String jd = "Months";

    System.out.printf("%88s%n", title1);
    System.out.println();
    System.out.printf("%81S%n", title2);
    System.out.println();
    System.out.println();
    System.out.printf("%76s%n", jd);
    System.out.println();

    for(String mon : months)
    {
    System.out.printf("%10S", mon);
    }
    System.out.println();
    System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>");
    System.out.println();

    for(double ture : temp)
    {
    System.out.printf("%10.1f", ture);
    }
    System.out.println();
    System.out.println();

    for(int h : humi)
    {
    System.out.printf("%10d", h);
    }
    System.out.println();
    System.out.println();

    for(double hi : formula)
    {
    System.out.printf("%10.1f", hi);
    }

    }
    }

    I'm trying to get the formula to print only when the tempurature is 80 degress or higher and when the humidity is 60 percent or higher...so is it doable??? Help if you can pleez!!:D

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    why not just use an if statement inside your loop?

    if( (t >= 80) && (h >=60)){
    print out your stuff
    }
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  3. #3
    Join Date
    Apr 2009
    Posts
    3
    Rep Power
    0

    Default

    Well, I tried that already...it refused to print when I did it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •