help in java
Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have a number of constructor methods: one with two parameters for the two instance variables, and a noargument constructor (set to zero degrees Celsius). Include the following:
(1) two accessor methods to return the temperature one to return the degrees Celsius, the other to return the degrees Fahrenheit use the following formulas to write the two methods, and round to the nearest tenth of a degree:
degreesC = 5(degreesF - 32)/9
degreesF = (9(degreesC)/5) + 32
(2) three mutator or set methods: one to set the value, one to set the scale (F or C), and one to set both;
(3) three comparison methods: an equals method to test whether two temperatures are equal, one method to test whether one temperature is greater than another, and one method to test whether one temperature is less than another (note that a Celsius temperature can be equal to a Fahrenheit temperature as indicated by the above formulas); and
(4) a suitable toString method. Then write a driver program (or programs) that tests all the methods. Be sure to use each of the constructors, to
include at least one true and one false case for each of the comparison methods, and to test at least the following temperature equalities: 0.0 degrees C = 32.0 degrees F, -40.0 degrees C = -40.0 degrees F, and 100.0 degrees C = 212.0 degrees F.
View Answers
April 22, 2011 at 5:19 PM
class Temperature{
private double value;
private char scale;
public Temperature(){
value = 0;
scale = 'C';
}
public Temperature(double value, char scale){
setTemperature(value, scale);
}
public double getTempInCelsius(){
if(scale == 'C'){
return value;
}else {
return (double)5/9 *(value - 32);
}
}
public double getTempInFahrenheit(){
if(scale == 'F'){
return value;
}else {
return (double)(9/5 *(value)) + 32;
}
}
public void setValue(double value){
this.value=value;
}
public void setScale(char scale){
this.scale=scale;
}
public void setTemperature(double value, char scale){
this.value = value;
if (scale == 'F'){
this.scale = scale;
}else {
this.scale = 'C';
}
}
public boolean isGreater(Temperature another){
return (this.getTempInCelsius()> another.getTempInCelsius() );
}
public boolean equals(Temperature another){
return (this.getTempInCelsius()== another.getTempInCelsius() );
}
public boolean isSmaller(Temperature another){
return (this.getTempInCelsius()< another.getTempInCelsius() );
}
public String toString (){
return "temperature : "+value + " " + scale;
}
}
public class TemperatureConverter{
public static void main(String[] args){
Temperature temp1=new Temperature(30, 'F');
Temperature temp2=new Temperature(15, 'C');
if (temp1.isGreater( temp2)){
System.out.println(temp1 + "is greater than " + temp2);
}
else {
System.out.println(temp2 + "is greater than " + temp1);
}
System.out.println("Temperature in Fahrenheit " + temp1 + " is "+ temp1.getTempInCelsius()+" C");
System.out.println("Temperature in Celcius " + temp2 + " is "+ temp1.getTempInFahrenheit()+" F");
Temperature temp3=new Temperature(0, 'C');
Temperature temp4=new Temperature(-40, 'C');
Temperature temp5=new Temperature(100, 'C');
System.out.println("0 degree C"+ "="+ temp3.getTempInFahrenheit()+" degree F");
System.out.println("-44 degree C"+ "="+ temp4.getTempInFahrenheit()+" degree F");
System.out.println("100 degree C"+ "="+ temp5.getTempInFahrenheit()+" degree F");
}
}
Related Tutorials/Questions & Answers:
java help! java help! I need
help starting off a program I am trying to write for class. The class should contain a private instance variable to represent temperature in Degrees Celsius and it should have the following methods
Help With Java...Help With
Java... Write a
java program that can take a positive integer greater than 2 as input and write out the number of times one must repeatedly divide this number by 2 before getting a value less than 2
Advertisements
help in javahelp in java
Rational Numbers
Rational numbers are numbers that can be represented as a fraction p /
q where p is an integer number and
q is a positive integer (
q != 0). Design and implement a
Java class
RationalNumber
help in javahelp in java Write an application that prompt the user to enter a number to use as an array size, and
then attempt to declare an array using the entered size.
Java generates a NegativeArraySizeException if wou attempt to create
java help?java help? Write a program, where you first ask values to an array with 6 integer values and then count the sum and average of the values in methods (send in the array & return the counted value to the main program). Print
java help java help Write a
Java program that does the following:
1.Creates a grading program based on the Baker College grading standard. You will need to look up the current grade standard. You may use only the letter grades without
help for javahelp for java 1.convert the following Pseudo code to
java if/else structure
if student?s grade is greater than or equal to 90 Print ?A?
else
if student?s grade is greater than or equal to 80
Print ?B?
else
help in javahelp in java 3.Flights
Design and implement a class called Flight that represents an airline flight. It should contain instance data that represents the airline name, flight number, and the flight's origin and destination cities
help in javahelp in java Write a program that will evaluate simple expressions such as 17 + 3 and 3.14159 * 4.7. The expressions are to be typed in by the user. The input always consist of a number, followed by an operator, followed
help in javahelp in java Design and implement a class called Sphere that contains instance data that represents the sphere's diameter. Define the Sphere constructor to accept and initialize the diameter, and include getter and setter
help in javahelp in java The factorial of a nonnegative integer n is written n! (pronounced ââ?¬Å? n factorialââ?¬Â?)
and is defined as follows:
n!=n . (n-1) . (n-2) . .... . 1 (for values of n greater than or equal to 1) and
n!=1 (for n
help in javahelp in java Gross And Dozens
Design and implement a class called GrossAndDozens to convert a given number of eggs into the number of gross, the number of dozens, and to the number of left over eggs. If you have N eggs, then you
help in javahelp in java Shopping cart
Create 3 shopping carts from a Cart class. Each class should have four items in it, a title, a price for the 4 items and the number of each. Your shopping cart should use private variables, so use
help in javahelp in java
Team Roster
Create a program called TeamRoster that uses a class called Roster. Roster should contain a team name and the names of all...
or
help me on this pleas..
7. Gross And Dozens
Design and implement a class
help in javahelp in java Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have a number
help in javahelp in java Temperature
Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have
help in javahelp in java Create 3 shopping carts from a Cart class. Each class should have four items in it, a title, a price for the 4 items and the number of each. Your shopping cart should use private variables, so use getter and setter
help in javahelp in java Define a class named Money whose objects represent amounts of U.S. money. The class will
have two instance variables of type int for the dollars and cents in the amount of money.
Include a constructor with two
help in javahelp in java Create a class named Order that performs order processing of a single item. The class has five
instance variables (fields) : customer name, customer number, quantity ordered, unit price, and
total price. Define
java helpjava help How to Open CSV Files in a Microsoft Excel Application Using
Java Code with example pgm
java helpjava help 1) build class(es) for the dresses, choose (dress ID, color, price, designer)( link lists)
2) construct the driver class by establishing two separate objects for each sister
3) let them both to enter the dresses
java helpjava help Rational numbers are numbers that can be represented as a fraction p /
q where p is an integer number and
q is a positive integer (
q != 0). Design and implement a
Java class
RationalNumber for representing such numbers
Java helpJava help 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 'C' for Celsius or 'F
Java HelpJava Help 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 'C' for Celsius or 'F
java helpjava help Design and implement a class called DateWriter that has three instance variables:
a string for month, an integer for day, and an integer for year. The class should has
a constructor to accept and initialize the values
Intro Java help with DoubleIntro
Java help with Double I have to evaluate a math expression using double in
Java. I can input the code fine for the expression, but I don't know how to view the answer that it gives me.
help Need Help in Java programmingNeed
Help in
Java programming Hello. Can someone please
help me with writing the following program
Java program that gives assignment details such as:assignment number,assignment name,due date,submission date,percentage marks
PLZ Need some help JAVA...HELP !!PLZ Need some
help JAVA...
HELP !! Create a class names Purchase Each purchase contains an invoice number, amount of sale and amount of sales tax. Include set methods for the invoice number and sale amount. Within the set
help help how i can send a pitcture on url in
java New to Java Please helpNew to
Java Please help Hi I need
help, can some one
help me.... Thanks!
If you are new in
java, then you need to learn core
java concepts.So go through the following link:
Core
Java Tutorials
Here, you will find
java,java,java,helpjava,
java,
java,help Dear people, can anyone
help me complete this program
import java.util.*;
public class StringDemo {
static String a="{a=100;b=200;c=300}";
public static void main(String args[])
{
String b[]=a.split
Help me - Java BeginnersHelp me please
help me in writing a program in
java "A student has a name,roll no., class, home address, date of birth. First dessigne a suitable class for date, write constructor and get and set functions. Then dissign a class
Java Programming HelpJava Programming Help Hello ! I m the student of last year and i need your
help to complete my
java project. I going to make a site like youtube... with controls ..
I Just want to use jsp and applet in my project . Please
help me
helphelp pls
help me to get the code of a
java program
a program to perform different shapes in a menu using javaapplet
Need help on JAVA JSPNeed
help on
JAVA JSP Hi,
I have never worked on
java and I have been given an assignment where I have to fix existing issues in the tool(created using
JAVA JSP).
e.g.
Tool does not adjust with the resolution of the screen
Java Help PleaseJava Help Please I can't seem to figure out how to make this program, can some one
help me please? It is due soon!!
4) Write a program that will take an input (Date object will contain fields for the month, day, and year - all
Java programing helpJava programing help Can you
help me create this program?
Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign
Java application Help?Java application
Help? Write an application that accepts a users password from the keyboard. When the entered password is less then six characters more then 10 characters, or does not contain at lease one letter and one digit
java-help - Java Beginnersjava-help hello sir, please
help me.....the below given is the output.java program
here in this program am using the stmts
ta. append("clustering")
where ta is a textarea created in input.java file.i have designed only one
help with program - Java BeginnersHelp with program Simple
Java Program // Defining class Stars.java to print stars in certain orderclass Stars{// main() functionpublic static void main(String[] args){int a = 1, b = 5, c, d, i; // declaring 5 int type
help to write java codehelp to write
java code write a full code to produce a system will calculate all items to get total carry-marks which are 60 marks. and get sum of assignment 1,assignment 2, midterms-test and lave work to get total marks
help to write java codehelp to write
java code write a full code to produce a system will calculate all items to get total carry-marks which are 60 marks. and get sum of assignment 1,assignment 2, midterms-test and lave work to get total marks
Graphic interface java helpGraphic interface
java help A modified checkers program with class name Checkers using double buffering. Somehow the program must have two top..., please
help helphelp i need
help with this code.
write a
java code for a method named addSevenToKthElement that takes an integer array, and an integer k as its arguments and returns the kth element plus 7.
any
help would be greatly
Java application help!Java application
help! In Deep Water Associates operates a business that offers a variety of services to customers who own swimming pools, including... minute
60
$8
Can anyone
help me
Java Help (Beginer Tutorial)Java Help (Beginer Tutorial) Hi this is my first year for
Java... doing so I was wondering if anyone was willing to
help me solve a couple of them... would appericate any
help at all! Im using Eclipse by the way.
Practice 2)Write
help in java programhelp in
java program please could you
help me with my assignment
I have to submit it on Monday 29 October
please
help me :(
Write a program to test the Person class defined below. Your test program should
help - Java Beginnershelp hi,i am new to
java & i do not have progamming background, i... to do or what could be the issue? plz
help hello,
First complie ur...:\>javatutorial>
java classname afterwards it will give u output. But before
Need Help - Java Beginners projects in
Java as well as J2EE...
Can u
help me and guide to do a project...Need Help Hello Sir,
Am a beginner of
Java. Also i did course.../reference/tutorials/
http://netbeans.org/kb/trails/
java-ee.html
http
help - Java Beginnershelp Sir...i will pass you some questions which actually i am not able to do....will u
help me..reply soon