FINDING MEDIAN FOR AN ARRAY OF INTS WITH EVEN NUMBER OF VALUES

okie dokie fellas i know this has got to be easy but i hjave been sittin at my comp forever workin on projects that are due and my head isn't all there anymore...could someone please clue me in on how im supposed to write the logic to find the median of an array of integers if the array contains an even number of values...I know I have to average the 2 values on either side but i cant figure it out at all...sorry i know its dumb but thnaks to anyone who helps
package pgm3deClercqMatt;
* @author Owner
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.text.*;
public class ExamStatistics
     public static void main(String[] args)
          DbConnection db = new DbConnection("pgm3");
          boolean moreRecords;
          String query = "SELECT * FROM pgm3Data ORDER BY ExamGrade";
          ResultSet rs = db.processQuery(query);
          int nbrGrades = 0;
          ResultSetMetaData rsmd = null;
          try
               rsmd = rs.getMetaData();
          catch(SQLException sqlex)
               JOptionPane.showMessageDialog(null, "SQLException getting ResultSet data or metadata");
               System.exit(0);
          int s[] = new int[200];
          DecimalFormat decimal = new DecimalFormat("#,##0.00");
          int n = 0, aboveNinety = 0, numberAboveNinety = 0;
          double sum = 0, avgGrade = 0, medianGrade = 0;
          try
               moreRecords = rs.next();
               if(!moreRecords)
                    JOptionPane.showMessageDialog(null, "pgm3Data Result Set is Empty.");
                    System.exit(0);
               while(moreRecords)
                    s[n] = rs.getInt(1);
                    n++;
                    moreRecords = rs.next();
               }// end of while loop
               System.out.println("n = " + n);
               System.out.println("s[0]= " + s[0]);
               System.out.println("s[n-1]= " + s[n-1]);
               //FIND AVERAGE OF ARRAY
               for(int j=0; j<n; ++j)
                    sum += s[j];
                    avgGrade = sum/n;
               //FIND NUMBER OF GRADES ABOVE OR EQUAL TO 90
               for(int j=0; j<n; ++j)
                    if(s[j]>=90)
                         numberAboveNinety++;
               //FIND MEDIAN EXAM GRADE
               for(int j=0; j<n ; ++j)
                    if(Math.abs(medianGrade - Math.floor(medianGrade))<1.e-10)
                          medianGrade = s[(j+1)/2];
                    else
                         medianGrade =    <HERE IS WHERE THE PROB IS
          }// end of try block
          catch(SQLException sqlex)
               JOptionPane.showMessageDialog(null, " SQLException getting ResultSet data or metadata");
               System.exit(0);
          String output = "";
          output = "Number of Exam Grades: " + n;
          output += "\nHighest Exam Grade: " + maxOfArray(s, n) + "\nLowest Exam Grade: " + minOfArray(s, n)
                    + "\nAverage Grade: " + decimal.format(avgGrade) + "\nNumber of exam grades above 90: "
                    + numberAboveNinety + "\nMedian Exam Grade: " + medianGrade;
          JOptionPane.showMessageDialog(null, output);
          System.exit(0);
     }// end of main
     static int maxOfArray(int z[], int n)
          int j, max = z[0];
          for(j=1; j<n; ++j)
               if(z[j]>max)
                    max = z[j];     
          return max;
     static int minOfArray(int z[], int n)
          int j, min = z[0];
          for(j=1; j<n; ++j)
               if(z[j]<min)
                    min = z[j];     
          return min;
}// end of ExamStatistics
class DbConnection
     //     class DbConnection creates and manages the db connection,
     //     processes queries, and returns result sets for processing
     private Connection connection = null;
     private String url="jdbc:odbc:";
     private Statement statement;
     private String username = "";
     private String password = "";
     private ResultSet rs;
     private int nbrResultSets = 0;
     //     Constructor Argument is the registered name of the database
     DbConnection(String dbName)
          try
          {// load driver to allow connection to database
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               connection = DriverManager.getConnection ((url+dbName), username, password );
          catch (ClassNotFoundException cnfex)
               fatalError("ClassNotFoundException on connection attempt");
               System.exit(0);
          catch (SQLException sqlex )
               fatalError("SQLException -- Unable to Connect to db");
               System.exit(0);
     } // end of constructor
     ResultSet processQuery(String query)
     //     process a single SQL query and return the resulting data set
          rs = null;
          try
               statement = connection.createStatement();
               rs = statement.executeQuery(query);
          catch (SQLException sqlex)
               fatalError("SQLException on query or processing");
          return rs;
     void endConnection()
          try
               connection.close();
          catch (SQLException e)
               fatalError("SQLException on attempt to close connection");
     //     simple local fatal error handler
     private void fatalError(String msg)
          JOptionPane.showMessageDialog(null,msg);
          System.exit(0);
} // end of class DbConnection

sorry to anyone who thinks what i'm doing is a joke
first of all i'm a student and secondly i'm taking
java in a summer session so things don't get
explained as well as they should. And how is this our problem?
I'm doing the best
i can. The for loop was because the array that I
defined to hold 200 values was being filled by a
database with a supposed unknown number of values but
less than 200 so i waslooping through to get each
value and put it in order and the conditional
statement was supposed to test to see if the incoming
median was an integer and was in the final write-up
put into it's own boolean method returning false if
there was no median and you needed to take the
average of the next lowest and highest values. BThere's always a median. The definition I sent you tells you what it is.
But
thnak you very much to the people that actually help
on here and don't try to bash people who have put
effort into writing their code, however shitty it may
look to them. You can't control what people say about your stuff. Everyone who criticizes your work isn't making a personal attack. They're telling you something that you should be learning from. Your problem is that you can't separate yourself from your work.
No one knows absolutely everything and
people who decide to talk down on others when they
are using this forum as a last resort need to grow
up.Grow up? That's what you need to do. If you think for a moment that you'll never be criticized once you leave that ivory tower you're sadly mistaken. You need to figure out how to separate yourself from your code.
%

Similar Messages

  • Set a default value for a radio button populated with a List of value

    Hi,
    I am using jdeveloper 11.1.1.3.0. I need to set a default value for a radio button populated with a List of value(Yes/No). Here's the selectonechoice code.
    <af:selectOneRadio value="#{bindings.Code.inputValue}"
    label="#{bindings.Code.label}"
    required="#{bindings.Code.hints.mandatory}"
    shortDesc="#{bindings.Code.hints.tooltip}"
    id="sor1" autoSubmit="true"
    valuePassThru="true" layout="horizontal">
    <f:selectItems value="#{bindings.Code.items}" id="si1"/>
    </af:selectOneRadio>
    I want to have the selectonechoice set to No by default. In the previous versions, I set the default value in the base attribute VO. But it is not working in the new version.
    Thanks

    Hi,
    this should work in JDeveloper 11.1.1.3 the same as in 11.1.1.2. If it doesn't then it is better to file a bug than to work around it
    Frank

  • How to create an array of ring with a different items/values for each

    Hi All,
    i want an array of text ring with different items and values for each text ring. Do you have other solution if it does not work?
    thanks by advance

    0utlaw wrote:
    Hello Mnemo15,
    The properties of elements in an array are shared across all controls or indicators in an array, so there is no way to specify unique selectable values for different text rings in an array.  It sounds like what you are looking for is a cluster of ring controls, where each control can be modified independently.  
    Could you provide a more descriptive overview of the sort of behavior you are looking for?  Are these ring elements populated at run time?  Will the values be changed dynamically? Will the user interact with them directly?
    Regards,
    But the selection is not a property, it is a value... I just tried it and you can have different selections.  Just not different items.
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • Batch Split for Material which are activated with serial number management

    Hello All,
    We have requirement where we want batch split to be mandatory during goods reciept with inbound delivery  for material which are serial number managed.
    Please let me know the possible solution to achive this requirement.
    Appreciate your quick response.
    BR,
    Tushar

    I have resolved this issue by myself. Check out the link where I have briefed how to resolve the issue using bapi BAPI_OUTB_DELIVERY_CHANGE.
    BAPI_OUTB_DELIVERY_CHANGE - Batch Splits don't work
    Regards,
    Senthil G.

  • I can't seem to create my object for my array!!

    I am in school. My project is to create bank accounts for 3 people. I have 2 for loops, one for my account_numbers and the other for the months of the year. This will track each account's transactions for the year. I initialized my array: int[] accnt_num_array = {123, 523, 723}; Account 123 should be accnt_num_array[0] and so on. My next line is: accnt_num_array = new int[3]; To create the object, and call my method getDeposit, but I get an error: "object type required, but int found." I need help desperately.
    email me at [email protected]
    Any help you could give to a struggling Java programmer would be greatly appreciated.

    int[] accnt_num_array = {123, 523, 723}; Account 123 should
    be accnt_num_array[0] and so on. You have the instantiated the array of ints with the reference named accnt_num_array at this point. You don't need
    accnt_num_array = new int[3]; To create the object,because it's already in existance. Take this out and start using the array.

  • STATUS WITH SERIAL NUMBER

    Hi Gurus
    My requirement is as follows
    1) This is with serial number concept
    2) The production schedule for FG will be given with serial number at intial stage itself every day
    3) There are 2 subassemblies required for FG ie) Eg.A and B
    4) The above 2 subassemblies were identified with same serial number XXX
    5) The subassemblies with Same Serial Numbers A and B only assembled for engineerig purpose
    5) I want to monitor the stauts of a) Is schedule has released to shop floor b) Sub assy A with Serial number completed c) Sub assy B with Serial number completed etc d) Is the Final assembly FG completed
    6) As the sub assy production process takes long time ie) 1 week it is needed what is the subassy status individually by A and B
    At present the client is in Production Order , Interested in going Repetitive, if the solution available in Repetitive it is appreciated
    I will clarify in detail if any questions pl
    K.Prabakaran

    Dear Ramanujam
    Need some clarification from your answer
    Your scenario is possible using REM also. The serial number profile defined should have the procedure PPSF (for REM). Also in OIS2 tick the check box ExtReqmt if serial numbers are to be created before prodn. You could have external number ranges activated.
    <i>I could see procedure PPSF in OSI2 but unable to see the tick mark area ECC6.0</i>
    You could track the Serial numbers generated for a material with IQ09 transaction.
    Once the serial comes into stock the System status will be AVLB (available). So you could track the prod status of these serial numbers at Sub assembly and assembly stages.
    <i>some extend understood</i>
    <i>could you please reply with some details with intro to serial numbers business process flow step by step T codes etc</i>
    thanks
    K.Prabakaran

  • PI - Why Value Mapping only for little number of value?

    Dear Experts,
    I really want to know the reason why Value Mapping in PI is suitable if the number of values to be mapped is little.
    Is it because it is stored in Memory Cache instead of Database table that make it less reliable?
    or is it because it would be hard to maintain the value, because we should entry the value one by one manually which will make the entry process a tedious process?
    If it is, what is the suitable way to do mapping in PI with large number of value?
    Thank you,
    Suwandi C.

    Hi,
    did you check the below link,
    http://help.sap.com/saphelp_nw73ehp1/helpdata/en/2A/107E72FFFC4B7E96730D2903B17A15/frameset.htm
    http://wiki.scn.sap.com/wiki/display/XI/Value+mapping
    Regards
    srinivas

  • My MacBook Pro stated that it needed to be updated. I clicked yes to restart the computer and update but when it restarted it stays on the gray screen with the apple logo and then pops up, stating "unable to find driver for this platform." What do I do?

    My MacBook Pro stated that it needed to be updated. I clicked yes to restart the computer and update but when it restarted it stays on the gray screen with the apple logo and then pops up, stating "unable to find driver for this platform." What do I do?

    Boot into Recovery by holding down the key combination command-R at the startup chime. Release the keys when you see a gray screen with a spinning dial.
    Note: You need an always-on Ethernet or Wi-Fi connection to the Internet to use Recovery. It won’t work with USB or PPPoE modems, or with networks that require any kind of authentication other than a WPA or WPA2 Personal password.
    When the Mac OS X Utilities screen appears, follow the prompts to reinstall the Mac OS. You don't need to erase the boot volume, and you won't need your backup unless something goes wrong. If your Mac didn’t ship with Lion, you’ll need the Apple ID and password you used to upgrade, so make a note of those before you begin.
    Don't install the Thunderbolt update -- it's defective.

  • I am trying to connect Garritan Personal Symphony to Logic Express and Garageband. A dialog box pops up and asks for plugin Garritan-P. Where do I find it and what do I do with it. I can't locate this plugin doing searches on any of the porgrams.

    I am trying to connect Garritan Personal Symphony to Logic Express and Garageband. A dialog box pops up and asks for plugin Garritan-P. Where do I find it and what do I do with it. I can't locate this plugin doing searches on any of the porgrams.

    I'm not sure which version of Garritan Personal Orchestra you have or when you are getting a window pop-up, but check this link for starters:
    http://afjohnston.blogspot.com/2009/11/using-garritan-personal-orchestra-gpo.htm l

  • I created a new Apple ID for iCloud on my iPhone, but I can't seem to find a way to "sign out" or "log out" of that Apple ID (for iCloud) to sign in with another Apple ID. The only account login I could change was the Store. How do I "log out"

    I created a new Apple ID for iCloud on my iPhone, but I can't seem to find a way to "sign out" or "log out" of that Apple ID (for iCloud) to sign in with another Apple ID. The only account login I could change was the Store.
    How do I "log out" or "sign out" of iCloud on my iPhone? There is an option to delete the account, but I just want to log off. I want to keep the account name for future use.

    @fernandamagalhaes
    It looks like the article below has the information you are looking for.
    iCloud: Change iCloud feature settings
    http://support.apple.com/kb/PH2613
    Turn off iCloud completely
    Depending on whether you want to stop using iCloud on all or only some devices, do one or more of the following:
    On your iOS device’s Home screen, go to Settings > iCloud, then at the bottom of the screen, tap Delete Account.
    Note:   If you delete your iCloud account, iCloud will no longer back up your iOS data. You can still back up your device in iTunes (for more information, open iTunes and choose iTunes > Help). 
    On your Mac, open iCloud preferences, then click Sign Out.
    If your Mac has OS X v10.7.5 and you turn off iCloud, your calendar information and reminders aren’t stored locally in iCal. If you want to retain your calendar and reminder information, you need to back it up before turning off iCloud. For more information, see the Apple Support article iCloud: Calendar & reminder data removed from Calendar and Reminders or iCal when disabling iCloud Calendar.
    On your Windows computer, open the iCloud Control Panel, then click Sign Out.
    Note:   If you turned on automatic download of music, app, or book purchases (in iTunes preferences or in Settings on your iOS device), your iTunes purchases are still downloaded to your devices.
    Set up iCloud on your devices

  • I am trying to buy Ai and my trial is up.  It is asking for a serial number and I cannot find an e-mail with the number.  What shall I do?

    I am trying to buy Ai.  My 30 day trial is up.  It is asking for a serial number and I cannot find an e-mail with the number.  What shall I do?

    Please refer below link :
    Creative Cloud pricing and membership plans | Adobe Creative Cloud

  • I have a 2009 macbook pro with os x10.9.2 and can't find drivers for windows

    i have a 2009 macbook pro with os x10.9.2 and can't find drivers for windows. i trying to install windows using bootcamp but does not allows me to download the drivers..

    From the system requirements page: http://support.apple.com/kb/HT5634 for your computer
    MacBook Pro
    (13-inch, Mid 2009)
    4
    4
    DVD
    DVD
    DVD
    MacBook Pro
    (15-inch, 2.53 GHz, Mid 2009)
    4
    4
    DVD
    DVD
    DVD
    MacBook Pro
    (15-inch, Mid 2009)
    4
    4
    DVD
    DVD
    DVD
    MacBook Pro
    (17-inch, Mid 2009)
    4
    4
    DVD
    DVD
    DVD
    MacBook Pro
    (17-inch, Early 2009)
    4
    4
    DVD
    DVD
    DVD
    The drivers are located on the OS DVD that came with your computer.

  • User event for array of waveforms with attribute

    I have been transferring data in a Producer/Consumer architecture via User Events.  The data consisted of an array of waveforms. When I added an attribute to the waveforms the code breaks with two errors about Create User Event: User event data type is unnamed or has elements with no names or duplicate names, and Contains unwired or bad terminal.
    From reading the help on user events it is not clear that arrays are even allowed: "user event data type is a cluster of elements or an individual element whose data type and label define the data type and name of the user event."
    From experimentation it seems that arrays of numerics and arrays of wavefroms without attributes work. A single waveform with an attribute can also be used. But an array of the same waveform with attribute leads to a broken run arrow. It also appears that I can put the array of waveforms with attributes inside a cluster and then create the user event.
    Is this a bug, an undocumented corner case, or some "feature" that I do not understand?
    Searching for User Event for Array of Waveforms generates some interesting, but mostly irrelevant results.
    Lynn

    tst wrote:
    Another option would be typecasting, but it looks like you can't typecast a waveform. Variant to Data or Coerce to Type might also work, but I haven't tried.
    I have also done the Flatten To String and Unflatten From String to send data around.  It would be preferable to not need to do that though.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • In addition to the FormsCentral subscription charge ($152.87 including tax) I was billed about the same time for $15.93. I can't find any way to get in touch with anyone from Adobe. The phone number I'm supposed to call is cut off on my invoice. Can someo

    In addition to the FormsCentral subscription charge ($152.87 including tax) I was billed about the same time for $15.93. I can't find any way to get in touch with anyone from Adobe. The phone number I'm supposed to call is cut off on my invoice. Can someone respond ASAP? Thanks

    I have forwarded your request to the support team that should be able to resolve this issue for you quickly. Expect to hear from them shortly.
    Andrew

  • ICM with CVP, failed to find networktrunkgroup for trunkgroupid 200

    Hi All,
    i am trying to build ICM with CVP. i have ICM and CVP on seperate box. all pims are active everything seems to be normal at my end but for some reason call is not working.
    when i dial the number on the vrupim i am getting a messge:
    Trace: VRUPeripheral::RequestInstruction: Failed to find NetworkTrunkGroup for TrunkGroupID 200
    and on my router i am getting the message:
    **** CVP HANDOFF.TCL: AFD9EF57.89D711E0.804C80F9.53B25ADC abnormally disconnected with code 38.
    please advise how to fix it.
    Thanks
    Munish

    hi
    Can you share screen shot of NTG & which version of CVP u are using . have you created Network VRU Labels.
    SIP Call With IVR Service is Terminated With Reason Code: Q.850;Cause=38
    Symptom:
    Any failure of the bootstrap VoiceXML Server fetches to Call Server causes the SIP IVR Service
    leg of call to be terminated by the recovery handoff TCL scripts on VoiceXML Server Gateway
    with a Q850 code of 38.
    Message:
    Q.850;Cause=38
    Cause:
    If the Unified CVP loses network connectivity, the VoiceXML Server Gateway is not able to
    get information from the IVR Service, and as a result a code 38 rejection is generated in the
    Gateway logs.
    remove the following lines from the network interface config in IOS:
    Action:
    no ip route-cache cef
    no ip route-cache
    no ip mroute-cache
    keepalive 1800
    no cdp enable
    This I got it from CVP 4.x Troubleshooting guide. http://www.cisco.com/en/US/docs/voice_ip_comm/cust_contact/contact_center/customer_voice_portal/cvp4_0/troubleshooting/guide/cvp40tsg.pdf
    and check also
    http://developer.cisco.com/web/cvp/forums/-/message_boards/view_message/1726816

Maybe you are looking for

  • Ipod makes clicking noise and won't be recognized by itunes.

    I've had this ipod for about 2-3 years (5th generation 30 GB) and all of a sudden it started making clicking noises when i started it. So i connected it to my computer and all it does is (1). Start up with the Apple Logo (2). Make that clicking noise

  • Macbook display

    My daughter's MacBook (white 13" - last model) has developed a display problem - sometimes it 'greys out' - you can still see the desktop behind but it loks like someone has placed tracing paper over the screen. It is an intermitent problem and somet

  • Placing in smart objects?

    I am trying to place a picture into one of my smart objects but it wont let me, it keeps placing the picture in its own layer.

  • Is there a workaround to no flash player?

    I cannot see some you tube videos because I don't have flash player. Is there a workaround?

  • No error in the Process Chain

    HI   I am Working In production support    Recently I am Facing a Problem in the Process chains    Actual Process chain consist of Local Chains(many)    Some times one Local chain does not trigger even the previous Local chain gets completed Sucessfu