Thread: Please help
View Single Post
  #5 (permalink)  
Old 04-01-2008, 11:15 AM
cod4 cod4 is offline
Member
 
Join Date: Mar 2008
Posts: 5
cod4 is on a distinguished road
teacher sent this earlier today, still dont know what to do
Code:
import java.util.*; public class Temperature { //you will need to declare an instance variable to store the temperature here. //it must be given private access control. public boolean setF(double tInFahrenheit) { return true; } public boolean setC(double tInCelsius) { return true; } public boolean setK(double tInKelvin) { return true; } //Each of the set methods must return the value true if the set operation was successful //and false otherwise. Your set methods must not allow temperatures that are not //physically realizable (below zero Kelvin). You must check the input values and return //false if they are temperatures that are below zero Kelvin (absolute zero). public double getF() { return 0.0; } public double getC() { return 0.0; } public double getK() { return 0.0; } //These get methods will return the temperature represented by the object in the units indicated. //You will need to convert from whatever your internal representation is to the appropriate units //(Fahrenheit, Celsius, or Kelvin). public boolean equals(Temperature t) { return true; } public boolean greaterThan(Temperature t) { return true; } public boolean lessThan(Temperature t) { return true; } //These comparison methods will return true if the calling object is related to the argument //object by the operator named by the method name. In other words, given two Temperature objects, //t1 and t2: //the method invocation t1.equals(t2) returns true if (and only if) the two temperature objects //represent the same temperature. //method call t1.lessThan(t2) returns true iff t1 < t2 //method call t1.greaterThan(t2) returns true iff t1 > t2 //The following static methods must be defined (you will find them useful for implementing //the get and set methods, and they are also useful as library routines for other programmers): public static double fahrenheitToCelsius(double degreesF) { return 0.0; } public static double fahrenheitToKelvin(double degreesF) { return 0.0; } public static double celsiusToFahrenheit(double degreesC) { return 9.0/5.0*degreesC + 32.0; } public static double celsiusToKelvin(double degreesC) { return 0.0; } public static double kelvinToCelsius(double degreesK) { return 0.0; } public static double kelvinToFahrenheit(double degreesK) { return 0.0; } //Finally, you must provide constructor methods as follows: //sets to a default temperature value of zero degrees C. public Temperature() { } //sets to t degrees in the scale represented by the scale parameter //(use 'c' or 'C' for Celsius, 'f' or 'F' for Fahrenheit, and 'k' or 'K' for Kelvin). //If the scale parameter is not interpretable or the temperature specified is not a //physically possible temperature, your constructor should set the temperature to the default //value specified for the default constructor above (you can see how to deal with this situation //in a more reasonable fashion by using exception handling (in chapter 8). For now, we don't want //to allow the creation of an object that represents an "impossible" temperature.). public Temperature(double t, char scale) { } }

Last edited by cod4 : 04-01-2008 at 12:10 PM.
Reply With Quote