0% found this document useful (0 votes)
124 views

Java Project

This document contains code and documentation for a Java currency converter project created by five students. The project allows users to enter an amount and select different currencies to convert from and to. It connects to a Google API to retrieve live currency exchange rates in JSON format and displays the converted amount. The code includes a servlet that handles requests and parsing of the API response. Documentation provides an introduction to Java, servlets, JSP and the purpose and scope of the currency converter application.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views

Java Project

This document contains code and documentation for a Java currency converter project created by five students. The project allows users to enter an amount and select different currencies to convert from and to. It connects to a Google API to retrieve live currency exchange rates in JSON format and displays the converted amount. The code includes a servlet that handles requests and parsing of the API response. Documentation provides an introduction to Java, servlets, JSP and the purpose and scope of the currency converter application.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

WINTER SEMESTER 2021-2022

JAVA Project Slot: B2


Course Code & Title: CSE1007- JAVA Programming
Adithiyan Rajan – 20BCE0329
Ishanvi Sharma – 20BCE0394
Anish Samir Patankar – 20BCE0398
Arya Jay Wadhwani – 20BCE0399
Parth Sunil Chavan – 20BCI0055

This is the currency converter or it is also called as currency exchange. This project is
basically a web-based interface which helps person to change their money from one state to
another state or we can say that it helps in exchanged the money from their original state.

Abstract -We all know that every country uses different currency system, so when person is
travel from one place to another or when person transfer the money from one country to another
country then everyone needs to convert their currency, by keeping this thought in the mind, I
develop the currency convertor or currency exchange system in java programming language.
It is simple calculator like application. This application is so convenient that’s why anybody
can use it. Most probably this application is used in share market, Business strategy and many
more. The currency convertor has a simple interface in which user can enter the amount and
choose the changes by dropdown list.

Purpose:

Currently we are needed to recognize the amount of the currency and to convert it manually.
This is stressful especially to people who aren’t so smart in calculations. So, this project is
developed to replace human power to recognize the amount of the currency.

Currency converter system is implemented to reduce human power to automatically


recognize the amount of currency and convert it into the other currency without human
supervision. Easily accessible online currency converter is very useful to show travelers how
their own currencies will fare when exchanged with other foreign currency. Moreover,
currency converters help international import and export businesses by helping them
determine the selling and buying profits of different products.

Scope:

Many business people use this tool in the import/export business to determine the selling and
buying profits of various products. With an online converter, a trader can identify the
difference in making or losing money. All kinds and types of businesses can use online
currency converters for quick and effective results. As a trader, you can use a converter to get
a good estimate of what your foreign trip would cost while traveling abroad.

Introduction to Java
• Java is Object oriented, Multi-threading language developed by Sun Microsystems in
1991.

• It is designed to be small, simple and portable across different platforms as well as OS.

Features of Java:
Syntax based on C++
• Object-oriented

• Support for Internet applications

• Extensive library of prewritten classes

• Portability among platforms

• Built-in networking security as JRE is inaccessible to other parts of computer

Java Programs:
• Applets:

• Small programs designed to add interactivity to Web sites

• Downloaded with the Web page and launched by the Internet browser

• Servlets :

• Run by Web server on the server

• Typically generate Web content

• Applications:
• Programs that run standalone on a client

Java Servlets:
• Servlets are server side applets that are loaded and executed by a web server in the same
manner that applets are loaded and executed by a web browser.

• Java Servlets are useful to create Dynamic pages. Depending upon my input server will
give an output

Features of Servlets:
• Database Connectivity

o Insert/Update/delete/drop

o Select

• Servlets Chaining

• Server Side Includes

• Applet Servlet Communication

• Inter-servlet Communication

• Page Compilation

• Session Tracking

JSP:
Introduction:
• As a Java-based technology, it enjoys all of the advantages that the java language
provides with respect to development and deployment.

• JSP runs on major web platforms.


• Client (web browser) makes a request via an HTTP.

• The web server receives the request and sends it to the Servlets/JSP engine. If the
Servlets/JSP is not loaded, the web server will load it into the JVM and execute it.

• Web server returns response to the Client.

JSP Directives: They generate side effects that are change the way the JSP container
processes the page.

Implicit Objects:

• Request

• Response
• Session

• Application

• Page Context

• Exception

JSP Actions: The JSP actions allow the transfer of control between pages.
• Forward
• Include
• Plug-in

Code :
https://github.com/Arya-
Wadhwani07/CurrencyConverter/tree/master/Currency%20Con
verter/nbproject

convert.java
package com.exchange;

import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.InputStream;
import java.net.*;
import com.google.gson.*;

/**
*
* @author pakallis
*/
class Recv
{
private String lhs;
private String rhs;
private String error;
private String icc;
public Recv()
{

}
public String getLhs()
{
return lhs;
}
public String getRhs()
{
return rhs;
}
}
public class Convert extends HttpServlet {

/**
* Processes requests for both HTTP <code>GET</code> and
<code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
String query = "";
String amount = "";
String curTo = "";
String curFrom = "";
String submit = "";
String res = "";
HttpSession session;
resp.setContentType("text/html;charset=UTF-8");
PrintWriter out = resp.getWriter();

/*Read request parameters*/


amount = req.getParameter("amount");
curTo = req.getParameter("to");
curFrom = req.getParameter("from");

/*Open a connection to google and read the result*/


try {

query = "http://www.google.com/ig/calculator?hl=en&q=" + amount


+ curFrom + "=?" + curTo;
URL url = new URL(query);
InputStreamReader stream = new
InputStreamReader(url.openStream());
BufferedReader in = new BufferedReader(stream);
String str = "";
String temp = "";

while ((temp = in.readLine()) != null) {


str = str + temp;
}

/*Parse the result which is in json format*/


Gson gson = new Gson();
Recv st = gson.fromJson(str, Recv.class);
String rhs = st.getRhs();
rhs = rhs.replaceAll("�", "");

/*we do the check in order to print the additional


word(millions,billions etc)*/
StringTokenizer strto = new StringTokenizer(rhs);
String nextToken;
out.write(strto.nextToken());
nextToken = strto.nextToken();
if( nextToken.equals("million") || nextToken.equals("billion")
|| nextToken.equals("trillion"))
{
out.println(" "+nextToken);
}

} catch (NumberFormatException e) {
out.println("The given amount is not a valid number");
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods.


Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}

package com.exchange;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

public class HTTPXMLTest


{
/* public static void main(String[] args)
{
try {
new HTTPXMLTest().start();
} catch (Exception e) {
e.printStackTrace();
}
}*/
String currency[];
void start() throws Exception
{
URL url = new
URL("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
URLConnection connection = url.openConnection();

Document doc = parseXML(connection.getInputStream());


NodeList descNodes = doc.getElementsByTagName("Cube");
for(int i=0; i<descNodes.getLength();i++)
{
currency[i] = new String();
currency[i] =
descNodes.item(i).getAttributes().getNamedItem("currency").toString();

}
}

private Document parseXML(InputStream stream)


throws Exception
{
DocumentBuilderFactory objDocumentBuilderFactory = null;
DocumentBuilder objDocumentBuilder = null;
Document doc = null;
try
{
objDocumentBuilderFactory =
DocumentBuilderFactory.newInstance();
objDocumentBuilder =
objDocumentBuilderFactory.newDocumentBuilder();

doc = objDocumentBuilder.parse(stream);
}
catch(Exception ex)
{
throw ex;
}

return doc;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.web.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/web-project/3">
<name>CurrencyExchangeV3</name>
<minimum-ant-version>1.6.5</minimum-ant-version>
<web-module-libraries>
<library dirs="200">
<file>${file.reference.gson-2.0_1.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
</web-module-libraries>
<web-module-additional-libraries/>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

SNAPSHOTS:

You might also like