Java Eclipse Heat Index -
i complete beginner , hardly know basics of java (i've been in class 2 weeks). first assignment calculate heat index based on current temperature , current humidity given user, in java using eclipse. have come code, however, no avail. code ask users input temperature , humidity, not print out results. provided uml diagram required use build code way have better understanding of why did did. ultimately, think problem lies somewhere in process of passing values , different methods... there willing take , possibly guide me in right direction?
import java.util.scanner; public class heatindexcalculator1 { private int temperature; private double humidity; private double heatindex; public static void main(string args[]) { //get current temp , humidity user scanner input = new scanner(system.in); system.out.printf("please enter current temperature in degrees fahrenheit: "); int currenttemp = input.nextint(); system.out.printf("\nplease enter current humidity percentage: "); double currenthumidity = input.nextdouble(); } private double calculateheatindex ( int currenttemp, double currenthumidity ) { //setting parameters function int temperature = currenttemp; double humidity = currenthumidity; double answer; final double c1 = -42.379; final double c2 = 2.04901523; final double c3 = 10.14333127; final double c4 = -0.22475541; final double c5 = -.00683783; final double c6 = -5.481717e-2; final double c7 = 1.22874e-3; final double c8 = 8.5282e-4; final double c9 = -1.99e-6; int t = temperature; double r = humidity; double t2 = temperature * temperature; double r2 = humidity * humidity; //function of calculating heat index double answer = c1 + (c2 * t) + (c3 * r) + (c4 * t * r) + (c5 * t2) + (c6 * r2) + (c7 * t2 * r) + (c8 * t * r2) + (c9 * t2 * r2); return answer; } private void printheatindex( int currenttemp, double currenthumidity, double calculatedheatindex) { double calculatedheatindex = answer; //print heat index system.out.println("\nat temperature of" + currenttemp + "and humidity of" + currenthumidity + "percent . . .\n"); system.out.println("\nit feels like:" + calculatedheatindex + "f"); } }
you need change main method per below:
public static void main(string args[]) { //get current temp , humidity user scanner input = new scanner(system.in); system.out.printf("please enter current temperature in degrees fahrenheit: "); int currenttemp = input.nextint(); system.out.printf("\nplease enter current humidity percentage: "); double currenthumidity = input.nextdouble(); //creating object of heatindexcalculator class heatindexcalculator1 heatindex = new heatindexcalculator1(); double x = heatindex.calculateheatindex(..,..); heatindex.printheatindex(currenttemp,currenthumidity,x); }
also, compiler may give error because methods in heatindexcalculator1 class private, if change them public works.
Comments
Post a Comment