4 Replies - 397 Views - Last Post: 01 February 2013 - 11:26 AM Rate Topic: -----

#1 matt.d1848  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-January 13

how to get my program to run

Posted 30 January 2013 - 08:41 PM

Can someone explain to me how to get this to run?

import java.util.Scanner; 

public class HeatIndexCalculator {
	    int currentTemp;
	    double currenHumidity;
	  	double heatIndex;
	    double calculatedHeatIndex;
		double c1 =     -42.379;
		double c2 =  2.04901523;
		double c3 = 10.14333127;
		double c4 =  -.22475541;
		double c5 =  -.00683783;
		double c6 =  -.05481717;
		double c7 =   .00122874;
		double c8 =  -.00085282;
		double c9 =  -.00000199;
		
		public double calculateHeatIndex(int currentTemp, double currentHumidity){
			double one;
			double two;
			double three;
			double four;
			one = c1+c2*currentTemp+c3*currentHumidity;
			two = c4*currentTemp*currentHumidity+c5*(currentTemp*currentTemp);
			three= c6*(currentHumidity*currentHumidity )+c7*(currentTemp*currentTemp)*currentHumidity;
			four = c8*currentTemp*(currentHumidity*currentHumidity)+c9*(currentTemp*currentTemp)*(currentHumidity*currentHumidity);
			heatIndex=+one+two+three+four;
			return heatIndex;
			
		}
		
		public void printHeatindex(int currentTemp, double currentHumidity,double calculatedHeatIndex){
			Scanner input = new Scanner (System.in);
			System.out.print("Please enter the current temperature in degrees fahrenheit");
			currentTemp=input.nextInt();
			System.out.println("please enter the current humidity as a percentage");
			currentHumidity=input.nextDouble();
		
			calculatedHeatIndex = calculateHeatIndex(currentTemp,currentHumidity);
			System.out.printf("At a temperature of %iF and a humidity of %d percent\n",currentTemp,currentHumidity);
			System.out.printf("It actually feels like:%dF",calculatedHeatIndex);
		
		input.close();
		}
		public void main(String[] arg, double currentHumidity, int currentTemp,double calculatedHeatIndex){
			calculateHeatIndex(currentTemp, currentHumidity);
			printHeatindex( currentTemp, currentHumidity,calculatedHeatIndex);
		}
		}
		


Is This A Good Question/Topic? 0
  • +

Replies To: how to get my program to run

#2 matt.d1848  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-January 13

Re: how to get my program to run

Posted 30 January 2013 - 09:50 PM

so i'm getting this to run but it says i still have errors


import java.util.Scanner; 

public class HeatIndexCalculator {
	   public int currentTemp;
	    public double currenHumidity;
	  	double heatIndex;
	    double calculatedHeatIndex;
		double c1 =     -42.379;
		double c2 =  2.04901523;
		double c3 = 10.14333127;
		double c4 =  -.22475541;
		double c5 =  -.00683783;
		double c6 =  -.05481717;
		double c7 =   .00122874;
		double c8 =  -.00085282;
		double c9 =  -.00000199;
		
		public double calculateHeatIndex(int currentTemp, double currentHumidity){
			double one;
			double two;
			double three;
			double four;
			one = c1+c2*currentTemp+c3*currentHumidity;
			two = c4*currentTemp*currentHumidity+c5*(currentTemp*currentTemp);
			three= c6*(currentHumidity*currentHumidity )+c7*(currentTemp*currentTemp)*currentHumidity;
			four = c8*currentTemp*(currentHumidity*currentHumidity)+c9*(currentTemp*currentTemp)*(currentHumidity*currentHumidity);
			heatIndex=one+two+three+four;
			return heatIndex;
			
		}
		
		public void printHeatIndex(int currentTemp, double currentHumidity){
			
		
			
			System.out.printf("At a temperature of %i F and a humidity of %i percent\n",currentTemp,currentHumidity);
			System.out.printf("It actually feels like:%i F", calculateHeatIndex(currentTemp,currentHumidity));
		
		
		}
		
		public static void main(String[] arg){
			Scanner input = new Scanner (System.in);
			int a;
			double b;
			System.out.println("Please enter the current temperature in degrees fahrenheit");
			a=input.nextInt();
			System.out.println("please enter the current humidity as a percentage");
			b=input.nextDouble();
			input.close();
			HeatIndexCalculator test1 = new HeatIndexCalculator();
			test1.calculateHeatIndex(a, B)/>;
	        test1.printHeatIndex(a, B)/>;
		
			
		}
		
}
		
		

Was This Post Helpful? 0
  • +
  • -

#3 farrell2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 851
  • View blog
  • Posts: 2,605
  • Joined: 29-July 11

Re: how to get my program to run

Posted 30 January 2013 - 09:56 PM

So, what are the errors?
Was This Post Helpful? 0
  • +
  • -

#4 matt.d1848  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-January 13

Re: how to get my program to run

Posted 01 February 2013 - 09:38 AM

when i put in the numbers it crashes right after when it gets to the two methods i wrote.
Was This Post Helpful? 0
  • +
  • -

#5 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2204
  • View blog
  • Posts: 5,236
  • Joined: 10-September 10

Re: how to get my program to run

Posted 01 February 2013 - 11:26 AM

Please answer the questions asked with as much detail as possible. In this case, the answer,

I'm getting the following errors:
java.util.UnknownFormatConversionException: Conversion = 'i'
	at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
	at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
	at java.util.Formatter.parse(Unknown Source)
	at java.util.Formatter.format(Unknown Source)
	at java.io.PrintStream.format(Unknown Source)
	at java.io.PrintStream.printf(Unknown Source)
	at HeatIndexCalculator.printHeatIndex(HeatIndexCalculator.java:36)
	at HeatIndexCalculator.main(HeatIndexCalculator.java:53)

Would be much more helpful. "My program crashes" is not helpful.

The error is telling you that the conversion 'i' in the printf statement in line 36 is not a legal or known coversion. Since one of the numbers being converted is an int and the other a double, you would use %d and %f in place of %i. I'll leave to you to determine which goes where.

You can learn more about the Java's formatted print statement by referring to the API which may refer you to the Formatter class or some other page that has essentially the same info.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1