Help me regarding this topic

Discussion in 'Java' started by smart, Mar 13, 2008.

  1. smart

    smart Guest

    Hi, to all i am new to core java and question on Swings. See this code
    and help me.

    I want to calculate student marks and his average. When i click button
    total marks will have calculate and i am posting code below


    Thanks



    if(ae.getSource()==btnCal)
    {



    btnNew.setEnabled(true);
    btnSave.setEnabled(false);
    btnDel.setEnabled(true);
    Connection conSno;
    Statement stSno;
    int Total,Average;
    int English = Integer.praseInt(tfEng.getText());
    int Telugu = Integer.praseInt(tfTel.getText());
    int Mathmatics = Integer.praseInt(tfMaths.getText());
    int Science = Integer.praseInt(tfSci.getText());
    int Social = Integer.praseInt(tfSoc.getText());
    int Hindi = Integer.praseInt(tfHin.getText());


    Class.forName("sun.Jdbc.Odbc.JdbcOdbcDriver");
    conSno =
    DriverManager.getConnection("jdbc:eek:dbc:DRIVER{Microsoft Access
    Driver(*.mdb)};DBQ=D:\\ProgressReport.mdb");


    Total = English+Telugu+Mathmatics+Science+Social+Hindi;

    Average = Total / 6;

    tfTot.setText(String.ValueOf(Total));
    tfAvg.setText(String.ValueOf(Average));

    stSno=conSno.createStatement();

    ResultSet rsSno=stSno.executeQuery("select Tot,Avg from
    ProgressReport where Sno = '"+Sno+"'");

    if(rsSno.next())
    {

    tfTot.setText(rsSno.getString(12));
    tfAvg.setText(rsSno.getString(13));

    } // end of the if condition
    } // end of the btnCal
     
    smart, Mar 13, 2008
    #1
    1. Advertising

  2. On Mar 13, 4:46 pm, smart <> wrote:

    Sub: Help me regarding this topic

    How is it a 'smart' person can create such a dumb subject
    line? (That is a question - you can tell by the addition
    of the '?' question mark.)

    For this post, even a simple subject line of
    'average student marks - Swing' would have
    been better.

    > Hi, to all i am new to core java and question on Swings.


    It is *Swing* - no final 's'.

    >..See this code and help me.


    It is not considered good form to issue commands
    to people. Adding a 'please' at the beginning of
    the sentence turns that command into a request.

    > I want to calculate student marks and his average. When i click button
    > total marks will have calculate and i am posting code below


    OK - what is your question?

    A couple of notes:
    - You have a lot greater chance of getting an
    answer if you include short but *compilable* code.
    - Please indent code with 2-4 spaces per indent level,
    not the large indents which will force line-wrap.
    - Now I glance at the snippet I notice 'Telugu' from
    the other day, and (checking) you were the person
    that asked that question. A variety of things were
    suggested to you, including to conform to the coding
    (naming) conventions that other programmers expect.
    Why did you ignore that advice? Do you intend to
    waste the time and effort of the people who are
    trying to help?
    - People here will not 'finish your homework' for you.
    To get good values from these groups, you need to
    ask *specific* questions - we are not some kind of
    'homework help-desk'.

    --
    Andrew T.
     
    Andrew Thompson, Mar 13, 2008
    #2
    1. Advertising

  3. smart wrote:
    > Hi, to all i am new to core java and question on Swings. See this code
    > and help me.


    We can only help if you tell is what you think is going wrong.
    - is there a compiler error message?
    - is there a run-time error message?
    - does the output differ from what you expect? How exactly?

    >
    > I want to calculate student marks and his average. When i click button
    > total marks will have calculate and i am posting code below
    >


    I think you really should pay attention to what Andrew and others have
    said about formatting your source code - I find it hideously unreadable.



    >
    >
    >
    >
    > if(ae.getSource()==btnCal)


    Looks like this is part of some event handler like an ActionListener.
    It's a shame you don't provide a complete (but small) example program.

    > {
    >
    >
    >
    > btnNew.setEnabled(true);
    > btnSave.setEnabled(false);
    > btnDel.setEnabled(true);
    > Connection conSno;
    > Statement stSno;


    Presumably those are java.sql.Connection and java.sql.Statement - I
    recommend you read about Model-View-Controller (MVC) patterns and try to
    keep database code in separate classes from your GUI code.


    > int Total,Average;


    That level of indentation is ridiculous, please convert tabs to two
    (maybe four) spaces before posting. Most editors and IDEs I've used
    allow you to configure them so that tabs are always converted to spaces.

    Cariable names should start with lower case ("english" instead of
    "English") otherwise you confuse readers by making variable names look
    like class names.

    > int English = Integer.praseInt(tfEng.getText());
    > int Telugu = Integer.praseInt(tfTel.getText());
    > int Mathmatics = Integer.praseInt(tfMaths.getText());
    > int Science = Integer.praseInt(tfSci.getText());
    > int Social = Integer.praseInt(tfSoc.getText());
    > int Hindi = Integer.praseInt(tfHin.getText());


    I'd have an array or HashMap of JTextFields to eliminate this repetition.


    >
    >
    > Class.forName("sun.Jdbc.Odbc.JdbcOdbcDriver");
    > conSno =
    > DriverManager.getConnection("jdbc:eek:dbc:DRIVER{Microsoft Access
    > Driver(*.mdb)};DBQ=D:\\ProgressReport.mdb");


    See above. Anyway, your JDBC code seems to be scattered around
    incoherently, I'd gather it all up in one place.


    >
    >
    > Total = English+Telugu+Mathmatics+Science+Social+Hindi;
    >
    > Average = Total / 6;
    >
    > tfTot.setText(String.ValueOf(Total));
    > tfAvg.setText(String.ValueOf(Average));
    >
    > stSno=conSno.createStatement();
    >
    > ResultSet rsSno=stSno.executeQuery("select Tot,Avg from
    > ProgressReport where Sno = '"+Sno+"'");
    >
    > if(rsSno.next())


    I usually use while(xxx.next()) unless I have specifically checked that
    only one record will be returned.

    > {
    >
    > tfTot.setText(rsSno.getString(12));
    > tfAvg.setText(rsSno.getString(13));


    getString(12) will not return anything useful since your SQL statement
    only selects two fields from the table.

    You are overwriting the text in tfTot, which you just put your
    calculated total into. It is no surprise you don't ever see the
    calculated total - I guess that is the actual problem (which you failed
    to say).

    >
    > } // end of the if condition
    > } // end of the btnCal



    Unless you pay some attention to the advice about tabs and
    capitalisation, I will find it very hard to summon the will to respond
    any further.

    --
    RGB
     
    RedGrittyBrick, Mar 13, 2008
    #3
  4. smart

    Hal Rosser Guest

    > int English = Integer.praseInt(tfEng.getText());
    > int Telugu = Integer.praseInt(tfTel.getText());
    > int Mathmatics = Integer.praseInt(tfMaths.getText());
    > int Science = Integer.praseInt(tfSci.getText());
    > int Social = Integer.praseInt(tfSoc.getText());
    > int Hindi = Integer.praseInt(tfHin.getText());


    To start with, I don't think Integer has a praseInt method.
    I may be wrong, but spelling counts a lot in Java.
     
    Hal Rosser, Mar 14, 2008
    #4
  5. Hal Rosser wrote:
    >> int English = Integer.praseInt(tfEng.getText());
    >> int Telugu = Integer.praseInt(tfTel.getText());
    >> int Mathmatics = Integer.praseInt(tfMaths.getText());
    >> int Science = Integer.praseInt(tfSci.getText());
    >> int Social = Integer.praseInt(tfSoc.getText());
    >> int Hindi = Integer.praseInt(tfHin.getText());

    >
    > To start with, I don't think Integer has a praseInt method.
    > I may be wrong, but spelling counts a lot in Java.
    >
    >

    I think he has it right. The great Int god needs much prasing.
     
    David Zimmerman, Mar 14, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cliff R.
    Replies:
    3
    Views:
    421
    Roy Schestowitz
    Jun 15, 2005
  2. Replies:
    0
    Views:
    2,213
  3. jacob navia
    Replies:
    5
    Views:
    550
    spinoza1111
    May 30, 2010
  4. Romanian

    Help? Not sure if right topic =(

    Romanian, May 18, 2006, in forum: Javascript
    Replies:
    1
    Views:
    68
    Lasse Reichstein Nielsen
    May 18, 2006
  5. FAQ server
    Replies:
    1
    Views:
    226
    Dr J R Stockton
    Oct 16, 2008
Loading...

Share This Page