Uploaded by chaudharyabhishekmp

App

advertisement
Temperature Converter in Java
A PROJECT REPORT
Submitted by
Abhishek Chaudhary [Reg No: RA2211003030318]
Rajat Rajput [Reg No: RA2211003030331]
Nityam Rai [Reg No: RA2211003030343]
Abhinav Tyagi [Reg No: RA2211003030310]
Under the guidance of
Mrs. Shubhangi Sharma
(Assistant Professor, Department of Computer Science & Engineering)
in partial fulfillment for the award of the
degree of
BACHELOR OF TECHNOLOGY
in
COMUTER SCIENCE & ENGINEERING
of
FACULTY OF ENGINEERING AND TECHNOLOGY
Delhi NCR campus, Modinagar, Ghaziabad (UP)
OCTOBER 2023
SRM INSTITUTE OF SCIENCE
& TECHNOLOGY
(Under Section 3 of UGC Act, 1956)
BONAFIDE CERTIFICATE
Certified that this project report titled “Temperature Converter in Java” is the
bona fide work of “Abhishek Chaudhary [Reg No: RA2211003030318], Rajat
Rajput
[Reg
No:
RA2211003030331],
Nityam
Rai
[Reg
No:RA2211003030343], Abhinav Tyagi [Reg No: RA2211003030310]”, who
carried out the project work under my supervision. Certified fur-ther, that to
the best of my knowledge the work reported herein does not form any other
project report or dissertation on the basis of which a de-gree or award was
conferred on an earlier occasion on this or any other candidate.
SIGNATURE
SIGNATURE
Mrs. Shubhangi Sharma
Dr Akash Punhani
GUIDE
Assistant Professor
Dept. of Computer Science &
Engineering
HEAD OF THE DEPARTMENT
Professor
B. Tech Second Year
Signature of the Internal Examiner
Signature of the External Examiner
ABSTRACT
The Java Temperature Converter using Swing is a sophisticated
software application developed to address the ubiquitous need for
temperature conversions across different units. This project report
unveils a comprehensive exploration of the development, design, and
functionalities
of
this
user-friendly
Java-based
application.
Temperature conversion is an everyday necessity, spanning diverse
domains such as science, engineering, meteorology, and culinary
arts. By employing the Swing framework, this application offers an
intuitive, visually appealing, and interactive solution for converting
temperatures between Celsius, Fahrenheit, and Kelvin units.
Temperature conversion, while seemingly simple, involves
intricate mathematical transformations, and this report aims to shed
light on the nuances involved in solving the inverse problem. The
inverse problem refers to the challenge of converting temperatures
across various scales and units, each having its unique zero points
and scaling factors. We delve deep into the mathematical
foundations and design considerations that underpin this project,
striving to provide a clear, elegant, and efficient solution to this
universal problem.
ACKNOWLEDGEMENTS
We would like to thank our guide, Mrs. Shubhangi Sharma, for her
valuable guidance, constant encouragement, personal caring, timely
aid and offering timely assistance as well as providing us a wonderful
environment in which to explore ourselves. Throughout the project, she
has extended bright and agreeable assistance to us, despite her hectic
schedule.
We would also want to express our gratitude to Dr Akash Punhani,
Professor and Head, Department of B Tech Second Year, SRM Institute
of Science and Technology (Delhi-NCR Campus), for his helpful
recommendations and support during the project's duration. We would
like to express our gratitude to the personnel and students at the SRM
Institute of Science and Technology's Computer Science and
Engineering Department for their assistance during our investigation.
Finally, we want to express our gratitude to our parents, family, and
friends for their unwavering love, constant assistance, and unwavering
support.
TABLE OF CONTENTS
ABSTRACT
ACKNOWLEDGEMENTS
LIST OF TABLES
1 INTRODUCTION
1.1 Inverse Problem
1.1.1 Sub sections
2 LITERATURE SURVEY
2.1 Frequency Domain SI
2.2 Particle Swarm Optimization
3 System Analysis
4 System Design
4.1 Tables and Figures
5 Coding, Testing
6 Future Enhancement
7 Conclusion
8 Reference
CHAPTER 1
INTRODUCTION
Temperature conversion is a ubiquitous and practical challenge
encountered in numerous fields, ranging from meteorology to daily
activities like cooking and home climate control. People worldwide
frequently need to convert temperatures between different units, such
as Celsius, Fahrenheit, and Kelvin, to make informed decisions or
effectively interact with diverse systems. This project addresses the
need for a user-friendly and efficient solution to this problem by
developing a Java-based temperature converter application using the
Swing framework.
2.1 Inverse Problem
The "inverse problem" in the context of temperature conversion
refers to the challenge of seamlessly converting temperatures from one
unit to another. In other words, given a temperature value in one unit,
the application needs to accurately calculate and display the equivalent
values in other units. Achieving this efficiently and accurately involves
understanding the mathematical foundations of temperature conversion
and designing an intuitive and user-friendly interface.
2.1.1 Subsection
In this subsection, we delve deeper into the complexities of the "inverse
problem" in temperature conversion. This problem can be quite intricate
when dealing with units that have different zero points and scaling
factors, such as Celsius and Fahrenheit. The subsection discusses the
mathematical formulas and algorithms used to perform temperature
conversions, highlighting the challenges and considerations that shaped
the application's design.
When it comes to temperature conversion, the core challenge is to
ensure that users can effortlessly and accurately convert temperatures
between various units, even if they are unfamiliar with the underlying
mathematical relationships. Hence, the user interface and system
design play a crucial role in addressing this challenge.
CHAPTER 2
LITERATURE SURVEY
A comprehensive literature survey is a crucial component of any project,
as it provides valuable insights into the existing solutions and best
practices within the field. In the case of our Java Temperature
Converter using Swing, the literature survey played a pivotal role in
understanding the historical context and the various approaches taken
by other developers to address temperature conversion challenges.
2.1 Historical Overview
The literature survey began with an exploration of the historical
development of temperature conversion techniques. It traced the
evolution of temperature scales, from the Celsius scale developed by
Anders Celsius in 1742 to the Fahrenheit and Kelvin scales. By
understanding the origins and principles behind these temperature
units, we gained a deeper appreciation of the complexities involved in
converting between them.
2.2 Existing Software Solutions
This section of the literature survey focused on the examination of
existing software solutions designed for temperature conversion. We
reviewed a range of applications and libraries developed in Java and
other programming languages. These tools ranged from simple
command-line utilities to more complex, feature-rich applications
with graphical interfaces.
CHAPTER 3
SYSTEM ANALYSIS
The
system
architecture
outlines
the
high-level
structure of the application, defining how its various
components interact and work together to achieve the
intended functionality. In the case of our Temperature
Converter, the architecture can be divided into the
following components:
4.1.1 User Interface (UI)
The User Interface (UI) is the front-end component that
interacts with the users. It is developed using the
Swing framework, which provides a user-friendly
graphical interface for entering temperature values,
selecting units, and displaying the conversion results.
4.1.2 Temperature Conversion Logic
This component is responsible for the core functionality
of the application, performing the actual temperature
conversions. It consists of algorithms and mathematical
formulas for converting temperatures between different
units (e.g., Celsius, Fahrenheit, Kelvin).
CHAPTER 4
SYSTEM DESIGN
CHAPTER 5
CODING, TESTING
import javax.swing.*;
import java.awt.event.*;
public class TC extends JFrame {
JLabel l1, l2, l3, l4;
JComboBox tc1, tc2;
JTextField t1, t2;
JButton b, dot, ac, bs, pm;
JButton n0, n1, n2, n3, n4, n5, n6, n7, n8, n9;
public TC(String s) {
super(s);
}
public void setComp() {
String arr1[] = { "Celsius", "Fahrenheit", "Kelvin", "Rankine", "Reaumur" };
String arr2[] = { "Celsius", "Fahrenheit", "Kelvin", "Rankine", "Reaumur" };
this.l1 = new JLabel("To");
this.l2 = new JLabel("Enter the Value:");
this.l3 = new JLabel("Converted Value:");
this.l4 = new JLabel("From");
this.tc1 = new JComboBox(arr1);
this.tc2 = new JComboBox(arr2);
this.t1 = new JTextField();
this.t2 = new JTextField();
this.b = new JButton("Convert");
this.dot = new JButton(".");
this.pm = new JButton("±");
this.bs = new JButton("<--");
this.ac = new JButton("AC");
this.n0 = new JButton("0");
this.n1 = new JButton("1");
this.n2 = new JButton("2");
this.n3 = new JButton("3");
this.n4 = new JButton("4");
this.n5 = new JButton("5");
this.n6 = new JButton("6");
this.n7 = new JButton("7");
this.n8 = new JButton("8");
this.n9 = new JButton("9");
setLayout(null);
this.tc1.setBounds(75, 50, 100, 20);
this.t1.setBounds(200, 50, 100, 20);
this.l1.setBounds(100, 75, 50, 20);
this.l4.setBounds(90, 25, 50, 20);
this.l2.setBounds(200, 35, 100, 20);
this.l3.setBounds(200, 85, 100, 20);
this.tc2.setBounds(75, 100, 100, 20);
this.t2.setBounds(200, 100, 100, 20);
this.b.setBounds(138, 150, 100, 20);
this.ac.setBounds(238, 200, 50, 100);
this.pm.setBounds(238, 350, 50, 50);
this.bs.setBounds(238, 300, 50, 50);
this.dot.setBounds(188, 350, 50, 50);
this.n0.setBounds(88, 350, 100, 50);
this.n1.setBounds(88, 200, 50, 50);
this.n2.setBounds(138, 200, 50, 50);
this.n3.setBounds(188, 200, 50, 50);
this.n4.setBounds(88, 250, 50, 50);
this.n5.setBounds(138, 250, 50, 50);
this.n6.setBounds(188, 250, 50, 50);
this.n7.setBounds(88, 300, 50, 50);
this.n8.setBounds(138, 300, 50, 50);
this.n9.setBounds(188, 300, 50, 50);
this.b.addActionListener(new Handler());
this.ac.addActionListener(new Handler());
this.pm.addActionListener(new Handler());
this.bs.addActionListener(new Handler());
this.dot.addActionListener(new Handler());
this.n0.addActionListener(new Handler());
this.n1.addActionListener(new Handler());
this.n2.addActionListener(new Handler());
this.n3.addActionListener(new Handler());
this.n4.addActionListener(new Handler());
this.n5.addActionListener(new Handler());
this.n6.addActionListener(new Handler());
this.n7.addActionListener(new Handler());
this.n8.addActionListener(new Handler());
this.n9.addActionListener(new Handler());
add(this.tc1);
add(this.tc2);
add(this.l1);
add(this.l2);
add(this.l3);
add(this.l4);
add(this.t1);
add(this.t2);
add(this.b);
add(this.ac);
add(this.dot);
add(this.pm);
add(this.bs);
add(this.n0);
add(this.n1);
add(this.n2);
add(this.n3);
add(this.n4);
add(this.n5);
add(this.n6);
add(this.n7);
add(this.n8);
add(this.n9);
this.t2.setEditable(false);
}
class Handler implements ActionListener {
public void actionPerformed(ActionEvent e) {
String x, y;
x = (String) TC.this.tc1.getSelectedItem();
y = (String) TC.this.tc2.getSelectedItem();
if (e.getSource() == TC.this.n0)
TC.this.t1.setText(TC.this.t1.getText() + "0");
if (e.getSource() == TC.this.n1)
TC.this.t1.setText(TC.this.t1.getText() + "1");
if (e.getSource() == TC.this.n2)
TC.this.t1.setText(TC.this.t1.getText() + "2");
if (e.getSource() == TC.this.n3)
TC.this.t1.setText(TC.this.t1.getText() + "3");
if (e.getSource() == TC.this.n4)
TC.this.t1.setText(TC.this.t1.getText() + "4");
if (e.getSource() == TC.this.n5)
TC.this.t1.setText(TC.this.t1.getText() + "5");
if (e.getSource() == TC.this.n6)
TC.this.t1.setText(TC.this.t1.getText() + "6");
if (e.getSource() == TC.this.n7)
TC.this.t1.setText(TC.this.t1.getText() + "7");
if (e.getSource() == TC.this.n8)
TC.this.t1.setText(TC.this.t1.getText() + "8");
if (e.getSource() == TC.this.n9)
TC.this.t1.setText(TC.this.t1.getText() + "9");
if (e.getSource() == TC.this.dot)
TC.this.t1.setText(TC.this.t1.getText() + ".");
if (e.getSource() == TC.this.ac) {
TC.this.t1.setText("");
TC.this.t2.setText("");
}
if (e.getSource() == TC.this.pm) {
String spm = new String();
spm = TC.this.t1.getText();
if (spm.length() == 0)
TC.this.t1.setText("-");
else if (spm.charAt(0) != '-')
TC.this.t1.setText("-" + TC.this.t1.getText());
else
TC.this.t1.setText("" + spm.substring(1));
}
if (e.getSource() == TC.this.bs) {
int n;
String bsp = new String();
bsp = TC.this.t1.getText();
n = bsp.length();
TC.this.t1.setText("" + bsp.substring(0, n - 1));
}
if (e.getSource() == TC.this.b) {
// Both are same.......................
if (x == "Celsius" && y == "Celsius") {
TC.this.t2.setText("" + TC.this.t1.getText());
} else if (x == "Fahrenheit" && y == "Fahrenheit") {
TC.this.t2.setText("" + TC.this.t1.getText());
} else if (x == "Kelvin" && y == "Kelvin") {
TC.this.t2.setText("" + TC.this.t1.getText());
} else if (x == "Rankine" && y == "Rankine") {
TC.this.t2.setText("" + TC.this.t1.getText());
} else if (x == "Reaumur" && y == "Reaumur") {
TC.this.t2.setText("" + TC.this.t1.getText());
}
// Celsius to others.........................
else if (x == "Celsius" && y == "Fahrenheit") {
String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) ((a * 9 / 5) + 32);
TC.this.t2.setText("" + b);
} else if (x == "Celsius" && y == "Kelvin") {
String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) (a + 273.15);
TC.this.t2.setText("" + b);
} else if (x == "Celsius" && y == "Rankine")
{ String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) (a * 9 / 5 + 32 +
459.67); TC.this.t2.setText("" + b);
} else if (x == "Celsius" && y == "Reaumur")
{ String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) (a * 0.8);
TC.this.t2.setText("" + b);
}
// Fahrenheit to others......................
else if (x == "Fahrenheit" && y == "Celsius") {
String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) ((a - 32) * 5 / 9);
TC.this.t2.setText("" + b);
} else if (x == "Fahrenheit" && y == "Kelvin")
{ String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) ((a - 32) * 5 / 9 + 273.15);
TC.this.t2.setText("" + b);
} else if (x == "Fahrenheit" && y == "Rankine")
{ String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) (a + 459.67);
TC.this.t2.setText("" + b);
} else if (x == "Fahrenheit" && y == "Reaumur") {
String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) ((a - 32) / 2.25);
TC.this.t2.setText("" + b);
}
// Kelvin to others.........................
else if (x == "Kelvin" && y == "Celsius") {
String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) (a - 273.15);
TC.this.t2.setText("" + b);
} else if (x == "Kelvin" && y == "Fahrenheit")
{ String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) ((a - 273.15) * 9 / 5 + 32);
TC.this.t2.setText("" + b);
} else if (x == "Kelvin" && y == "Rankine") {
String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) (a * 9 / 5);
TC.this.t2.setText("" + b);
} else if (x == "Kelvin" && y == "Reaumur")
{ String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) ((a - 273.15) * 0.8);
TC.this.t2.setText("" + b);
}
// Rankine to others............................
else if (x == "Rankine" && y == "Celsius") {
String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) ((a - 32 - 459.67) / 1.8);
TC.this.t2.setText("" + b);
} else if (x == "Rankine" && y == "Fahrenheit")
{ String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) (a - 459.67);
TC.this.t2.setText("" + b);
} else if (x == "Rankine" && y == "Kelvin") {
String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) (a / 1.8);
TC.this.t2.setText("" + b);
} else if (x == "Rankine" && y == "Reaumur")
{ String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) ((a - 32 - 459.67) / 2.25);
TC.this.t2.setText("" + b);
}
// Reaumur to others........................
else if (x == "Reaumur" && y == "Celsius") {
String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) (a * 1.25);
TC.this.t2.setText("" + b);
} else if (x == "Reaumur" && y == "Fahrenheit") {
String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) (a * 2.25 + 32);
TC.this.t2.setText("" + b);
} else if (x == "Reaumur" && y == "Kelvin")
{ String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) (a * 1.25 +
273.15); TC.this.t2.setText("" + b);
} else if (x == "Reaumur" && y == "Rankine") {
String s = TC.this.t1.getText();
float a = Float.parseFloat(s);
float b = (float) (a * 2.25 + 32 + 459.67);
TC.this.t2.setText("" + b);
}
}
}
}
public static void main(String[] args) {
TC jf = new TC("Temperature Converter");
jf.setComp();
jf.setSize(400, 500);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
CHAPTER 6
FUTURE ENHANCEMENT
The future enhancements section outlines several potential avenues for
improving and extending the functionality of the Java Temperature
Converter developed using the Swing framework.
Additional Temperature Units: Currently, the application supports
conversion between Celsius, Fahrenheit, and Kelvin. To make it even
more versatile, future enhancements could include the addition of other
temperature units such as Rankine and Réaumur. This expansion would
cater to a broader range of users with different temperature scale
preferences.
Custom Unit Conversions: Offering the ability for users to define and
convert to custom temperature units would be a valuable feature. This
could be accomplished by allowing users to input the conversion
formula and units, making the application adaptable to specialized
scenarios or industries.
Real-Time Data Integration: To make the application more dynamic
and useful for various purposes, consider integrating real-time
temperature data from online sources or sensors. Users could choose
to convert temperatures from live data streams, providing up-to-theminute information.
Historical Temperature Data: Allow users to convert historical
temperature data. This feature could be beneficial for researchers,
historians, and data analysts. Users could input dates and locations
to retrieve historical temperature values and then convert them to
their preferred units.
CHAPTER 7
CONCLUSION
In conclusion, the development of the Java temperature converter
using Swing has been a significant and rewarding endeavour. This
project aimed to provide a practical, user-friendly solution for
temperature conversions across various units, including Celsius,
Fahrenheit, and Kelvin. The following key points highlight the
accomplishments and significance of this project:
User-Friendly Interface: The Swing framework was employed to
create an intuitive and user-friendly interface. Users can easily input a
temperature value in one unit and obtain its equivalents in other units.
The graphical interface enhances the application's accessibility and
usability.
Mathematical Foundations: The project addressed the challenging
inverse problem of temperature conversion, involving different zero
points and scaling factors. Detailed discussions and implementation
of mathematical formulas and algorithms were provided, ensuring the
accuracy of temperature conversions.
Extensive Testing: Rigorous testing methodologies were employed to
validate the application's accuracy and reliability. This included test
cases for various temperature values and units, ensuring that the
application consistently delivered precise results.
Literature Review: The project involved a comprehensive literature
survey, which not only informed the development process but also
highlighted the unique contributions of this project within the realm of
temperature conversion applications.
CHAPTER 8
REFERENCE
[Deitel, P. J., & Deitel, H. M. (2014). Java: How to Program (Early Objects). Pearson].
[Eckel, B. (2006). Thinking in Java. Prentice Hall.]
[Liang, Y. D. (2014). Introduction to Java Programming, Comprehensive Version.
Pearson]
[Horstmann, C. S., & Cornell, G. (2013). Core Java, Volume I--Fundamentals. Prentice
Hall.]
[Oracle Documentation. (https://docs.oracle.com/javase/8/docs/)]
[Swing (Java). Wikipedia. (https://en.wikipedia.org/wiki/Swing_(Java))]
Download