Practical assessment task 2013

PHP:
this.rs = this.stmt.executeQuery("SELECT * FROM Voters;");
                      while (this.rs.next()) {
                        if (ID.equalsIgnoreCase(this.rs.getString("ID"))) {
                          JOptionPane.showMessageDialog(null, "User already registered", "ERROR", 0);
                          run = false;
                        }
                      }

if you had a million Voters, that could get slow
Change this to a "SELECT ID FROM Voters where ID=?"

PHP:
this.rs2 = this.stmt.executeQuery("SELECT * FROM Accounts;");
                        this.rs2.first();
                        this.rs2.moveToInsertRow();
                        this.rs2.updateString("ID", ID);
                        this.rs2.updateString("Password", Password);
                        this.rs2.insertRow();

                        this.rs = this.stmt.executeQuery("SELECT * FROM Voters;");
                        this.rs.moveToInsertRow();
                        this.rs.updateString("ID", ID);
                        this.rs.updateString("Name", Name);
                        this.rs.updateString("Surname", Surname);
                        this.rs.updateString("Race", Race);
                        this.rs.updateString("Address", Address);
                        this.rs.insertRow();
                        this.rs.close();

same here, rather use "INSERT INTO Accounts (ID, Password) VALUES (?, ?)"
 
create classes for your domain objects. you can these use these to do validation

eg
PHP:
public class Account {
  private String id;
  private String password;

  public void validate() throws Exception {
     //do validation and throw validation errors
  }
}
 
LiquidCocaine - Java is the easiest language in the world to reverse engineer. Bad choice.

Why do you care so much about hiding your implementation? The only way you will improve your skills is if you let others see the code that you have written.
 
ok, well I reverse engineered it anyway :)

some basic tips

you use this alot

PHP:
this.Reg.setFont(new Font("Tahoma", 1, 24));

rather do something like this

in some common file
PHP:
 public static DEFAULT_FONT = new Font("Tahoma", 1, 24);

and then in when you want to use the default
PHP:
this.Reg.setFont(DEFAULT_FONT);

all your Swing attributes could be named a bit better eg
PHP:
private JLabel Password;
private JPasswordField Pword_txt;

rather
PHP:
private JLabel passwordLabel;
private JPasswordField passwordInput/passwordField;


you have a lot of mixed style/nameing convensions too

eg
PHP:
private void Exit_menuActionPerformed(ActionEvent evt)
{
}
private void BackActionPerformed(ActionEvent evt)
{
}
private void initComponents() {
}

the standard convension is to use camelCaps, with the first word being lower case. Only class/interface names begin with uppercase
eg
PHP:
private void exitMenuActionPerformed(ActionEvent evt)
{
}
private void backActionPerformed(ActionEvent evt)
{
}
private void initComponents() {
}

public interface Foo {
}

public class FooImpl implements Foo {
}

pick a brace ({ }} style and stick to it. I prefer
PHP:
public void sameLineBrace() {
}
over
PHP:
public void nextLineBrace()
{
}

Thanks, most of the Swing coding is done by Netbeans, I'm aware of the camelCaps naming convension will rename such variables when I start documentation of the code. Bracket style is done for you in Netbeans but I haven't finalised the code yet.
 
Last edited:
PHP:
this.rs = this.stmt.executeQuery("SELECT * FROM Voters;");
                      while (this.rs.next()) {
                        if (ID.equalsIgnoreCase(this.rs.getString("ID"))) {
                          JOptionPane.showMessageDialog(null, "User already registered", "ERROR", 0);
                          run = false;
                        }
                      }

if you had a million Voters, that could get slow
Change this to a "SELECT ID FROM Voters where ID=?"

PHP:
this.rs2 = this.stmt.executeQuery("SELECT * FROM Accounts;");
                        this.rs2.first();
                        this.rs2.moveToInsertRow();
                        this.rs2.updateString("ID", ID);
                        this.rs2.updateString("Password", Password);
                        this.rs2.insertRow();

                        this.rs = this.stmt.executeQuery("SELECT * FROM Voters;");
                        this.rs.moveToInsertRow();
                        this.rs.updateString("ID", ID);
                        this.rs.updateString("Name", Name);
                        this.rs.updateString("Surname", Surname);
                        this.rs.updateString("Race", Race);
                        this.rs.updateString("Address", Address);
                        this.rs.insertRow();
                        this.rs.close();

same here, rather use "INSERT INTO Accounts (ID, Password) VALUES (?, ?)"

Thanks! Apart from the coding how's the look & feel? Could you register, log & vote?
 
Last edited:
LiquidCocaine - Java is the easiest language in the world to reverse engineer. Bad choice.

Why do you care so much about hiding your implementation? The only way you will improve your skills is if you let others see the code that you have written.

I don't mind sharing, my main concern was look & feel as the coding is not finalised as yet.
 
Top
Sign up to the MyBroadband newsletter
X