Write a Temperature class in java and only assing the values if they are valid.
Temperature
Degrees:double between -50 and 150 F
Scale :char can be C or F
+Temperature () default to 10 celcius
+Temperature(temp:double, scale:char) assign if valid
+get_Temp():double returns current temperature value
+get_Scale(): char returns current scale
+set(temp:double,scale:char)void set degrees and scale if valid
+set_Temp(temp:double)void assings it if valid
+set_Scale(scale:char)voild coverts existing tmep to scale if valid
+covert_FtoC(temp: double)double coverts F to returned C
package com;
public class Temperature {
double Degrees;
char Scale;
public Temperature() {
Degrees=10.0;
Scale='C';
}
public Temperature(double degrees, char scale) {
if(degrees>=-50 && degrees<=150 && (scale=='C' || scale=='F'))
{
Degrees = degrees;
Scale = scale;
}
}
public double get_Temp() {
return Degrees;
}
public void set_Temp(double degrees) {
if(degrees>=-50 && degrees<=150)
Degrees = degrees;
}
public char get_Scale() {
return Scale;
}
public void set_Scale(char scale) {
if(scale=='C' || scale=='F')
Scale = scale;
}
public void set(double degrees, char scale)
{
if(degrees>=-50 && degrees<=150 && (scale=='C' || scale=='F'))
{
Degrees = degrees;
Scale = scale;
}
}
public double convert_FtoC(double temp)
{
temp = ((temp - 32)*5)/9;
return temp;
}
}
Write a Temperature class in java and only assing the values if they are valid. Temperature...
In java Se8 i am trying to write a program convert temperature
between celsius, fahrenheit and kelvin, but i am stuck at how to
return the proper result without chage the frame, and I cnould not
figure out how to use those three settemp method.
import java. uti1. Arrays public class Temperature different scale names/ public static Stringll scales -Celsius", "Fahrenheit", "Kelvin private double temperature private char scale; public Temperature (double temp temp 273. 15; this. scale-C if (temp <-273....
A breakdown of the problem is as follows: Class name: Temperature Instance variables: temp (double) and tempScale (char; either ‘C’ or ‘F’) Constructor methods: Temperature() – sets temp to 0 Celsius Temperature(double initialTemp) – sets temp Temperature(char tempType) – sets tempScale to ‘C’ or ‘F’) Temperature(double initialTemp, char tempType) -- sets temp and tempScale to ‘C’ or ‘F’) Accessor methods: getTemp – returns value of temp for the object getTempScale– returns temperature scale (‘C’ or...
In this assignment you will be implementing a weather forecaster. It involves writing 3 different classes plus a driver program. It is recommended that you write one class at a time and then write a driver (tester) program to ensure that it works before putting everything together. Alternately, you can use the Interactions tab of JGRASP to test some of the early classes. This is discussed in the next few pages. The Season Class The first, shortest, and easiest class...
Java please The kelvin is the base unit of temperature in the International System of Units (SI), having the unit symbol K. It is named after the Belfast-born, Glasgow University engineer and physicist William Thomson, 1st Baron Kelvin (1824–1907). It uses absolute zero as its null point. The Celsius scale, also known as the centigrade scale, is a temperature scale used by the International System of Units (SI). The Celsius scale is based on 0 °C for the freezing point...
Java program
Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a floating- point number for the temperature and a character for the scale, eitherでfor Celsius or 'F' for fahrenheit. The class should have Four constructors: one for the number of degrees, one for the scale, one for both the degrees and scale, and a default constructor. For each of these constructors, assume zero degrees if no value is specified and celsius if no...
In java code: Write a Temperature class that has two private instance variables: • degrees: a double that holds the temperature value • scale: a character either ‘C’ for Celsius or ‘F’ for Fahrenheit (either in uppercase or lowercase) The class should have (1) four constructor methods: one for each instance variable (assume zero degrees if no value is specified and assume Celsius if no scale is specified), one with two parameters for the two instance variables, and a no-argument...
Java Write a Temperature class that has two private instance variables: • degrees: a double that holds the temperature value • scale: a character either ‘C’ for Celsius or ‘F’ for Fahrenheit (either in uppercase or lowercase) The class should have - four constructor methods: one for each instance variable (assume zero degrees if no value is specified and assume Celsius if no scale is specified), one with two parameters for the two instance variables, and a no-argument constructor (set...
import java.util.Scanner; public class TempConvert { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); //ask the user for a temperature System.out.println("Enter a temperature:"); double temp = scnr.nextDouble(); //ask the user for the scale of the temperature System.out.println("Is that Fahrenheit (F) or Celsius (C)?"); char choice = scnr.next().charAt(0); if(choice == 'F') { //convert to Celsius if given temperature was Fahrenheit System.out.println(temp + " degrees Fahrenheit is " + ((5.0/9) * (temp-32)) + " degrees Celsius"); } else {...
CIT-111 Homework #4, Part A Chapter 4, problem #7 (pages 254-255) A breakdown of the problem is as follows: Class name: Temperature Instance variables: temp (double) and tempScale (char; either ‘C’ or ‘F’) Constructor methods: Temperature() – sets temp to 0 Celsius Temperature(double initialTemp) – sets temp Temperature(char tempType) – sets tempScale to ‘C’ or ‘F’) Temperature(double initialTemp, char tempType) -- sets temp and tempScale to ‘C’ or ‘F’) Accessor methods: getTemp – returns value of...
In Java*
Please implement a class called "MyPet". It is designed as shown
in the following class diagram.
Four private instance variables: name (of the type String),
color (of the type String), gender (of the type char) and weight(of
the type double).
Three overloaded constructors:
a default constructor with no argument
a constructor which takes a string argument for name, and
a constructor with take two strings, a char and a double for
name, color, gender and weight respectively.
public...