Owen Soenso
Owen Soenso

Reputation: 19

Portion of code not running

Part of my java code is not running. I am fairly new to java and have been working out some new environment changes. My class was told to build a windchill temperature calculator. My main issue is that my code works up to the for (ws = wsp; ws <= c; ws += 0.5) then stops.

import java.util.*;
class Assign1
{
   public static void main(String args[])
{
  Menu user = new Menu();
  Menu.mainmenu();
  user.acceptSelection();
}
}
class Menu
{
  public static void mainmenu()
{
  System.out.println("Temperature Analysis MENU");
  System.out.println("1.W)ind Chill Temperature");
  System.out.println("0.E)xit");
  System.out.println("Enter Selection:");
}  
public void acceptSelection()
{
  Scanner stdin = new Scanner(System.in);
  String selection = stdin.nextLine();
  char choice = selection.charAt(0);

  switch(choice)
  {
     case 'W':
     case 'w':
     case '1':
              processing.process(); break;
     case 'E':
     case 'e':
     case '0':
              System.out.println("E"); break;
  }  
}
}
class processing
{
 public static void process()
{
  Scanner stdin = new Scanner(System.in);
  System.out.println("\n\n\n\n\n\n\n");
  System.out.print("Please enter START air temp in celsius (decimal) MUST be BELOW 9: ");
  double sa = stdin.nextDouble();
  System.out.print("Please enter END air temp in celsius (decimal) MUST be BELOW 9: ");
  double ea = stdin.nextDouble();
  System.out.print("Please enter wind speed (decimal) FROM 8km/h to: ");
  double w = stdin.nextDouble();
  System.out.println("\n==================================================================\n");
  calculation(sa, ea, w);

}
public static void calculation(double a, double b, double c)
{
  double wsp = 8.0;
  double airTemp;
  double ws;
  int size = 150;
  double[] wChill = new double[size];
  int count = 0;
     System.out.print("    " + a);
     while(a <= b)
     {
        System.out.print("    " + a);
        a +=5;
        count++;
     }
     System.out.print("    " + b);
  int count2 = 0;
     while(wsp <= c)
     {
        count2++;
        wsp += 0.5;
     }   
  double[][] chart = new double[count2][count];   
  int i = 0, j = 0, k = 0;

This is where it stops working. I cannot get it to print my loop out. Any help in fixing my problem would be appreciated as well as notes to my code as i am trying to improve. I am using JGrasp if it helps.

       for (ws = wsp; ws <= c; ws += 0.5)
     {
     System.out.println(ws + "   ");
     for (airTemp = a; airTemp <= b; airTemp += 5.0)
     {
        if ((ws + 0.5) > c)
       {
        System.out.printf( "%2d    %2d", c , chart[k][i]);
       }
       else
       {
        wChill[i] = (13.12 + (0.6215*airTemp)+(-11.37*Math.pow(ws, 0.16))+(0.3965*airTemp*Math.pow(ws, 0.16)));
        chart[k][i] = wChill[i];
        System.out.print(chart[k][i] + "   ");
       }
       i++;
     }
     k++;
  }


}


}

Upvotes: 0

Views: 70

Answers (1)

Scary Wombat
Scary Wombat

Reputation: 44854

According to you code you have a while loop

while(wsp <= c) {...}

then you have a for loop

for (ws = wsp; ws <= c; ws += 0.5)

so as you can see ws is assigned the value of wsp which has in the while already exceeded the value of c

Upvotes: 1

Related Questions