temperature converting

temperature converting

Write a program that makes use of a class called Degrees that implements the following doublemethods as per the UML class

    Method celsius returns the Celsius equivalent of a given Fahrenheit temperature
    Method fahrenheit returns the Fahrenheit equivalent of a given Celsius temperature
    Method displayTable should use the above methods to prints charts showing:


    The Fahrenheit equivalents of all Celsius temperatures from 0 to 100 degrees in 4 degree intervals
    The Celsius equivalents of all Fahrenheit temperatures from 32 to 212 degrees in 10 degree intervals
    Both columns in each chart should be printed to one decimal place
    Print the charts in a neat tabular format that minimizes the number of lines of output while remaining readable
View Answers

June 19, 2012 at 1:20 PM

Here is an example of Temperature Conversion where we have converted Celcius to Fahrenheit and vice versa. For this, we have create three functions celcius(), fahrenheit() and display table which display the conveted values in the form of chart.

import java.util.*;
import java.text.*;

class Degrees 
{
    public static double fahrenheit(int temp) {
         return (1.8 * temp) + 32;
    }

    public static double celsius(int temp) {
         return (temp - 32) / 1.8;
    }
    public static void displayTable(){
        DecimalFormat df=new DecimalFormat("##.#");
        System.out.println("Celcius (C)   Fahrenheit (F)");
        for(int i=0;i<=100;i+=4){
            System.out.println(i+"\t    |     "+df.format(fahrenheit(i)));
        }
        System.out.println("Fahrenheit (F)   Celcius (C) ");
        for(int i=32;i<=212;i+=10){
            System.out.println(i+"\t    |     "+df.format(celsius(i)));
        }
    }

    public static void main(String[] args) 
    {
        displayTable();
    }
}

July 1, 2012 at 4:59 AM

thanks :)









Related Tutorials/Questions & Answers:
temperature converting
temperature converting   Write a program that makes use of a class... temperature Method fahrenheit returns the Fahrenheit equivalent of a given Celsius temperature Method displayTable should use the above methods to prints
ModuleNotFoundError: No module named 'temperature'
ModuleNotFoundError: No module named 'temperature'  Hi, My Python... 'temperature' How to remove the ModuleNotFoundError: No module named 'temperature' error? Thanks   Hi, In your python environment
Advertisements
ModuleNotFoundError: No module named 'temperature'
ModuleNotFoundError: No module named 'temperature'  Hi, My Python... 'temperature' How to remove the ModuleNotFoundError: No module named 'temperature' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'temperature'
ModuleNotFoundError: No module named 'temperature'  Hi, My Python... 'temperature' How to remove the ModuleNotFoundError: No module named 'temperature' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'temperature'
ModuleNotFoundError: No module named 'temperature'  Hi, My Python... 'temperature' How to remove the ModuleNotFoundError: No module named 'temperature' error? Thanks   Hi, In your python environment
Help with Temperature program
Help with Temperature program  I need help to write a GUI program to calculate the temperature. and here is the format Application that converts temperature between 3 different scales: Fahrenheit, Celsius and Kelvin. ΓΆβ?¬Β
Temperature Converter in SWT
are created for converting the temperature. A button is created to perform an action... Temperature Converter in SWT       This example illustrates you how to convert temperature from
Convert Temperature
Convert Temperature       This section illustrates you how to convert the temperature from Fahrenheit to Celsius. To convert the temperature, we have created two
Converting ISO8601-compliant String to java.util.Date
Converting ISO8601-compliant String to java.util.Date  Converting ISO8601-compliant String to java.util.Date
ModuleNotFoundError: No module named 'rpi-temperature-mqtt'
ModuleNotFoundError: No module named 'rpi-temperature-mqtt'  Hi...: No module named 'rpi-temperature-mqtt' How to remove the ModuleNotFoundError: No module named 'rpi-temperature-mqtt' error? Thanks   Hi
ModuleNotFoundError: No module named 'CPU-temperature-monitor'
ModuleNotFoundError: No module named 'CPU-temperature-monitor'  Hi...: No module named 'CPU-temperature-monitor' How to remove the ModuleNotFoundError: No module named 'CPU-temperature-monitor' error? Thanks   
converting string to double in java
converting string to double in java  Please post an example to converting string to double in java. Thanks!   Convert String to Double Tutorial
C Temperature Converter
C Temperature Converter       Here we are going to illustrates you how to convert temperature... the user to enter the temperature in celsius. The scanf() function gets the entered
Converting PDF in to XML
Converting PDF in to XML  I have to convert PDF into XMl without any loss in text. Please suggest sth good
converting field to text sql
converting field to text sql  I wanted to convert the field to TEXT in SQL.. is it possible?   SQL - Converting the field to TEXT works SELECT CONVERT(TEXT,fld_name) FROM TABLE_NAME   SQL - Converting
Java Temperature Converter
Java Temperature Converter In this tutorial, you will learn how to convert temperature from Celsius to Fahrenheit and vice versa. Here is an example where we have created three functions celcius(), fahrenheit() and display table
Converting a NSString into NSDate
Converting a NSString into NSDate  hello. How can I create a NSDate object out of it and then get different components like day, month, date, year from it. I have date string: Tuesday, October 19, 2010.ADS_TO_REPLACE_1
Java and converting a PDF to XML
Java and converting a PDF to XML  I reviewed your example - https://www.roseindia.net/tutorial/java/xml/pdftoXML.html - and on many users group, it receives high praise. I understand it uses iText but I am having a problem
Converting string to Int - JDBC
Converting string to Int  String nrate=request.getParameter("t3"); i want convert this nrate to integer to make calculations on it... so what should i do??? where t3 is a text area name and i am fetching...  Hi
Converting XML to string
Converting XML to string  Hi Friends, I had an requirement in which a java program receives an xml messages from external web application such as (jsp, php) and then it converts the received xml message into a string. could
Java and converting a PDF to XML
Java and converting a PDF to XML  I reviewed your example - https://www.roseindia.net/tutorial/java/xml/pdftoXML.html - and on many users group, it receives high praise. I understand it uses iText but I am having a problem
converting decimal to base 32
converting decimal to base 32  procedure for converting decimal to base 32   CREATE PROCEDURE RTCONVERSION ( @valueToConvert int, @convertedValue varchar(20) out ) AS declare @counter int; declare @num int; declare @x
Converting Text Files into Bzip File
Converting Text Files into Bzip File  Hi, I am facing the problem during run the program, when converting text files into Bzip file. Please guide me how do i convert the text file into bzip file in PHP. I will welcome, if anyone
Converting NSURL to NSString creating a problem
Converting NSURL to NSString creating a problem  Hi , In my iPad/iPhone universal application, we are trying to covert theNSURL to NSString which cause the application crash. Does any one have idea about converting NSURL
Converting NSURL to NSString creating a problem
Converting NSURL to NSString creating a problem  Hi , In my iPad/iPhone universal application, we are trying to covert theNSURL to NSString which cause the application crash. Does any one have idea about converting NSURL
converting html file into pdf - Struts
converting html file into pdf  i want to convert html file into pdf file using java code please help me
Converting jsp variable to java variable
Converting jsp variable to java variable  Hi how to convert java script variable to java variable on same jsp page
converting image to byte[] - Java Beginners
converting image to byte[]  Dear Sir Can you please tell me a solution for converting a java.awt.Image to byte[] eg: java.awt.Image... for converting } Please give me a solution Thanks in Advance. Rahul
Converting HTML to image - Java Beginners
Converting HTML to image   Is it possible to convert html to image with java code ?   Hi friend, Please give the problem in details for complete solution. For read more information : http
converting one file format to another
converting one file format to another  Hi ser I need a code to export data from data grid to PDF and XL format plz help me out
losing precision converting from java BigDecimal to double
losing precision converting from java BigDecimal to double  losing precision converting from java BigDecimal to double
converting an xml file in relational database objects
converting an xml file in relational database objects  converting an xml file in relational database objects
Converting HTML to XML - Java Beginners
Converting HTML to XML  Hi, I am generating an HTML file (JSP from a Java Struts App.) I need to figure out a way to create an XML file from that HTML document. If you can refer me to some Java Code, that would
ffmpeg converting file mp4 to mov
ffmpeg converting file mp4 to mov  Hi, How to convert the mp4 file into mov file? Thanks   Hi, You should install ffmpeg on your computer and then use the following command to convert mp4 file into mov file
Javascript Question about converting Celcius to Fahrenheit
Javascript Question about converting Celcius to Fahrenheit  How to create a program to ask the user to enter a temperature in degrees celcius it convert it to fahrenheit using the following formula: f = (c*9/5)+32
xml Converting to java using JDOM
xml Converting to java using JDOM  Hello , I am new to java and JDom so i make a Xml file and i need help to read it from java using objects , my idea is i have school has a class,class has a 3 students ,student has a address
Converting a String to Integer in Java
Converting a String to Integer in Java In this video tutorial I will show you.... There are two methods of converting the String into integer value. One method...?": ADS_TO_REPLACE_2 Here is example code for converting a string to Integer
I converting binary to decimal and vice versa
I converting binary to decimal and vice versa  can i ask for the codes in converting binary to decimal and decimal to binary to be run in one program with repeat.. pls. help me! i badly need the codes by monday!! pls
java image converting to byte codes - Java Beginners
java image converting to byte codes  i want to convert an image to human unreadable format which is uploaded by client to server.How can i do
converting binary text to ascii readable text
converting binary text to ascii readable text  is there a way to read binary txt file and write them as ascii readable text files
converting html to ppt,pptx - Java Beginners
converting html to ppt,pptx   Hi, i convert html to .doc format.But i want to convert the html to ppt,xml,pptx,docx,pdf.. Is there any possibility to solve this problem
converting html to ppt,pptx - Java Beginners
converting html to ppt,pptx   Hi, i convert html to .doc format.But i want to convert the html to ppt,xml,pptx,docx,pdf.. Is there any possibility to solve this problem
converting java class to java fx class
converting java class to java fx class   i am working on a java project which would convert text to speech and speech to text. i have developed.... but when i m converting the same file to javafx .. it is giving an error " speech
Converting a Filename to a URL
Converting a Filename to a URL       A file object is used to a give a filename. Creating the File object doesn't mean that a file exists. It may be that the does not exist. Suppose
Converting the text files into bzip file.
Converting text  file into bzip file In this example, you will see, how to convert a text file into bzip file. In this example, we have printed 'I am a good programmer' along with converting a file into bzip file.  Opne the PHP
Issue in Converting .zip file to .jar file?
Issue in Converting .zip file to .jar file?  I have a folder called "printpdf.jar". I have changed the .jar to .zip and did some customizations. After which i had "zipped" it again and made as ".jar". Now the final file
converting pdf to ps in mutiple languages - Development process
converting pdf to ps in mutiple languages  hi deepak, i want to convert pdf in to ps. These PDF are in hindi format,these pdf are converted...). actually am converting the hindi pdf into hindi ps manuaaly, but i want
converting html to ppt,pptx - Java Beginners
converting html to ppt,pptx   Hi, i convert html to .doc format.But i want to convert the html to ppt,xml,pptx,docx,pdf.. Is there any possibility to solve this problem?  Hi Friend, We are providing you a code
converting Json data into rows of DTO in java
converting Json data into rows of DTO in java  I am using jqxgrid, and I am able to access the json data in JAVA controller. But now my requirement is to fetch every row of the grid and insert into the database. I have tried 'N
Java code for converting between .xls to .xlsx and vice versa - Java Beginners
Java code for converting between .xls to .xlsx and vice versa  I've a web application which allows clients to upload or download MS Excel sheets. I need a solution in Java from which i can upload in MS Excel 2003 and download

Ads