4 Replies - 3202 Views - Last Post: 28 February 2009 - 03:45 PM Rate Topic: -----

#1 mmccaule  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-February 09

conversions among Fahrenheit, Centigrade and Kelvin systems

Post icon  Posted 28 February 2009 - 03:07 PM

Here is what the error states:The code you submitted is incorrect . Can someone please explain what I did wrong in a that a dummy like me can understand.

Example Test Case

temperature + degrees C = convertTemp + degrees K


Your code:
class studentSubmission {
	double convertTemperature(double temperature, 
							  char fromSystem, char toSystem) {
		double convertTemp = 0.0; 
		double degrees = 0; 
		switch(fromSystem) { 
			case 'F': 
			   if (toSystem == 'F') 
			   { 
				  System.out.println("no conversion needed, Fahrenheit to fahrenheit requested"); 
				  convertTemp = temperature; 
				  break; 
				} 
				if (toSystem == 'C') 
				{ 
				  convertTemp = 5 * (degrees - 32)/9; 
				  System.out.println("temperature + degrees F =  + convertTemp + degrees C"); 
				  break; 
		 } 
				if (toSystem == 'K') 
		 { 
				  convertTemp = ((degrees - 273) * (9/5)) + 32; 
				  System.out.println("temperature + degrees F = + convertTemp + degrees K"); 
				  break; 
				 } 
			case 'C': 
		 if (toSystem == 'C') 
				 { 
		   System.out.println("no conversion needed, Centigrade to Centigrade requested"); 
				  convertTemp = temperature; 
				  break; 
		  } 
		 if (toSystem == 'F') 
		 { 
		   convertTemp = (degrees - 32) * (5 / 9); 
		   System.out.println("temperature + degrees C = convertTemp + degrees C"); 
		   convertTemp = temperature; 
		   break; 
		 } 
		 if (toSystem == 'K') 
		 { 
		  convertTemp = (degrees - 273); 
		  System.out.println("temperature + degrees C = convertTemp + degrees K"); 
		  convertTemp = temperature; 
		   break; 
		 } 
			case 'K': 
		 if (toSystem == 'K') 
		 { 
		   System.out.println("no conversion needed, Kelvin to Kelvin requested"); 
		   convertTemp = temperature; 
		   break; 
		 } 
		 if (toSystem == 'F') 
		 { 
		   convertTemp = (degrees - 32) * (5 / 9) + 273; 
		   System.out.println("temperature + degrees K = convertTemp + degrees F"); 
		   convertTemp = temperature; 
		   break; 
		 } 
		 if (toSystem == 'C') 
		   { 
		   convertTemp = degrees + 273; 
		   System.out.println("temperature + degrees K = convertTemp + degrees C"); 
		   convertTemp = temperature; 
		   break; 
				 } 
		} 
		   return convertTemp;
	}
}



Moderator Note: Added code tags.
- Core


Is This A Good Question/Topic? 0
  • +

Replies To: conversions among Fahrenheit, Centigrade and Kelvin systems

#2 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: conversions among Fahrenheit, Centigrade and Kelvin systems

Posted 28 February 2009 - 03:13 PM

Quote

Here is what the error states:The code you submitted is incorrect


And where did you submit it?

Are you getting any errors from the program?

Please post code like this: :code:

You can edit your post for this.
Was This Post Helpful? 0
  • +
  • -

#3 mmccaule  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-February 09

Re: conversions among Fahrenheit, Centigrade and Kelvin systems

Posted 28 February 2009 - 03:23 PM

View PostBigAnt, on 28 Feb, 2009 - 02:13 PM, said:

Quote

Here is what the error states:The code you submitted is incorrect


And where did you submit it?

Are you getting any errors from the program?

Please post code like this: :code:

You can edit your post for this.

[/quote]
I submitted my code in "Gradiance Online Accelerated Learning". It formats the beginning code. I have to fill in the proper code for it to compile and run correctly. It told me that it compiled/built correctly but did not get the proper results. Here is what the problem states:

This method takes a temperature value, a character indicating the temperature system from which to convert and another character indicating the target temperature system. The method returns the value of the temperature in the target system.

The method handles conversions among Fahrenheit, Centigrade and Kelvin systems. These systems are represented by ''F'', ''C'' and ''K'' respectively. The formula to convert from Fahrenheit to Centigrade is: C = (F - 32) * (5/9). The formula to convert from Kelvin to Centigrade is: K = C + 273. From these two formulas, we can derive the other formulas as: C = K - 273; F = (C * (9/5)) + 32; K = ((F -32) * (5/9)) + 273; F = ((K - 273) * (9/5)) + 32.

The method uses the above formulas to do the temperature conversion. For instance, given inputs 20, ''C'', ''F'', the method returns 68.

The following is the method prototype for the method:
double convertTemperature(double temperature, char fromSystem, char toSystem)

If either fromSystem or toSystem is not ''F'', ''C'' or ''K'', then the method should return the temperature unchanged (that is the output value is the same as the input value).

Please submit your code below.


class studentSubmission {
double convertTemperature(double temperature,
char fromSystem, char toSystem) {



double convertTemp = 0.0;
double degrees = 0;
switch(fromSystem) {
	case 'F':
	   if (toSystem == 'F')
	   {
		  System.out.println("no conversion needed, Fahrenheit to fahrenheit requested");
		  convertTemp = temperature;
		  break;
		}
		if (toSystem == 'C')
		{
		  convertTemp = 5 * (degrees - 32)/9;
		  System.out.println("temperature + degrees F =  + convertTemp + degrees C");
		  break;
	}
		if (toSystem == 'K')
	{
		  convertTemp = ((degrees - 273) * (9/5)) + 32;
		  System.out.println("temperature + degrees F = + convertTemp + degrees K");
		  break;
		 }
	case 'C':
	if (toSystem == 'C')
		 {
	  System.out.println("no conversion needed, Centigrade to Centigrade requested");
		  convertTemp = temperature;
		  break;
	 }
	if (toSystem == 'F')
	{
	  convertTemp = (degrees - 32) * (5 / 9);
	  System.out.println("temperature + degrees C = convertTemp + degrees C");
	  convertTemp = temperature;
	  break;
	}
	if (toSystem == 'K')
	{
	 convertTemp = (degrees - 273);
	 System.out.println("temperature + degrees C = convertTemp + degrees K");
	 convertTemp = temperature;
	  break;
	}
	case 'K':
	if (toSystem == 'K')
	{
	  System.out.println("no conversion needed, Kelvin to Kelvin requested");
	  convertTemp = temperature;
	  break;
	}
	if (toSystem == 'F')
	{
	  convertTemp = (degrees - 32) * (5 / 9) + 273;
	  System.out.println("temperature + degrees K = convertTemp + degrees F");
	  convertTemp = temperature;
	  break;
	}
	if (toSystem == 'C')
	  {
	  convertTemp = degrees + 273;
	  System.out.println("temperature + degrees K = convertTemp + degrees C");
	  convertTemp = temperature;
	  break;
		 }
}
   return convertTemp;


[/quote]
Was This Post Helpful? 0
  • +
  • -

#4 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: conversions among Fahrenheit, Centigrade and Kelvin systems

Posted 28 February 2009 - 03:35 PM

Well the degrees variable is always zero, why do you need this, just use the temperature variable passed in and then there is no need for the degrees variable at all.
Was This Post Helpful? 0
  • +
  • -

#5 mmccaule  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-February 09

Re: conversions among Fahrenheit, Centigrade and Kelvin systems

Posted 28 February 2009 - 03:45 PM

View PostBigAnt, on 28 Feb, 2009 - 02:35 PM, said:

Well the degrees variable is always zero, why do you need this, just use the temperature variable passed in and then there is no need for the degrees variable at all.


I give it a shot thank you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1