Results 1 to 12 of 12
Like Tree1Likes
  • 1 Post By Tolls

Thread: Functional explain

  1. #1
    Razorfc is offline Member
    Join Date
    Mar 2012
    Posts
    27
    Rep Power
    0

    Default Functional explain

    Java Code:
     
    public static List<GameDetails> getGameHighScores() throws SQLException {
        List<GameDetails> r = new ArrayList<GameDetails>();
        ResultSet rs = null;
        //connectToDatabase();
    //TODO
    
        if (con == null) {
          throw new SQLException("Not connected to database");
        } else {
          // prepare the statement if the connection is different
          if (loadAllHighScoresSQLSt == null) {
            loadAllHighScoresSQLSt = con.prepareStatement(loadAllHighScoresSQL);
          }
    
          // execute the query to get a result set
          rs = loadAllHighScoresSQLSt.executeQuery();
    
          double moveSpeed = 0;        // data from result set
          int firingInterval = 0;
          int highScore = 0;
    
          double speed = 0;            // target data
          int interval = 0;
          int score = 0;
    
          // details to add to list
          GameDetails details;
    
          // start at the first record
          rs.first();
    
          // go through the rows of the record set, add any high scores to list
          while (rs.next()) {
    
            // get data
            moveSpeed = rs.getDouble("MoveSpeed");
            firingInterval = rs.getInt("FiringInterval");
            highScore = rs.getInt("HighScore");
    
            // check the move speed + firing interval settings
    //        if ((moveSpeed != speed) || (firingInterval != interval)) {
    //          // settings changed so this is a new high score
    //          // set new targets
    //          speed = moveSpeed;
    //          interval = firingInterval;
    //          score = highScore;
    
              // add details to list
              details = new GameDetails(new UserDetails((String) rs.getString("UserName")), new GameSettings(moveSpeed, firingInterval));
              r.add(details);
    //        } else {
    //          if (highScore == score) {
    //            // another player has the same high score. add to list
    //            details = new GameDetails(new UserDetails((String) rs.getString("UserName")), new GameSettings(moveSpeed, firingInterval));
    //            r.add(details);
    //          }
            }
          }
    
    I have already done the code but i just dunno how to explain in function while i was about to present to the lecture about my ideas i wrote
    he ask me to explain why you put if statement instead without it the if statement as for the gamehighscore 
    e.g  if ((moveSpeed != speed) || (firingInterval != interval))
    
    and 
    
    whats is the function do? for gamehighscoretablemodel
    
    public Object getValueAt(int rowIndex, int columnIndex) {
        if (columnIndex == 0)
          return ((GameDetails)this.highScores.get(rowIndex)).getUserDetails().getUserName();
        if (columnIndex == 1)
          return Double.valueOf(((GameDetails)this.highScores.get(rowIndex)).getGameSettings().getMoveSpeed());
        if (columnIndex == 2) {
          return Integer.valueOf(((GameDetails)this.highScores.get(rowIndex)).getGameSettings().getFiringInterval());
        }
        return Integer.valueOf(((GameDetails)this.highScores.get(rowIndex)).getHighScore());
      }
    *
    . Thank you so much for the help i just need to one more thing to explain to him to proof that this is my work. I couldn't explain in vocal as i know in my head.
    Last edited by Razorfc; 06-22-2012 at 12:22 PM.

  2. #2
    Razorfc is offline Member
    Join Date
    Mar 2012
    Posts
    27
    Rep Power
    0

    Default Re: Functional explain

    Functional explain-untitled.jpg
    with my if statement works in the diagram but what happened without the if statement

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: Functional explain

    I have absolutely no idea what's going on in that, though the lack of [code] tags [/code] probably doesn't help.
    I am confused as to why you can't explain what's going on in the code...
    For starters that 'if' statement is commented out.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    Razorfc is offline Member
    Join Date
    Mar 2012
    Posts
    27
    Rep Power
    0

    Default Re: Functional explain

    Yeah but i dunno whats the function do
    Java Code:
     
    public static List<GameDetails> getGameHighScores() throws SQLException {
        List<GameDetails> r = new ArrayList<GameDetails>();
        ResultSet rs = null;
        //connectToDatabase();
    //TODO
    
        if (con == null) {
          throw new SQLException("Not connected to database");
        } else {
          // prepare the statement if the connection is different
          if (loadAllHighScoresSQLSt == null) {
            loadAllHighScoresSQLSt = con.prepareStatement(loadAllHighScoresSQL);
          }
    
          // execute the query to get a result set
          rs = loadAllHighScoresSQLSt.executeQuery();
    
          double moveSpeed = 0;        // data from result set
          int firingInterval = 0;
          int highScore = 0;
    
          double speed = 0;            // target data
          int interval = 0;
          int score = 0;
    
          // details to add to list
          GameDetails details;
    
          // start at the first record
          rs.first();
    
          // go through the rows of the record set, add any high scores to list
          while (rs.next()) {
    
            // get data
            moveSpeed = rs.getDouble("MoveSpeed");
            firingInterval = rs.getInt("FiringInterval");
            highScore = rs.getInt("HighScore");
    
            // check the move speed + firing interval settings
    //        if ((moveSpeed != speed) || (firingInterval != interval)) {
    //          // settings changed so this is a new high score
    //          // set new targets
    //          speed = moveSpeed;
    //          interval = firingInterval;
    //          score = highScore;
    
              // add details to list
              details = new GameDetails(new UserDetails((String) rs.getString("UserName")), new GameSettings(moveSpeed, firingInterval));
              r.add(details);
    //        } else {
    //          if (highScore == score) {
    //            // another player has the same high score. add to list
    //            details = new GameDetails(new UserDetails((String) rs.getString("UserName")), new GameSettings(moveSpeed, firingInterval));
    //            r.add(details);
    //          }
            }
          }

  5. #5
    Razorfc is offline Member
    Join Date
    Mar 2012
    Posts
    27
    Rep Power
    0

    Default Re: Functional explain

    tring loadAllHighScoresSQL =
    "SELECT userName, MoveSpeed, FiringInterval, HighScore"
    + " FROM tblHighScores ORDER BY MoveSpeed, FiringInterval, HighScore DESC";
    this is the fucntion of sql statment

    w

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default Re: Functional explain

    Quote Originally Posted by Razorfc View Post
    Yeah but i dunno whats the function do
    Did you write it in a higher state of consciousness and now you're back to earth you don't understand yourself anymore ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Razorfc is offline Member
    Join Date
    Mar 2012
    Posts
    27
    Rep Power
    0

    Default Re: Functional explain

    Yes it takes 4 weeks to write it and i couldn't explain in words because i have disaiblity in output words.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: Functional explain

    Well, we don't either.
    All I can say is the method says getGameHighScores()...and yet fails to return any high scores at all.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    Razorfc is offline Member
    Join Date
    Mar 2012
    Posts
    27
    Rep Power
    0

    Default Re: Functional explain

    Oh so without the if statement then it show the list of original tblHighScores but fails to reutrn any high scores in order. So with the if statement it then execute the game highscore and show the list on the picture in order. Meaning it will tell you who go the highest score. here is the game highscore shown below without the if statement

    he ask me to explain why you put if statement instead without it the if statement as for the gamehighscore
    e.g if ((moveSpeed != speed) || (firingInterval != interval))

    Functional explain-untitled.jpg
    Last edited by Razorfc; 06-22-2012 at 01:08 PM.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: Functional explain

    But even if you take out the copmmented out code I can't see where the highscore (or score) values get saved.
    They just go out of scope?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    Razorfc is offline Member
    Join Date
    Mar 2012
    Posts
    27
    Rep Power
    0

    Default Re: Functional explain

    yeah so if you get rid of if statement expect left with
    [code]
    details = new GameDetails(new UserDetails((String) rs.getString("UserName")), new GameSettings(moveSpeed, firingInterval));
    r.add(details);
    [code/]
    whats happens? i think it show Functional explain-untitled.jpg
    with the if statement
    it show the highest high score in order rather than without the if statement from #2

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: Functional explain

    I have absolutely no idea.
    If I were you I'd get a debugger and step thorugh it to see what it is returning.
    Failing that, stick lots of println() calls in there to see what's going on.
    DarrylBurke likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. can someone explain what this exactly does?
    By liluma in forum New To Java
    Replies: 4
    Last Post: 08-21-2011, 07:58 PM
  2. Non functional radio buttons and messed up array
    By flameofSuzaku in forum New To Java
    Replies: 2
    Last Post: 01-10-2011, 05:38 PM
  3. Replies: 2
    Last Post: 12-13-2010, 01:34 PM
  4. Replies: 3
    Last Post: 12-13-2010, 07:22 AM
  5. functional/procedureal Methods
    By leiferouis in forum New To Java
    Replies: 5
    Last Post: 01-09-2009, 05:40 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •