CURRENCY CONVERTER
USING JAVA
This currency converter is a mini-Java project that
provides a web-based interface for
exchanging/converting money from one currency to
another. It is developed using Ajax, Java servlets web
features. Such applications have been used in the
business industry.
Program:
package [Link];
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
import [Link].*;
* @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;
[Link]("text/html;charset=UTF-8");
PrintWriter out = [Link]();
/*Read request parameters*/
amount = [Link]("amount");
curTo = [Link]("to");
curFrom = [Link]("from");
/*Open a connection to google and read the result*/
try {
query = " hl=en&q=" + amount + curFrom + "=?" + curTo;
URL url = new URL(query);
InputStreamReader stream = new
InputStreamReader([Link]());
BufferedReader in = new BufferedReader(stream);
String str = "";
String temp = "";
while ((temp = [Link]()) != null) {
str = str + temp;
}
/*Parse the result which is in json format*/
Gson gson = new Gson();
Recv st = [Link](str, [Link]);
String rhs = [Link]();
rhs = [Link]("�", "");
/*we do the check in order to print the additional
word(millions,billions etc)*/
StringTokenizer strto = new StringTokenizer(rhs);
String nextToken;
[Link]([Link]());
nextToken = [Link]();
if( [Link]("million") || [Link]("billion") ||
[Link]("trillion"))
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>