DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

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

simsim00

  • Participant
  • Joined in 2009
  • *
  • Posts: 2
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

  • [Well, THAT escalated quickly!]
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
    • Participated in NANY Challenge Once
Pay more attention in class? :)
- carpe noctem

jeremejazz

  • hey!
  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 59
Hey, where did ya get that? facebook puzzles?
haha;D

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,652
    • Cody Award
    • Participated in NANY Challenge Five Times
So just add commenting to the code in Hungarian...

:D

Original address: https://www.donationcoder.com/forum/index.php?topic=18756.0