Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • May 02, 2016, 05:42:38 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Plz tell me how can i bring high quality to this Java code. it's urgent  (Read 3079 times)

simsim00

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 2
    • View Profile
    • Donate to Member
well, i have written this code for the problem give below. Plz help me to bring high quality to this i.e use of Hungarian Notation and commnts as required in the problem given below:
Problem:
Writing a maintainable code makes the product with High Quality. Here you are given a scenario where you have to write a maintainable code for the given problem.

Scenario:


Virtual Solutions is an IT solution provider company. It has hired you as a Software Engineer. Your job is to write code, but at the same it should be of High Quality.  Your Team Lead has asked you to write a very small code of user login functionality. The code should be of High Quality.

You are required to

a.   Write correct code for the user login in Java or C++
b.   Make use of Hungarian Notation for coding purpose
c.   Make use of Comments in the Code where required necessary.


code

<html>
<head>
<title>Khalid Mahmood   </title>
</head>

<body>
<br>
 <p> <h3><center>Please enter your user name and
 password</center></h3></p>

 <br>
 <br>
 <form  action="process2.jsp "    method = "post" >
 <center>username</center>
 <center><input type = "text" name=
 "username"></center>
 <center>password</center>
 <center><input type = "password" name =
 "password"></center>
 <center><input type="submit"     name="Submit"
 value="Login"></center>


 </form>

 </body>
 </html>








<%@ page import="java.util.*" %>
<jsp:useBean id="idHandler" class="foo.Login" scope="request">
<jsp:setProperty name="idHandler" property="*"/>
</jsp:useBean>

<%
   if (idHandler.validate()) {
%>
<jsp:forward page="success.jsp"/>
<%
   }  else {
%>
<jsp:forward page="retry.jsp"/>
<%
   }
%>












package foo;
 import java.sql.*;

 public class Login {

   private String username = "";
 private String password = "";

   public Login() {
  }

  public void setUsername(String username) {
     this.username = username;
  }

  public void setPassword(String password) {
     this.password = password;
   }


 public boolean  authenticate(String username2,
 String password2) {
  String query="select * from Registration;";
   String DbUserName="";
   String DbPassword="";
   String finalUser="";
  try {
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   Connection
 con=DriverManager.getConnection("jdbc:odbc:register");
   Statement stat=con.createStatement();
   ResultSet rst=stat.executeQuery(query);
   while(rst.next())

  {
   DbUserName=rst.getString("UserName");

  DbPassword=rst.getString("password");

   if (username2.equals(DbUserName) &&
 password2.equals(DbPassword)) {

 break;
     }


   }
 return true;
 }catch(Exception e){

 e.printStackTrace();
 return false;
 }
}}

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 8,981
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Donate to Member
Pay more attention in class? :)
- carpe noctem

jeremejazz

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 58
  • hey!
    • View Profile
    • Personal Website
    • Donate to Member
Re: Plz tell me how can i bring high quality to this Java code. it's urgent
« Reply #2 on: February 20, 2010, 02:13:45 AM »
Hey, where did ya get that? facebook puzzles?
haha;D

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,190
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: Plz tell me how can i bring high quality to this Java code. it's urgent
« Reply #3 on: February 20, 2010, 10:45:55 AM »
So just add commenting to the code in Hungarian...

 :D