How do use the method record(int score) in this code?

how do i use record(int score) from the class Stats to record a new score?
public class ScoreInfo {
private int score;
private int numStudents;
public ScoreInfo(int aScore){
      score = aScore;
      numStudents=1;
public void increment(){numStudents++;}
public int getScore(){return score;}
public int getFrequency(){return numStudents;}
import java.util.ArrayList;
import java.*;
public class Stats
private ArrayList<ScoreInfo> scoreList;
public boolean record(int score)
     int k=0;
     while(k<scoreList.size() && score > scoreList.get(k).getScore()){
          k++;
     boolean found = k<scoreList.size() && score == scoreList.get(k).getScore();
      if(found){scoreList.get(k).increment();}
      else{scoreList.add(k,new ScoreInfo(score));}
      return found;
public void recordScores(int[] stuScores)
static int score = 50;
public static void main(String[] args) throws Exception
Stats stats = new Stats();
ScoreInfo thestat = new ScoreInfo(score);
stats.scoreList.add(thestat);
}

hiwa wrote:
In your main() method, or in any code which tries to create a new score, below is wrong:
ScoreInfo thestat = new ScoreInfo(score);
stats.scoreList.add(thestat);They should be:
stats.record(thestat); // record() method creates a new ScoreInfo
// and add it to the scoreList, see your own posted code
stats.record(thestat); will not work because record has a parameter that needs an integer not an object
i tried public static void main(String[] args) throws Exception
Stats stats = new Stats();
ScoreInfo thestat = new ScoreInfo(7);
stats.record(7);
but i get this error Exception in thread "main" java.lang.NullPointerException
at Stats.record(Stats.java:13)
at Stats.main(Stats.java:39)

Similar Messages

  • How to use the method  setReadTimeout(int longtimes) in HttpUrlConnection?

    I have to use the HttpUrlConnection to download files ,sometimes the speed is very slow or just blocked for no reason.(no Exception was throw and I can't see any changes from my swing Interface)
    It seems the thread is dead. I try to use setReadTimeout() to control the read . but it isn't working ,
    Now I have to questions?
    one how to use the setReadTimeout() so it can throw the SocketTimeoutException like the API said
    second how to solve the problem I metioned before : sometimes the speed is very slow or just blocked for no reason
    Please somebody help me !!!

    That is not true. For example ajax continuous, http monitor or media streaming in client side is unusable without nio http client (or implementation is much simple and better). All logic is coming to client side from server. Modern client are very powerful and same time servers are overloaded.

  • How to use the method "getChildrenRemoved()" declared in ElementChange?

    How to use the method "getChildrenRemoved()" declared in DocumentEvent.ElementChange?

    I have tried to use it,but the code below alway say "Yes"....
    I really have no ideas about why ec is always a null.
    public void removeUpdate(DocumentEvent ee) {
           DocumentEvent.ElementChange ec = ee.getChange(doc.getDefaultRootElement());
           if(ec == null)
              System.out.println("Yes");
                     }

  • How to use the DISPLAY RECORD Setup Command in an etext file?

    Hi All,
    How to use the DISPLAY RECORD Setup Command in an etext file?
    I want to display a <NEW RECORD> conditionally. The condition will be based on the data coming through from the xml file.
    Please help me with an example. The BI User guide also doesnt show any examples.
    Your help is appreciated.
    Rgds,
    Kiran Panditi

    Hi,
    You can use vb coding in BEx Analyser to calculate your unit price. For this you have to first display the attributes of your object "XYZ". Then you can use VB cosing to calculate the value for the unit price field.
    One more thing cna you clarify whether is it display attribute or variable ?
    Regards,
    Balajee

  • How to use at last/ at end of in this code

    Hi,
    i want to do sum for each and every line item of the delivery quantity and compare it with final purchase order quantity if it is equal do not display in the output.(how to use at last/at end of ) in this code,
    below code wat i have ritten is only comparing first record with final purchase order quantity and displaying the output, but i want sum of every line item and compare with final quantity(purchase order quantity)
    if possible try modify this code
    clear:wa_final,wa_kopoo,wa_likpp1.
        loop at it_kopoo into wa_kopoo.
          move wa_kopoo-ebeln to wa_final-ebeln.
          move wa_kopoo-ebelp to wa_final-ebelp.
          move wa_kopoo-matnr to wa_final-matnr.
          move wa_kopoo-txz01 to wa_final-txz01.
          move wa_kopoo-menge to wa_final-menge.
          move wa_kopoo-meins to wa_final-meins.
          move wa_kopoo-werks to wa_final-werks.
          move wa_kopoo-matkl to wa_final-matkl.
          move wa_kopoo-reswk to wa_final-reswk.
          move wa_kopoo-aedat to wa_final-aedat.
          move wa_kopoo-ekgrp to wa_final-ekgrp.
          move wa_kopoo-EINDT to wa_final-EINDT.
        read table it_likpp1 into wa_likpp1 with key vgbel = wa_final-ebeln
                                                     vgpos = wa_final-ebelp.
          if sy-subrc eq 0.
            if wa_final-menge > wa_likpp1-LFIMG.
            else.
              continue.
            endif.
          endif.
          append wa_final to it_final.
          clear:wa_final,wa_kopoo,wa_likpp1.
        endloop.
      endif.

    Hi,
    Try this:
    define one more internal table it_final1 similar to i_final .
    CLEAR:wa_final,wa_kopoo,wa_likpp1.
    SORT it_kopoo BY ebeln ebelp.
    LOOP AT it_kopoo INTO wa_kopoo.
      move-corresponding wa_kopoo to wa_final.
      COLLECT wa_final INTO it_final1.
      CLEAR: wa_kopoo, wa_final.
    ENDLOOP.
    sort it_final1 by ebeln ebelp.
    LOOP AT it_final1 INTO wa_final.
      READ TABLE it_likpp1 INTO wa_likpp1 WITH KEY vgbel = wa_final-ebeln
                                                   vgpos = wa_final-ebelp.
      IF sy-subrc EQ 0.
        IF wa_final-menge NE wa_likpp1-lfimg.
          APPEND wa_final TO it_final.
        ENDIF.
      ENDIF.
    ENDLOOP.
    Regards,
    Subramanian

  • How to use the method getParameterValues() of request object in JSP?

    I'm trying to use the method
    String a[]=request.getParameterValues("ch_box");
    to retrieve the values from the form
    but it gives the error
    "Method getParamaterValues(java.lang.String) not found in interface javax.servlet.http.HttpServletRequest."
    so plz tell me how to overcome this hurdle?
    thanx

    Well, just one note... either you have a typo in your code, or else in your post.
    If you cut and pasted the error message (which it looks like you did), then the method getParamaterValues() should be getParameterValues() instead (notice the spelling difference), so you probably just have a typo in your code.

  • How to use the method for field-exit to trigger the workflow?

    Dear all,
         I want the workflow to trigger , when ever the check box for DELIVERY COMPLETED is checked in ME22N .
         I have developed a method in SE18 for the corresponding field and defined function module SWE_EVENT_CREATE with BOR bus2012 and event CHANGED.
        Now how to use this method to make my workflow to trigger?Shall I create an event in delegated bus2012 and can I call this method?
    Thanks and regards,
    S.Suresh

    Hi
    You want to place your method which is defined for particular filed.right?
    For that you can go for BADI. First you check whether any badi is getting called form that tcode ME22N. Then to place your method, implement that BADI.  So whenever that BADI is getting called, it will call your event. Through Event workflow will be getting triggered.
    Regards,
    Hemalatha.

  • Interface/Method question (how to use the method insert_table)

    Hi people!
    I'm working with DOI (desktop office integration).
    So far I've been able to reflect flat variables from my ABAP program into a Word Doc, but when it comes to internal tables I'm not sure how to achieve this.....
    I find out in the interface i_oi_word_processor_document the method insert_table, but I can't find a single simple example on how to use it....
    If no one knows how to use this method, does anyone know how to reflect an internal table fron my program into a Word Doc by another mean?
    Thanks in advance!!!
    Regards,
    Laura

    Hi Laura
    If you want you can use direct OLE calls. For this, you can refer to the tutorial <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/c1d54348-0601-0010-3e98-bd2a2dcd9e6c">"An Easy Reference For OLE Automation"</a> published at SDN.
    Kind Regards
    *--Serdar
    [email protected]

  • How to use the method calendar.getTimeInMillis() and setTimeInMillis(bb)

    I have met some problems in writing my programme,I want to know what the time is after every 20 minutes so have written some codes as below ,but the compilar warned me that there are some errors in them ,and I don't know how to use them correctly ,can you help me?
    Thank you very much!
    the code is:
    begin=datime+" 00:00:00";
    Calendar calendar=Calendar.getInstance();
    DateFormat df = DateFormat.getDateInstance();
    Date start=df.parse(begin);
    calendar.setTime(start);
    long aa=calendar.getTimeInMillis();
    calendar.setTimeInMillis(aa);

    Hopefully the following snippet of code will help you out (note that the Date class seems more appropriate for what you need to do):
    import java.util.*;
    import java.text.*;
          String begin="00:00:00";
          SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
          df.setTimeZone(TimeZone.getTimeZone("GMT"));
          Date start=new Date();
          try {
             start=df.parse(begin);
          } catch (Throwable e) {
             System.out.println("Invalid time format");
          long aa=start.getTime();   // to get the time in milliseconds
          System.out.println(aa);    // just to see what the answer is (should be zero)
          start.setTime(aa);         // to set the time in milliseconds
    ...V.V.

  • How to use the method finalize () ? It has protected access...

    Here is the program : the structure is the way I would write in Pascal.
    I need new object question at each turn in the loop ! But question is already defined outside the loop. So, I thought to the method finalize (). But the compilator doesn't agree.... It would be a good thing however to destroy objects wich are obsolete !
    public class MM {
       public static void main (String [] args) {
          Base base = new Base ();
          base.demanderNbCouleurs ();
          base.demanderNbPions ();
          Combi solution = new Combi ();
          solution.demander ();
          Combi question = new Combi ();
          question.cueillir ();
          question.afficher ();
          Reponse reponse = new Reponse ();
          reponse.demander ();
          boolean trouve = reponse.getBP () == base.getNbPions ();
          boolean erreur = false;
          while (! trouve & ! erreur) {
             question.enregistrer (reponse.getBP (), reponse.getMP ());
             question.finalize ();
             Combi question = new Combi ();
             question.cueillir ();
             while (! question.compatible () & ! question.getVide ()) {
                question.cueillir ();
             if (question.compatible ()) {
                question.afficher ();
                reponse.demander ();
                trouve = reponse.getBP () == base.getNbPions ();
             } else {
                erreur = true;
          conclusion (trouve);
       }

    So, I did ;
             question = new Combi ();And it's magical ! The program works...
    Now, I would like to give colors to my researcher Mastermind :
    1 2 3 4
    4 4 1 1 ... BP MP : 0 2
    1 1 6 5 ... BP MP : 1 0
    1 3 4 3 ... BP MP : 1 2
    1 2 3 4 ... BP MP : 4 0
    Trouve !
    I want the 1 to be red, the 2 be yellow, the 3 be green and so on...
    Is there any procedure " textColor " ?
    here is my method afficher () :
       public void afficher () {
          // Affiche le tableau 'combi'.
          for (int i = 0; i < NB_PIONS; i++) {
             // textColor (couleur [combi );
    System.out.print (" " + combi [i]);

  • How to use the insert record and check username function?

    Hi guys.
    I have an error that has me stumped.
    I have a form that inserts text from a text field into a
    mysql database and I have added a check user name function to check
    if this number already exists.
    Here's the page
    http://www.thechallenge.net.au/redemption2.php
    The error I get when using the page on the web is this
    Duplicate entry '' for key 1
    Can anyone help with this?

    ottoman007 wrote:
    I have tried the COUNTIF I input my formula =COUNTIF(6C:6M,">t") to the right of the row that I want to count and I get a red triangle and it says it isn't a valid reference. ... I am boggled how to do this.
    Badunit wrote:
    One parameter is the range (your row or column of checkboxes) and the other is the condition you want to count, which is TRUE.
                         =COUNTIF(6C:6M,TRUE)
    Regards,
    Barry

  • How to use the One-to-One mapping in Java Code

    Dear all:
    I have set the direct mapping and named query,
    and have written web service of login.
    I can login successfully.
    Now,I want learning about One-to-One mapping.
    I have setting the One-to-One mapping,
    then what can I do latter?
    I do not found any paper showing how to use it in web service?
    Somebody help me?thx all.

    Following code worked for me:
    import oracle.javatools.resourcebundle.BundleFactory;
    import java.util.ResourceBundle;
    * This method retrieves localized strings from a given XLIF resource bundle.
    * @param bundleName The XLIF bundle from which the localized string is to be retrieved.
    * @param key The key of the localized string.
    * @return The localized string retrieved from the given XLIF bundle.
    public static String getXlifLocalizedString(String bundleName, String key) {
    if (StringUtils.isEmpty(key)) {
    return key;
    if (StringUtils.isEmpty(bundleName)) {
    return "[" + key + "]";
    String localizedString = null;
    ResourceBundle resourceBundle = null;
    try {
    resourceBundle = BundleFactory.getBundle(bundleName);
    localizedString = resourceBundle.getString(key);
    } catch (Exception e) {
    LOG.log(Level.SEVERE, "Problem in loading XLIF resource bundle: " + bundleName, e);
    return "[" + key + "]";
    return localizedString;
    }

  • How does "use the hot fix installer to apply this update (ColdFusion 10 Update)" work?

    I am building a ColdFusion 10 server on Windows Server 2008-R2 from scratch using the Lockdown Guide. I am stuck on the Updates. The mandatory "manual" update is installed, but I don't see how to jump to Update 10. In the administrator, when I check for updates it shows Update 10, but there is no download button. There is a download button for Update 7, but nothing happens. Is there not manual download and installation option? What am I doing wrong here? This should be the easy part. Thanks.
    Message was edited by: GDMVU

    It sounds like the updates page is not loading properly.  Have you tried refreshing that page in CF Administrator?  Also, you might try restarting the ColdFusion service.  You might have a proxy/firewall issue as well.  Here is the direct download link for the update: http://download.adobe.com/pub/adobe/coldfusion/hotfix_010.jar.
    -Carl V.

  • How to use the method substituion in variable ODI

    Hi folks,
    I have a variable that run the follow query;
    select GER_LOT_EXEC_ODI('Fluxo', 1, 'C') FROM DUAL
    GER_LOT_EXEC_ODI is a function, and i need to pass the data shema name before this:
    I'd like that stay this:
    select data_shema_user.GER_LOT_EXEC_ODI('Fluxo', 1, 'C') FROM DUAL
    I tryed with the follow method and not worked:
    select <%=odiRef.getInfo( <"SRC_SCHEMA"> )%>.GER_LOT_EXEC_ODI('Fluxo', 1, 'C') FROM DUAL
    Error log
    900 : 42000 : java.sql.SQLException: ORA-00900: invalid SQL statement
    java.sql.SQLException: ORA-00900: invalid SQL statement
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:316)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:282)
         at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:639)
         at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:185)
         at oracle.jdbc.driver.T4CPreparedStatement.execute_for_rows(T4CPreparedStatement.java:633)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1086)
         at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2984)
         at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3026)
         at com.sunopsis.sql.SnpsQuery.executeQuery(SnpsQuery.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSqlV.execStdOrders(SnpSessTaskSqlV.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSqlV.treatTaskTrt(SnpSessTaskSqlV.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSqlV.treatTask(SnpSessTaskSqlV.java)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandSession.treatCommand(DwgCommandSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
         at com.sunopsis.dwg.cmd.e.i(e.java)
         at com.sunopsis.dwg.cmd.g.y(g.java)
         at com.sunopsis.dwg.cmd.e.run(e.java)
         at java.lang.Thread.run(Unknown Source)
    what is wrong?
    Thanks in advance
    Bovolini

    Hi,
    use <%=odiRef.getSchemaName("D")%>
    D as parameter if it is the Data Schema or W if you need the schema from Work Schema
    Your command will be like:
    select <%=odiRef.getSchemaName("D")%>.GER_LOT_EXEC_ODI('Fluxo', 1, 'C') FROM DUAL
    Works?
    Cezar Santos
    http://odiexperts.com

  • How to use a method in sequence diagram from a class diagram

    Hello, can someone tell me how to use the method from class diagram in sequence diagram? so far i only can add a classifier to the object lifeline but i still cannot add the method from the class...
    thx

    Now that Web Services is around, I'd look at possibly implement a Web Service call in your applet, which can then be given back any object(s) on return. Set up your server side to handle Web Service calls. In this way, you can break the applet out into an application should you want to (with very little work) and it will still function the same

Maybe you are looking for