Java class problem

  • From: "Gilbert Neiva" <gneiva@xxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sun, 27 Jun 2010 16:07:28 -0600

I'm trying to make a class that has a method to convert a celsius to two 
values, approximate fahrenheit, and accurate fahrenheit. The method is below.

public static String celsFahr()

// This method will print "Close enough"

// If the values of approximate fahrenheit

// are within two degrees of each other and

// it will print "Will not do" if those two

// values are not within

// two degrees of each other

{

appFahr = cels * 2 + 32;

// Formula to convert

// celsius to approximate fahrenheit

fahr = (9 / 5) * cels + 32;

// Formula to convert celsius to accurate fahrenheit

lessFahr = fahr - 3;

greatFahr = fahr + 3;


if ((appFahr <= fahr) && (appFahr > lessFahr) || (appFahr >= fahr) && (appFahr 
< greatFahr))

{

return System.out.println("Close enough");

}

else

{

return System.out.println("Will not do"); 

}

} // End of method



When I try to compile the .java file, I get the following error.



FahrClss.java:90: incompatible types
found   : void
required: java.lang.String
return System.out.println("Close enough");
^
FahrClss.java:94: incompatible types
found   : void
required: java.lang.String
return System.out.println("Will not do");
^
2 errors



I tried importing java.lang.String at the top of my class.



import java.lang.String;



Unfortunately, that did not work. What am I doing wrong. My entire class is 
below.



public class FahrClss

{

static int cels; // Stores the value for celsius

static int appFahr; // Stores the value

// of approximate fahrenheit

static int fahr; // Stores the value of

// exact fahrenheit

static int lessFahr; // Stores the value of

// fahr - 3

static int greatFahr; // Stores the value of

// fahr + 3




public FahrClss(int newCels)

// Start of parameterized constructor

{

cels = newCels; // Stores the value passed

// from newCels

}




public FahrClss()

// Start of default constructor

{

cels = 0; // object gets set to 0

}




public static int getCels()

// Start of observer method

{

return cels; // Returns the value of

// cels to driver class

}




public static int getAppFahr()

// Start of observer method

{

return cels * 2 + 32; // Returns the value of

// approximate fahrenheit to driver class

}




public static int getFahr()

// Start of observer method

{

return (9 / 5) * cels + 32; // Returns the value of

// fahrenheit to driver class

}




public static String celsFahr()

// This method will print "Close enough"

// If the values of approximate fahrenheit

// are within two degrees of each other and

// it will print "Will not do" if those two

// values are not within

// two degrees of each other

{

appFahr = cels * 2 + 32;

// Formula to convert

// celsius to approximate fahrenheit

fahr = (9 / 5) * cels + 32;

// Formula to convert celsius to accurate fahrenheit

lessFahr = fahr - 3;

greatFahr = fahr + 3;




if ((appFahr <= fahr) && (appFahr > lessFahr) || (appFahr >= fahr) && (appFahr 
< greatFahr))

{

return System.out.println("Close enough");

}

else

{

return System.out.println("Will not do"); 

}

} // End of method

} // End of class



Gilbert Neiva


Other related posts: