Question: public Temp() : The default constructor for the class, which initializes the object to 32 degree Fahrenheit. Both variables must be set using explicit assignment

public Temp(): The default constructor for the class, which initializes the object to 32 degree Fahrenheit. Both variables must be set using explicit assignment statements. You cannot rely on default values given to variables by Java.

public Temp(double initT, char initS): Another definition of the constructor. It takes as a parameter a temperature measurement and a symbol ('c' or 'C' for Celsius or 'f' or 'F' for Fahrenheit) representing the scale and initializes the object using those values. If the scale provided as a parameter is not valid, meaning the scale is not either Celsius or Fahrenheit, the constructor should use a default of Fahrenheit for the measurement. In either case, do not prompt the user for another value. Simply use the default specified. Both variables must be set using explicit assignment statements. You cannot rely on default values given to variables by Java.

public void set(): This method prompts the user for a decimal value representing a temperature and a character representing a scale (either Celsius or Fahrenheit). If an invalid scale (something other than 'c', 'C', 'f', or 'F') is entered, the method repeatedly asks for the scale again. You may assume that when prompted the user will provide a number (either floating point or integer) for the temperature.

public double getC(): This method returns the temperature in Celsius. If the temperature is stored in Celsius already, it just returns it. Otherwise it computes the equivalent temperature in Celsius (without changing the value in the object) and returns it. Note that to convert a temperature Tf in Fahreheit to one in Celsius you write: (Tf - 32) / 1.8.

public double getF(): This method returns the temperature in Fahrenheit. If the temperature is stored in Fahrenheit already, it just returns it. Otherwise it computes the equivalent temperature in Fahrenheit (without changing the value in the object) and returns it. Note that to convert a temperature Tc in Celsius to one in Fahrenheit you write: Tc * 1.8 + 32.

package hw5b;

// Name

import java.util.Scanner;

public class Temp { // No additional members of the class // Feel free to use local variables as necessary in each method private double tValue; // If you like, you can change the type of scale to Character private char scale; // For use in set() private Scanner vScan = new Scanner(System.in);

// The default constructor for the class public Temp() { }

// The parameterized constructor for the class public Temp(double initT, char initS) {

}

// Input values for the instance variables using the Scanner vScan public void set() { }

// Return the temperature in Celsius public double getC() { // A stub -- replace this by the correct code return 0.0; }

// Return the temperature in Fahrenheit public double getF() { // A stub -- replace this by the correct code return 0.0; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!