CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    May 2017
    Posts
    1

    Java Eclipse - Double Array Type Mismatch Errors

    Hi, I'm a student writing a java temperature conversion program. The program includes the main driver, a class to read from a file "temps" which has an array of temparatures. The second class "Temp" is supposed handle the calculations with multiple methods. Because the array file has temperatures, there are ofcourse decimals. I'm getting red squiggly lines in the 2nd class where I reference the 1st method "convertToFAH" the message is "The method convertToFah(double[]) in the type Temp is not applicable for the arguments (double[], double, double)". I'm also getting a type mismatch error in the method convertToFAH, on the temps array. "Type mismatch cannot convert from double [] to double". Since the file includes an array don't I have to include the square brackets?

    I'm almost at the end of the semester, but just haven't gotten the hang of converting different data types. How can I fix my program so the red squiggly lines go away?

    Code:
    public class Temp {
    	
    	private String [] months = {"January", "February","March", "April", "May","June",
    			"July", "August","September","October","November","December"};
    	
    	public Temp (double []temps, String months)
    	{
    		
    	double avg = 0;
    	double max = 0;
    	String maxMonth = null;
    	double min = 0;
    	String minMonth = null;
    	double fahrenheit = 0;
    	double centigrade = 0;
    	
    	convertToFah(temps, fahrenheit, centigrade);	<<<<<<<<<<<<<<<<<<error 1 is here
    	
    	}
    
    	public double convertToFah(double [] temps)
    	
    	{	double fahrenheit = 0;
    		double centigrade = 0;
    		int a = Array.getLength(temps);
    		
    		for(int i = 0; i < a; i++) 
    				
    		centigrade = temps; <<<<<<<<<<<<<<<<error 2 on the word temps
    		fahrenheit = centigrade * 9.0/5.0 + 32;
    		
    		return fahrenheit;
    	}
    Last edited by 2kaud; May 16th, 2017 at 04:08 AM. Reason: Added code tags

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured