Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Rationale :

A temperature converter helps in the conversion of the measurement units of the


temperature recorded in a particular unit. Temperature expresses the degree of heat or
cold of a solid, liquid, or gas. Temperature is measured using a thermometer. While
Kelvin (K) is the SI unit of temperature, people generally use Centigrade or Celsius (°C)
and Fahrenheit (°F) to measure temperature.

For example, the lowest practical temperature on Earth is -273.15 degrees Celsius.
Celsius is a measure of temperature. This recording can be represented in Kelvin as 0 K.
We use temperature converter to find the different readings of a given temperature on
different unit measuring scales.

Benefits of the Micro-Project:

A temperature converter helps in the conversion of the measurement units of the


temperature recorded in a particular unit.

Temperature expresses the degree of heat or cold of a solid, liquid, or gas. Temperature
is measured using a thermometer.

While Kelvin (K) is the SI unit of temperature, people generally use Centigrade or Celsius
(°C) and Fahrenheit (°F) to measure temperature.

Course Outcomes Achieved:

a) Develop programs using GUI Framework (AWT and Swing).

b) Handle events of AWT and Swings components.

c) Develop programs to handle events in Java Programming.


Literature Review
The measurement of temperature by using appropriate sensors and controllers is not
only important in environmental or weather monitoring but also crucial for many
industrial processes. This review covers the study of PLC, microcontrollers and sensors
which will be beneficial to readers in understanding the difference between application
of PLC and Microcontrollers in controlling temperature.

Actual Methodology Followed:

Input field for the user to type in their temperature - don't forget to validate that the
input is a number!

Dropdown menu or radio button for the user to choose if they are inputting in Celsius
or Fahrenheit

"Convert" button to trigger the temperature conversion

Display area for the final converted temperature and unit

Actual Resources Used:


Sr. NO. Name of Specification Qty Remarks
Resource
1. Operating system Windows 10 1 ✔
2. Hard disk 40 GB 1 ✔
3. RAM 2 GB 1 ✔
4. Processor I3 1 ✔
Outputs of the Micro-Project:

Code :

import javax.swing.*; l2 = new JLabel("Enter the


Value:");
import java.awt.event.*;
l3 = new JLabel("Converted
Value:");
public class TC extends JFrame
l4 = new JLabel("From");
{
tc1 = new JComboBox(arr1);
JLabel l1,l2,l3,l4;
tc2 = new JComboBox(arr2);
JComboBox tc1, tc2;
t1 = new JTextField();
JTextField t1,t2;
t2 = new JTextField();
JButton b,dot,ac,bs,pm;
b = new JButton("Convert");
JButton
dot = new JButton(".");
n0,n1,n2,n3,n4,n5,n6,n7,n8,n9;
pm = new JButton("±");

bs = new JButton("<--");
public TC(String s)
ac = new JButton("AC");
{
n0 = new JButton("0");
super(s);
n1 = new JButton("1");
}
n2 = new JButton("2");

n3 = new JButton("3");
public void setComp()
n4 = new JButton("4");
{
n5 = new JButton("5");
String arr1[] =
{"Celsius","Fahrenheit","Kelvin","Rankine","R n6 = new JButton("6");
eaumur"};
n7 = new JButton("7");
String arr2[] =
{"Celsius","Fahrenheit","Kelvin","Rankine","R n8 = new JButton("8");
eaumur"}; n9 = new JButton("9");
l1 = new JLabel("To"); setLayout(null);

tc1.setBounds(75,50,100,20);
t1.setBounds(200,50,100,20); bs.addActionListener(new
Handler());
l1.setBounds(100,75,50,20);
dot.addActionListener(new
l4.setBounds(90,25,50,20);
Handler());
l2.setBounds(200,35,100,20);
n0.addActionListener(new
l3.setBounds(200,85,100,20); Handler());

tc2.setBounds(75,100,100,20); n1.addActionListener(new
Handler());
t2.setBounds(200,100,100,20);
n2.addActionListener(new
b.setBounds(138,150,100,20); Handler());

n3.addActionListener(new
ac.setBounds(238,200,50,100);
Handler());

n4.addActionListener(new
pm.setBounds(238,350,50,50);
Handler());
bs.setBounds(238,300,50,50);
n5.addActionListener(new
Handler());
dot.setBounds(188,350,50,50);
n6.addActionListener(new
n0.setBounds(88,350,100,50); Handler());
n1.setBounds(88,200,50,50); n7.addActionListener(new
Handler());
n2.setBounds(138,200,50,50);
n8.addActionListener(new
n3.setBounds(188,200,50,50);
Handler());
n4.setBounds(88,250,50,50);
n9.addActionListener(new
n5.setBounds(138,250,50,50); Handler());

n6.setBounds(188,250,50,50); add(tc1);

n7.setBounds(88,300,50,50); add(tc2);

n8.setBounds(138,300,50,50); add(l1);

n9.setBounds(188,300,50,50); add(l2);

b.addActionListener(new add(l3);
Handler());
add(l4);
ac.addActionListener(new
add(t1);
Handler());
add(t2);
pm.addActionListener(new
Handler()); add(b);
add(ac);
t1.setText(t1.getText() + "0");
add(dot);
if(e.getSource()==n1)
add(pm);

add(bs); t1.setText(t1.getText() + "1");


add(n0); if(e.getSource()==n2)
add(n1);

add(n2); t1.setText(t1.getText() + "2");

add(n3); if(e.getSource()==n3)

add(n4);
t1.setText(t1.getText() + "3");
add(n5);
if(e.getSource()==n4)
add(n6);

add(n7); t1.setText(t1.getText() + "4");

add(n8); if(e.getSource()==n5)

add(n9);
t1.setText(t1.getText() + "5");
t2.setEditable(false);
if(e.getSource()==n6)
}

t1.setText(t1.getText() + "6");
class Handler implements if(e.getSource()==n7)
ActionListener

{ t1.setText(t1.getText() + "7");
public void if(e.getSource()==n8)
actionPerformed(ActionEvent e)

{ t1.setText(t1.getText() + "8");
String x,y; if(e.getSource()==n9)
x =
(String)tc1.getSelectedItem(); t1.setText(t1.getText() + "9");
y =
(String)tc2.getSelectedItem(); if(e.getSource()==dot)

t1.setText(t1.getText() + ".");
if(e.getSource()==n0)
if(e.getSource()==ac) t1.setText("" +
bsp.substring(0,n-1));
{
}
t1.setText("");
if(e.getSource()==b)
t2.setText("");
{
}
//Both are
if(e.getSource()==pm)
same.......................
{
if(x=="Celsius"
String spm = && y=="Celsius")
new String();
{
spm =
t1.getText(); t2.setText(""+t1.getText());
if(spm.length() }
== 0)
else
if(x=="Fahrenheit" && y=="Fahrenheit")
t1.setText("-");
{
else
if(spm.charAt(0)!='-')
t2.setText(""+t1.getText());

t1.setText("-" + t1.getText()); }

else else
if(x=="Kelvin" && y=="Kelvin")
t1.setText("" + spm.substring(1)); {
}
t2.setText(""+t1.getText());
if(e.getSource()==bs)
}
{
else
int n;
if(x=="Rankine" && y=="Rankine")
String bsp =
{
new String();

bsp = t2.setText(""+t1.getText());
t1.getText();
}
n =
bsp.length(); else
if(x=="Reaumur" && y=="Reaumur")
{ {

String
t2.setText(""+t1.getText()); s = t1.getText();
} float a
= Float.parseFloat(s);

float b
//Celsius to
= (float)(a * 9/5 + 32 + 459.67);
others.........................

else
t2.setText(""+b);
if(x=="Celsius" && y=="Fahrenheit")
}
{
else
String
if(x=="Celsius" && y=="Reaumur")
s = t1.getText();
{
float a
= Float.parseFloat(s); String
s = t1.getText();
float b
= (float)((a * 9/5)+32); float a
= Float.parseFloat(s);
t2.setText(""+b); float b
= (float)(a * 0.8);
}

else
t2.setText(""+b);
if(x=="Celsius" && y=="Kelvin")
}
{

String
s = t1.getText(); //Fahrenheit
to others......................
float a
= Float.parseFloat(s); else
if(x=="Fahrenheit" && y=="Celsius")
float b
= (float)(a + 273.15); {

String
t2.setText(""+b); s = t1.getText();
} float a
= Float.parseFloat(s);
else
if(x=="Celsius" && y=="Rankine") float b
= (float)((a - 32) * 5/9);
float b
t2.setText(""+b); = (float)((a - 32)/2.25);
}
t2.setText(""+b);
else
if(x=="Fahrenheit" && y=="Kelvin") }

String //Kelvin to
s = t1.getText(); others.........................

float a else
= Float.parseFloat(s); if(x=="Kelvin" && y=="Celsius")

float b {
= (float)((a - 32) * 5/9 + 273.15);
String
s = t1.getText();
t2.setText(""+b);
float a
} = Float.parseFloat(s);

else float b
if(x=="Fahrenheit" && y=="Rankine") = (float)(a - 273.15);

{
t2.setText(""+b);
String
s = t1.getText(); }

float a else
= Float.parseFloat(s); if(x=="Kelvin" && y=="Fahrenheit")

float b {
= (float)(a + 459.67);
String
s = t1.getText();
t2.setText(""+b);
float a
} = Float.parseFloat(s);

else float b
if(x=="Fahrenheit" && y=="Reaumur") = (float)((a - 273.15) * 9/5 + 32);

{
t2.setText(""+b);
String
s = t1.getText(); }

float a else
= Float.parseFloat(s); if(x=="Kelvin" && y=="Rankine")
{
t2.setText(""+b);
String
s = t1.getText(); }

float a else
= Float.parseFloat(s); if(x=="Rankine" && y=="Fahrenheit")

float b {
= (float)(a * 9/5);
String
s = t1.getText();
t2.setText(""+b);
float a
} = Float.parseFloat(s);

else float b
if(x=="Kelvin" && y=="Reaumur") = (float)(a - 459.67);

{
t2.setText(""+b);
String
s = t1.getText(); }

float a else
= Float.parseFloat(s); if(x=="Rankine" && y=="Kelvin")

float b {
= (float)((a - 273.15) * 0.8);
String
s = t1.getText();
t2.setText(""+b);
float a
} = Float.parseFloat(s);

float b
= (float)(a/1.8);
//Rankine to
others............................
t2.setText(""+b);
else
if(x=="Rankine" && y=="Celsius") }

{ else
if(x=="Rankine" && y=="Reaumur")
String
s = t1.getText(); {

float a String
= Float.parseFloat(s); s = t1.getText();

float b float a
= (float)(( a - 32 - 459.67) / 1.8); = Float.parseFloat(s);
float b {
= (float)(( a - 32 - 459.67) / 2.25);
String
s = t1.getText();
t2.setText(""+b);
float a
} = Float.parseFloat(s);

float b
= (float)(a * 1.25 + 273.15);
//Reaumur to
others........................
t2.setText(""+b);
else
if(x=="Reaumur" && y=="Celsius") }
{ else
if(x=="Reaumur" && y=="Rankine")
String
s = t1.getText(); {
float a String
= Float.parseFloat(s); s = t1.getText();
float b float a
= (float)(a*1.25); = Float.parseFloat(s);

float b
t2.setText(""+b); = (float)(a * 2.25 + 32 + 459.67);
}
t2.setText(""+b);
else
if(x=="Reaumur" && y=="Fahrenheit") }
{ }
String }
s = t1.getText();
}
float a
= Float.parseFloat(s);
public static void main(String[] args)
float b
= (float)(a * 2.25 + 32); {

TC jf = new TC("Temperature
t2.setText(""+b); Converter");
} jf.setComp();
else jf.setSize(400,500);
if(x=="Reaumur" && y=="Kelvin")
jf.setVisible(true); jf.setDefaultCloseOperation(JFrame.EXIT_ON
_CLOSE);

Output :

Learning Outcome of this Micro-Project:


I have completed this project successfully and have successfully made a simply
implement Temperature Converter. And also used glowing effects successfully.

Applications of this Micro-Project:


 Optionally, Select a scale: Celsius or Fahrenheit.
 Enter a temperature.
 Press the Convert button to see the results.
 The User Interface is a JSF page that asks for a temperature and a scale
(Fahrenheit or Celsius).
 When you click on Convert, the temperature string is passed to the
TemperatureConverter controller (managed) bean.

Conclusion
I have successfully implemented advance java programming language to implement this
project. It was wonderful experiance for me to work on this project.

You might also like