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

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
        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">


Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.

Program to input age from user and throw user-defined exception if entered age is negative