Sei sulla pagina 1di 24

CHAPTER 1

INTRODUCTION

Initially we need to download and install the Java software i.e. JDK for windows and
set the path in the environment variables. After this download and install Intellij IDEA
for windows in order to creating softwares using JDK and creating java programs.

In order to understand this project, you need to be at least used to program


the java basic concepts such as looping, array, list and also basic concepts of
controls such as label, textfield, choicebox and buttons. The code consists of three
files namely main class, fxml file, controller class. In main class we will call the
controller class. Main class is used to create menubar. Controller class implements
intialisable interface which initialises the controls using their id.

FXML file consists of two fields namely: text and scene builder. Insertion of
containers and controls takes place in the scene builder. Intellij idea software gives
the code automatically in the text field based on the insertion in scene builder.

1.1. INTRODUCTION
Java is a general-purpose, concurrent, class-based, object-oriented computer
programming language that is specifically designed to have as few implementation
dependencies as possible. It is intended to let application developers "write once, run
anywhere" (WORA), meaning that code that runs on one platform does not need to
be recompiled to run on another. Java applications are typically compiled to byte
code (class file) that can run on any Java virtual machine (JVM) regardless of
computer architecture. Java is, as of 2012, one of the most popular programming
languages in use, particularly for client-server web applications, with a reported 10
million users. Java was originally developed by James Gosling at Sun Microsystems
(which has since merged into Oracle Corporation) and released in 1995 as a core
component of Sun Microsystems' Java platform. The language derives much of its
syntax from C and C++, but it has fewer lowlevel facilities than either of them. Java
can be used to write applications and applets. A Java application is similar to any
other high-level language program: It can only be compiled and then run on the

1
same machine. An applet is compiled on one machine, stored on a server in binary,
and can be sent to another machine over the Internet to be interpreted by a Java-
aware browser. Java comes with a large library of ready-made classes and objects.
The key difference between Java 1.0 and 1.1 was in this library. Similarly, Java 2.0
has a very much larger library for handling user interfaces (Swing by name) but only
small changes to the core of the language.

1.2 OBJECT ORIENTED PROGRAMMING


Java supports object-oriented programming techniques that are based on a
hierarchy of classes and well-defined and cooperating objects.

1.2.1 Classes:
A class is a structure that defines the data and the methods to work on that
data. When you write programs in Java, all program data is wrapped in a class,
whether it is a class you write or a class you use from the Java API libraries. Classes
in the Java API libraries define a set of objects that share a common structure and
behavior.

1.2.2 Objects:
An instance is a synonym for object. A newly created instance has data
members and methods as defined by the class for that instance.

1.2.3 Well-Defined Boundaries and Cooperation:


Class definitions must allow objects to cooperate during execution.

1.2.4 Inheritance and Polymorphism:


One object-oriented concept that helps objects work together is inheritance.
Inheritance defines relationships among classes in an object-oriented language. The
relationship is one of parent to child where the child or extending class inherits all the
attributes (methods and data) of the parent class. In Java, all classes descend from
java.lang.Object and inherit its methods.
1.2.5 Encapsulation and Data Abstraction:

2
Wrapping of data members and methods into a single unit is called
Encapsulation. The process of hiding data from outside world is called Data hiding.
Class acquires the data hiding concept by using data abstraction i.e.,using a thing
without knowing background details.

1.3.ABOUT THE TEMPERATURE CONVERTER TOOL

Temperature is a measure of how hot or cold something is; specifically, a measure


of the average kinetic energy of the particles in an object, which is a type of energy
associated with motion. But how hot is hot, and how cold is cold? The terms hot and
cold are not very scientific terms. If we really want to specify how hot or cold
something is, we must use temperature. For instance, how hot is melted iron? To
answer that question, a physical scientist would measure the temperature of the
liquid metal. Using temperature instead of words, like hot or cold, reduces confusion.

Since molecules are so small, you must use an indirect method to measure the
kinetic energy of the molecules of a substance. As heat is added to a substance, the
molecules move more rapidly. This increased motion causes a small increase in the
volume, or amount of space, taken up by most materials. There are devices that use
the expansion of a substance to give an indirect measure of temperature. Such
devices are called thermometers.

There are many types of thermometers. Many thermometers are thin glass tubes
filled with a liquid. Mercury and alcohol are often used in thermometers because the
remain liquids over a large temperature range. A change in temperature causes a
small change in the volume of the liquid. However, this effect is magnified when the
liquid expands in the very thin tube of the thermometer.

Some thermometers, often used on the outside of aquariums, contain liquid crystals
that change color based on temperature. As temperature increases, the molecules of
the liquid crystal bump into each other more and more. This causes a change in the
structure of the crystals, which in turn affects their color. These thermometers are
able to accurately determine the temperature between 65 F and 85 F.

3
CHAPTER 2
LITERATURE SURVEY

2.1 JAVA
Java is recently widely used software for developing Android Applications. It
was developed by James Gosling and his colleagues. It is a Object Oriented
language. It can accomplish all sorts of tasks and solve the problems of other
programming languages such as C++,BASIC, and so on.

2.2 IMPLEMENTATIONS

2.2.1 Import packages


Import all packages related to controller class and main class. For running
the java program in a device which can run java programs occurs in two phases
namely compile time phase and runtime phase. In compile time phase only the
program gets converted to byte code which is done by JDK(Java Development Kit)
which is a complete kit for java programs. In runtime phase we can execute the
programs in device which is done by JRE(Java Runtime Environment) which
contains JVM(Java Virtual Machine).Java is platform independent i.e., java programs
once coded can run on any platform. Some of the java features which makes it
suitable for developing android applications are Polymorphism, Inheritance,
Abstraction, Encapsulation and data hiding, robust and multi-threaded language. We
can also create applets using java.These are the reasons of usage of Java in
building the game application CONNECT FOUR from scratch.

2.3 HISTORY OF THE TEMPERATURE

The idea of measuring temperature exists a long time. One of the first who wanted to
make a temperature scale was Galen (ca. 170). He had a scale of 4 degrees warmth
and 4 degrees of cold. The earlier measurement instruments for temperature where
called thermo scopes. In 1610 Galileo introduced wine in the thermo scopes instead
of air. In 1724 Gabriel Fahrenheit introduced the medium mercury in the thermo
scopes. The reason that mercury was used is that the thermal expansion of mercury

4
is large, mostly homogeneous and it does not stick on the glass. Mercury also stays
in the liquid phase for a great range of temperature. It is also easy to read.

2.4 PRESENT TEMPERATURE SCALES:

Present temperature scales have two basic points: from when the water starts to
freeze and when it starts to boil. Between these two temperatures a scale is made.
The two most popular scales are the Celsius (made by Anders Celsius) and
Fahrenheit (made by Gabriel Fahrenheit) scale. The Fahrenheit scale is defined so
that the melting point of water lays by 32 degrees Fahrenheit and the boiling point
lays by 212 degrees Fahrenheit. This means that between the freezing point and
boiling point there are 180 divisions. Fahrenheit introduced his scale in 1724.

Another scale is the Celsius scale. In the Celsius scale the freezing point of water is
set at 0 degrees (centigrade) and the boiling point at 100 degrees (centigrade). This
scale exists on 100 divisions, also known as centiscale. In 1948 the centidegrees
(centigrade scale) were replaced by the degrees Celsius ( oC). The Celsius scale is
defined by the following two points:

1. The triple point of water is defined at 0.01 oC.

2. One degree Celsius equals the change of temperature with one degree on the
ideal gas-scale.

On the Celsius-scale the boiling point of water with a pressure of 1 atmosphere is set
at 99.975 oC. With the centiscale it was 100.

2.5 SI TEMPERATURE SCALE

Temperature is related with the kinetic energy of the molecules. The kinetic energy
changes when the temperature changes. Temperature is defined as the translation of
heath between two objects. The fundamental temperature scale is the one of Kelvin.
The temperature scale of Kelvin depends of the absolute zero point. This is the point
where the molecules do not move anymore, so they do not give warmth. This is for

5
all molecules. The absolute zero point is by 0 K, this is -273.15 oC. The scale is the
same as the Celsius.

6
CHAPTER 3
AIM AND SCOPE OF PROJECT

3.1 INSTALLATION GUIDES


Here, the installation process of both JDK and intellij idea is explained.

3.1.1 Installing JDK


Go to chrome and download JDK(a software development environment for
developing java apps) for windows. To check whether the JDK is installed or not,
open command prompt and type javac. If all library files are found then jdk is
installed or otherwise add the java variable in environment variables.

3.1.2 Installing IntelliJ IDEA


Go to chrome and download IntelliJ IDEA for windows and install the same.
Intellij IDEA is a Integrated development kit for creating softwares using JDK. In this
there are two fields namely fxml file and scene builder in which we can design the
applications without code.

3.2 AIM AND SCOPE OF PROJECT

The aim of the project consisted of creating a JAVA script for Temperature converter
tool. It consists of file menu and help menu which gives the application information.
Here we are using IntelliJ idea software for developing java applications. In fxml file
we use VBox which arranges the fields in vertical order, Label which tells about the
label of the application, ChoiceBox which will have six choices to select the desired
one to convert the temperature, Textfield which takes the text from the user, Button
to convert the temperature. Here, two classes are used namely main which extends
application class and controller which is used to convert the temperature and it is
linked with the fxml file to create the application. Finally this project is used to convert
from one temperature to another temperature.

7
3.3 OBJECTIVES OF THE PROJECT

Temperature measurement in today’s industrial environment encompasses a wide


variety of needs and applications. To meet this wide array of needs the process
controls industry has developed a large number of sensors and devices to handle
this demand. In this experiment you will have an opportunity to understand the
concepts and uses of many of the common transducers, and actually run an
experiment using a selection of these devices. Temperature is a very critical and
widely measured variable for most mechanical engineers. Many processes must
have either a monitored or controlled temperature. This can range from the simple
monitoring of the water temperature of an engine or load device, or as complex as
the temperature of a weld in a laser welding application. More difficult measurements
such as the temperature of smoke stack gas from a power generating station or blast
furnace or the exhaust gas of a rocket may be need to be monitored. Much more
common are the temperatures of fluids in processes or process support applications,
or the temperature of solid objects such as metal plates, bearings and shafts in a
piece of machinery.

3.4 SAMPLE INPUT AND OUTPUT

3.4.1 Input

As soon as the user runs the program the conversion will start and there will be a
option window asking the user for the following:
1) Choice Box
2) Text Field to enter user temperature
3) Button which converts when clicked
4) File menu to start new conversion or to quit
5) Help menu to know about the developer

8
3.4.2 Output

On the click of the mouse in the choice box we can select the temperature
conversion label. On click on the textfield we can enter the user temperature. On
click of button convert, the temperature will be converted as per selection in the
choice box and displayed in the alert dialog box like message box. Clicking on file
menu, we can start the new conversion or quit the application. Clicking on the help
menu, we can know about the developer of the application.

9
CHAPTER 4
SYSTEM REQUIREMENTS

The system requirements(both hardware and software) used in developing Connect


four game is given below:

4.1 SOFTWARE REQUIREMENTS


Here, the software requirements are specified.

4.1.1 Operating systems

Here, the operating systems used is Windows 10 because of its speed, cortona,
action centre, security and various other features.

4.1.2 IntelliJ Idea

Intellij Idea is an Integrated Development Kit for creating softwares using JDK. It is
user friendly environment. In this, without any code we can design an application
using scene builder which automatically writes code based on the design of
application. It also contains FXML file in which specification of graphical
symbols(pane, gridpane, etc) is done.

4.1.3 JDK(Java Development Kit)

JDK is software development environment for developing Java applications. It is


used for software installation of Java. JDK contains compiler which is used to
convert Java code to Byte code. It contains the complete kit for Java development. It
is also defined as Java Runtime Environment plus some development tools such as
compiler.

10
4.1.4 Methodology

Here, in this temperature converter tool we are using two classes namely main class
and controller class. Main class contains all declarations like creating menubar, start
method, it extends application class. Controller class is declared here. At last in main
function launching of arguments is done.
Controller class implements intialiasable interface. Here the controllers like
text field, choice box, button, label are declared based on the code which are given
in the fxml file. Convert function is declared in the initialise method of controller class.
The convert function is defined below which consists of the code of converting one
temperature to another and vice versa. After a display method is present which
displays the new temperature in a dialog box which is done using alert dialog class.
At last we have warnuser function which warns the user if an invalid temperature is
entered.
private void convert() {
String input = userInputField.getText();
double enteredTemperature = 0.0f;
try {
enteredTemperature = Double.parseDouble(input);
} catch (Exception e) {
warnUser();
return;
}
double newTemperature = 0.0f;

enteredTemperature = Double.parseDouble(input);

if (isC_TO_F) {
newTemperature = (enteredTemperature * 9 / 5) + 32;
} else if(isF_TO_C) {
newTemperature = (enteredTemperature - 32) * 5 / 9;
}
//display(newTemperature);

else if(isC_TO_K){
newTemperature=(enteredTemperature)+273.15;
}else if(isK_TO_C){
newTemperature=(enteredTemperature)-273.15;
}
//display(newTemperature);
else if(isF_TO_K){
newTemperature=(enteredTemperature-32)*5/9+273.15;
}else if(isK_TO_F){

11
newTemperature=(enteredTemperature-273.15)*9/5+32;
}

display(newTemperature);
}

The above code is to convert from one temperature to another temperature and vice
versa.
private void display(double newTemparature) {
String unit=isC_TO_F?"F":"C";
String unit1=isC_TO_K?"C":"K";
String unit2=isF_TO_K?"F":"K";
System.out.println("The New Tempearture is"+newTemparature+unit);
Alert alert=new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Result");
alert.setContentText("The New Temperature is"+newTemparature+unit);
alert.setContentText("The New Temperature is"+newTemparature+unit1);
alert.setContentText("The New Temperature is"+newTemparature+unit2);
alert.show();
}

The above function display is used to display the new temperature in a dialog box
which is done using alert dialog class.
private void warnUser() {
Alert alert=new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error occured");
alert.setHeaderText("Invalid Temperature");
alert.setContentText("Please enter a valid temperature");
alert.show();
}

The above code is used to warn the user whether the user entered temperature is
valid or not.

12
4.2 Hardware requirements

The hardware requirements required here are Personal Computer, printer if needed,
mouse and keyboard. The hardware requirements may serve as the basis for a
contract for the implementation of the system and should therefore be a complete
and consistent specification of the whole system. They are used by software
engineers as the starting point for the system design. It shows what the systems do
and not how it should be implemented.
Hardware : Intel i5

RAM : 8GB (minimum)

13
CHAPTER 5

SUMMARY AND CONCLUSION

5.1 SUMMARY
I succeeded in achieving the goals we set out for ourselves, namely to
make temperature converter tool using JAVA that provides realistic conversion of
temperature. JAVA is well suited to support software for simple applications such as
TEMPERATURE CONVERTER TOOL and the project was manageable. Debugging
was necessary throughout the coding process, but often the problems we
encountered required only logic to understand how our code had misinterpretation.
However the skills we gained in FXML and loops could support further work in
creating game software using JAVA.

5.2 CONCLUSION
This report presents an introduction to Java and how Java is used to build
application and what are the tools that can be used to develop application and insert
controllers. This was an introduction to the main goal of our report that is design and
development of Temperature Converter Tool to be shared and used by users. Here, I
created a jar file of temperature converter application by which we can export the
application from the desktop to any other personal computer.

14
REFERENCES

1. JAVA A BEGINNER’S GUIDE, BY HERBERT SCHILDT, 8 th EDITION,


COVERS COMPLEX CONCEPTS LIKE LAMBDA EXPRESSIONS AND
FUNCTIONAL INTERFACES.

2. THE COMPLETE REFERENCE JAVA, BY HERBERT SCHILDT, 7 th


EDITION.

3. THE COMPLETE REFERENCE JAVA 2, BY HERBERT SCHILDT, 5 th


EDITION.

4. https://trainings.internshala.com/java-training accessed on May 2019.

5. http://www.sathyabama.ac.in/classnotes_view.php accessed on May 2019.

APPENDIX
(a) Code
(b)Screenshots

(a) Code

a.1 Main Class

15
package sample;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.util.Optional;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
FXMLLoader loader=new
FXMLLoader(getClass().getResource("app_layout.fxml"));
VBox rootNode=loader.load();
MenuBar menuBar=createMenu();
rootNode.getChildren().add(0,menuBar);
Scene scene=new Scene(rootNode);
primaryStage.setTitle("Temparature Converter Tool");
primaryStage.setScene(scene);
primaryStage.show();
}
private MenuBar createMenu(){
Menu fileMenu=new Menu("File");
MenuItem newMenuItem=new MenuItem("New");
newMenuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("New Menu");
}
});
SeparatorMenuItem separatorMenuItem=new SeparatorMenuItem();
MenuItem quitMenuItem=new MenuItem("Quit");
quitMenuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
Platform.exit();
System.exit(0);
}
});
fileMenu.getItems().addAll(newMenuItem,separatorMenuItem,quitMenuItem);
Menu helpMenu=new Menu("Help");
MenuItem aboutApp=new MenuItem("About");
aboutApp.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
aboutApp();
}

16
});
helpMenu.getItems().addAll(aboutApp);
MenuBar menuBar=new MenuBar();
menuBar.getMenus().addAll(fileMenu,helpMenu);
return menuBar;
}

private void aboutApp() {


Alert alertDialog=new Alert(Alert.AlertType.INFORMATION);
alertDialog.setTitle("My first desktop");
alertDialog.setHeaderText("Learning javafx");
alertDialog.setContentText("Iam just a beginer");
ButtonType yesBtn=new ButtonType("Yes");
ButtonType noBtn=new ButtonType("No");
alertDialog.getButtonTypes().setAll(yesBtn,noBtn);
Optional<ButtonType> clickedBtn=alertDialog.showAndWait();
if(clickedBtn.isPresent()&&clickedBtn.get()==yesBtn){
System.out.println("Yes");
}
else
{
System.out.println("No");
}
}

public static void main(String[] args) {


launch(args);
}
}

a.2 Controller Class

package sample;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import java.net.URL;
import java.util.ResourceBundle;
public class Controller implements Initializable {
@FXML
public Label welcomeLabel;
@FXML
public ChoiceBox<String> choiceBox;
@FXML
public TextField userInputField;
@FXML

17
public Button convertButton;
private static final String C_TO_F="Celsius to Fahrenheit";
private static final String F_TO_C="Fahrenheit to Celsius";
private static final String C_TO_K="Celsius to Kelvin";
private static final String K_TO_C="Kelvin to Celsius";
private static final String F_TO_K="Fahrenheit to Kelvin";
private static final String K_TO_F="Kelvin to Fahrenheit";
private boolean isC_TO_F=true;
private boolean isF_TO_C=true;
private boolean isC_TO_K=true;
private boolean isK_TO_C=true;
private boolean isF_TO_K=true;
private boolean isK_TO_F=true;
@Override
public void initialize(URL location, ResourceBundle resources) {
choiceBox.getItems().add(C_TO_F);
choiceBox.getItems().add(F_TO_C);
choiceBox.getItems().add(C_TO_K);
choiceBox.getItems().add(K_TO_C);
choiceBox.getItems().add(F_TO_K);
choiceBox.getItems().add(K_TO_F);
choiceBox.setValue(C_TO_F);
choiceBox.getSelectionModel().selectedItemProperty().addListener(new
ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable,
String oldValue, String newValue) {
if (newValue.equals(C_TO_F)) {
isC_TO_F = true;
} else if(newValue.equals(F_TO_C)){
isF_TO_C = true;
}
else if(newValue.equals(C_TO_K)){
isC_TO_K=true;
}else if(newValue.equals(K_TO_C)){
isK_TO_C=true;
} else if(newValue.equals(F_TO_K)){
isF_TO_K=true;
}else{
isF_TO_K=false;
}
}
});
convertButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
convert();
}
});
}

18
private void convert() {
String input = userInputField.getText();
double enteredTemperature = 0.0f;
try {
enteredTemperature = Double.parseDouble(input);
} catch (Exception e) {
warnUser();
return;
}
double newTemperature = 0.0f;

enteredTemperature = Double.parseDouble(input);

if (isC_TO_F) {
newTemperature = (enteredTemperature * 9 / 5) + 32;
} else if(isF_TO_C) {
newTemperature = (enteredTemperature - 32) * 5 / 9;
}
//display(newTemperature);

else if(isC_TO_K){
newTemperature=(enteredTemperature)+273.15;
}else if(isK_TO_C){
newTemperature=(enteredTemperature)-273.15;
}
//display(newTemperature);
else if(isF_TO_K){
newTemperature=(enteredTemperature-32)*5/9+273.15;
}else if(isK_TO_F){
newTemperature=(enteredTemperature-273.15)*9/5+32;
}

display(newTemperature);
}
private void display(double newTemparature) {
String unit=isC_TO_F?"F":"C";
String unit1=isC_TO_K?"C":"K";
String unit2=isF_TO_K?"F":"K";
System.out.println("The New Tempearture is"+newTemparature+unit);
Alert alert=new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Result");
alert.setContentText("The New Temperature is"+newTemparature+unit);
alert.setContentText("The New Temperature is"+newTemparature+unit1);
alert.setContentText("The New Temperature is"+newTemparature+unit2);
alert.show();
}
private void warnUser() {
Alert alert=new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error occured");

19
alert.setHeaderText("Invalid Temperature");
alert.setContentText("Please enter a valid temperature");
alert.show();
}

20
(b) Screenshots

b.1 The look of the application

b.2 The look of choicebox and its contents

21
b.3 The look of file menu in the menubar

22
b.4 The look of help menu in menubar

b.5 The conversion of one temperature to another temperature

b.6 The warning of invalid temperature

23
24

Potrebbero piacerti anche