Tuesday, 29 November 2016

Program to accept the value of temperature in Celsius using param tag and display the temperature in Fahrenheit on Applet

In this program, we pass temperature in Celcius as a parameter to applet and get it in applet's init( ) method to convert it in Fahrenheit. After that we will display the result on applet. The formula for the conversion from Celcius to Fahrenheit is given below:
temp_in_fah = temp_in_cel * 1.8 + 32
To convert temperatures in degrees Celsius to Fahrenheit, multiply by 1.8 (or 9/5) and add 32. For example: 15°C * 1.8 + 32 = 59°F


PROGRAM
import java.awt.*;  // import awt package
import java.applet.*; // import applet package

public class CelsiFahrApplet extends Applet 
{
    String msg;
    float celsius,fahrenheit;
    
    public void init() // override init() method
    {
        msg = getParameter("Temp");  // receiving parameter value
        celsius = Float.parseFloat(msg); // Convert string to int
        System.out.println(celsius);
        fahrenheit = (1.8f * celsius)+32; // Formula F = ((9/5)*C)+32
    }
    
    public void paint(Graphics g)
    {
        g.drawString("Temperature in Fahrenheit = "+fahrenheit,10,50); // display message on applet
    }
}
/*  <applet code=CelsiFahrApplet.class height=100 width=300>
  <param name="Temp" value="15">
 </applet>*/
OUTPUT 

C:\>javac CelsiFahrApplet.java 
C:\>appletviewer CelsiFahrApplet.java



1 comment:

  1. You can find several different sorts of Temperature converter, so every one of which contains its own own intent. At the United States, the Fahrenheit scale is most commonly utilised (for example ) to record temperatures from the headlines headlines ). You are going to find it utilised if pharmacies, banks, etc.. . examine that the afternoon's fever on digital indications in your roads. It's a convenient extension for scientific query plus it's used across the globe. Other significant temperatures scale is currently Fahrenheit that's used chiefly in United States. The system for converting from Celsius to Fahrenheit is much more complex.I'm utilizing this fever converter and earn the maximum correct conversions immediately, depending on some fever scales. The worthiness at Fahrenheit might be gotten by multi ply Celsius worth by 1.8 then add 3 2. H2o freezing position are currently in 32 Fahrenheit. The very Optimal/optimally way to Have the conversion performed would be always to utilize an Internet fever converter When the temperatures drops exceeding 0 amounts, the water molecules have been losing rate, the fascination between these is slowly developing and they crystallize forming ice. We are all aware the drinking water volume is steadily currently rising after freezing. That is really since the hydrogen molecules have been exercising a fantastic allure which makes the drinking water molecules have to be ordered in a particular placement, which makes spaces between these, and also hence causing the quantity be higher compared to the amount of atoms would be the exact same.

    ReplyDelete