How you search through arrays ?

Hey, how is it that you search through an array of ojects to find a specific value?
Eg
class Buildings
String name;
building [ ] build;
public Buildings ( String name, int max)
name = nam
maximum = max
build = new building[max]
in an abstract class i have an abstract public double getInsuredValue() as a method, so in the
class Flat and House, they both have their own getInsuredValue() method and in another method in the Buildings class I have made a method called
public Building createBuilding()
int type = 0;
for (int i = 0, i< maximum, i++)
if (type = 1)
build = new Flat(address, name, status and others- these are in the construct of the Flat extends Building class)
if (type = 2)
build = new House( address, name, money and others - these are in constuctor of House extends Build class)
Now what I want to be able to do, is search for the highest getInsuredValue() for a particular type of building, eg I know to find it for say all the types were just one building type
eg if it was just
build = new Building() and not ( build = new Flat() aswell as build = new House() you would go
--method name i have to use except ill take out parameter i have to use
public Building findHighestInsuredProperty()
Building highest = build[0]
double highestValue = highest.getInsuredValue()
for (int i = 0; i< maximum, i++)
if(build.getInsuredValue() > highestValue
highest = build[i]
highestValue = highest.getInsuredValue()
return highest;
but the method has a parameter in it called (int buildtype)
so for example if it was int = 1, i want it to just search through the array, look at the Flats and bring back highest, and if int = 2, i want it to look through the House ones and bring back value ? How do I do this? Thanks.

well maybe ive done something wrong before hand
the array is Building [ ] build;
in the class i have a method that adds building to array
public void addProperty (Property leftover)
           if (extra == null || numberofBuilids  > maximum)
                    return;
    build[numberOfBuilds] = extra;
    numberof Builds++
     }the next method i want to create a Building instance and return a reference to it
public Building createBuilding()
      String name;
      double type;
      double insu;
      Building build;
         for (int i = 0; i < maximum; i ++)
             name = Keyboard.readString ("Name: ")
            insu = Keyboard.readDouble("Insurance
             type = Keyboard.readBuilding ("type")
    if (type == 1)
               build = new House(name, type)
   if (type == 2)
              buid = new Flat (name, type)
  return build;
Is this right and does it add these instance to the array ?

Similar Messages

  • How do you search through posts?

    I'm having trouble with itunes u 'New URL box'...and I can't find how to search through posts! One post said to click on 'More Options' but I dont' see that either.

    A subscriber info dump is likely the fastest way.  If you're curious regarding other methods, you can also use the Data Link Explorer (CUDLE) tool which is in the Cisco Unity Tools Depot.  All extensions for all objects are referenced in the "DTMFAccessId" table.  The View menu has a Query Builder which you can use to compile a SQL query that searches for a digit string.  It's best to search for both the 10 digit string as well as an abbreviated string as Unity sees them essentially the same and they are usually should be associated with a single subscriber.  Once you find a match, you can use the "ParentObjectId" value associated with the DTMF access ID to look for a matching owner in the "GlobalSubscriber" table.  The ParentObjectId should match the SubscriberObjectId for a subscriber (assuming the DTMF access ID is assigned to a subscriber).  This is the same thing as looking at SQL; however, you are not directly accessing the DB so this is generally considered the safest way to browse and get a feel for where things are.
    Hailey

  • How to Search and Array for multiple occurrences of a value

    Hi,
    I am trying to search an array of doubles for a number and report the index location(s) of a number. I.e. -allow for repetition. Search and report all index[i] where the number is contained in the array. For example I have
    double[] myInputArray = new double[5];
    double[] myInputArray = { 1, 2, 3, 3, 5 }I know how to search through the array ONCE and return the first occurrence of a number:
    public double GetIndexOf(double Number) {
        for (int i=0; i<myInputArray.length; i++) {
             if (myInputArray[i] == Number){
                  return(i);
        return(-1);
      }How do I expand this code to report multiple index[i] locations if the number reoccurs in the array like the number 3 does in my example array above?

    The way the Java libraries do this type of operation (String.indexOf(), etc) is to specify the starting index along with what you want to find.
    Changing your example slightly (notice how I fixed your naming and more importantly, your return type):
    public int indexOf(double num) {
       return indexOf(num, 0);
    public int indexOf(double num, int fromIndex) {
        for (int i=fromIndex; i<myInputArray.length; i++) {
             if (myInputArray[i] == num){
                  return(i);
        return(-1);
    //usage to get all indices:
    for ( int index = -1; (index = indexOf(num, index+1)) != -1; ) {
       System.out.println(index);
    }Note that due to how floating point numbers work, you may find doing this on doubles (or any other operation that uses == with double arguments) to give you unexpected results.

  • AppleScript (or Automator?): How to search through online сhеss games?

    Hello.
    I would like to search for specific online сhеss games. Each game has a single adress. We are talking about millions of games. Obviously, it's far too long to index all the games. So I will set a limit and use the script at night. Conditions should be something like this:
    For adress example.com/game=NumberA to example.com/game=NumberB
    Search every web page containing SpecificWord
    Store wanted web adresses somewhere (so I could see the games by myself during the day)
    As you can see, I know nothing about Applescript and I don't know how to start, nor how the script can pick up adresses. I think it's possible and not difficult to code, just time consuming for the program to search through thousands of games.
    Should I use AppleScript or Automator? Should the script open Safari (or Firefox if possible) or can it search without any browser? Is it possible to simultaneously search through multiple pages/adresses? Maybe I could write several scripts for different ranges of games? If so, how many pages can I open at once? For instance I could disable images in Firefox to load quicker. How much time does it need to search for one game? 1, 2, 3, 4, 5 seconds?
    Any easy tutorials, examples of similar codes, advices, hints or tips are appreciated.

    Thanks for answering. Sorry that I was so unclear. My main problem was how to get urls and games id as variables. But then I thought there already should be programs doing web crawling. I have found Scrapy which use Python language.
    (Maybe I should edit my question, add Scrapy and Python as tags instead of applescript and automator. Is it possible?)
    I have Mac OS 10.6.8, Python 2.6.1. Scrapy needs at least Python 2.7 so I have downloaded the last version of Python (3.3).  I think I can handle the programming in Scrapy thanks to their tutorial. The most difficult part should be... how to install Scrapy. Don't laugh at me.
    I have entered "sudo easy_install Scrapy" in the terminal. But the terminal still uses Python 2.6.1. Python 3.3 is installed but I don't know how to clean update Python. If anyone knows, feel free...
    When I write scrapy in the terminal, here is what I get:
    Traceback (most recent call last):
      File "/usr/local/bin/scrapy", line 4, in <module>
        import pkg_resources
      File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg _resources.py", line 2556, in <module>
        working_set.require(__requires__)
      File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg _resources.py", line 620, in require
        needed = self.resolve(parse_requirements(requirements))
      File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg _resources.py", line 518, in resolve
        raise DistributionNotFound(req)  # XXX put more info here
    pkg_resources.DistributionNotFound: lxml
    It seems Scrapy also needs something called lxml. Right now I am trying to make Python 3.3 the default python version. Is there a web crawler GUI which already includes Python, Scrapy, lxml?
    By default I also have Python 2.4 and 2.5. Does the system need them? I prefer not to delete system files but together all Python versions weigh 500 MB.
    In regard to the real example URL: let's say instantchess.com. Here's a game URL: http://www.instantchess.com/?EXP=1&GPI=84094532
    84094532 is the game id. Let's say I want to search every Reti openings (thus the page must contain the word "Reti") from id 84000000 to 85000000 and store games id in my computer. If I have understood correctly, I need to search through the source code of the pages.
    Feel free to add any remarks, suggestions, ideas.

  • How to search for array in another array ?

    i want to search for array in another and when i got this array i want to take the next 5 bits  EX: array1 [ 4 8 7] , array2 [ 9 1 4 8 7 6 3 2 ] , output array [ 6 3 2 9 1]
    Thanks  

    I know we should be encouraging others to help them selves, but I had a solution that I think is what the user wants.  Attached is a VI that searches for a subarray in an array, and will return the index it is found at.  It will also return the input array, filtered if a match is found.  This VI just handles the double data type.
    Most of the code comes from an old post by Altenbach that I can't seem to find at the moment, but I saved a copy a while ago.  Props to him for posting it.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.
    Attachments:
    Filter Subarray - DBL.vi ‏18 KB

  • Searching through arrays part 3

       *  The moveTile method
       *  After the grid has been read and stored, the moveTile method
       *  takes in a single integer value that indicates a tile to move,
       *  and moves that tile into the blank tile's position, if it is a
       *  legal move. A move is only legal if the specified number exists
       *  in the grid, and if the specified tile's position is adjacent to
       *  the blank tile's position. The method returns a boolean value to
       *  indicate whether the move was made.
       * @param tileToMove The tile that is to be moved.
       * @return moveTile The boolean value which represents whether
       *                     or not the move was made.
      public boolean moveTile(int tileToMove){
        //set default boolean value to false
        boolean moveTile = false;
       //scans through the rows of the puzzle
        for(int scanRow=0;scanRow<grid.length;scanRow++){
          //scans through the columns of the puzzle
          for(int scanColumn=0;scanColumn<grid[0].length;scanColumn++){
           //scans through and checks if the desired tile exists
           //if it does exist, check if the '*' tile is beside it
          if(grid[scanRow][scanColumn]==tileToMove){
            //scans the tiles to the right of the tile being moved
            for(int besideRow=scanRow;besideRow<grid.length;besideRow++){
              //scans the tiles above the tile being moved
              for(int besideColumn = scanColumn;
                  besideColumn < grid[0].length;
                  besideColumn++){
                //scans the tile to the left of the tile being moved
                for(int besideRow2 = scanRow;
                    besideRow2 < grid.length && besideRow2 > 0;
                    besideRow2--){
                  //scans the tile under the tile being moved
                  for(int besideColumn2 = scanColumn;
                      besideColumn2 < grid[0].length && besideColumn2 > 0;
                      besideColumn2--){
                    //if the '*' tile is above or to the right of the tile
                    //being moved, then swap the files
                    if(grid[besideRow][besideColumn]== -1){
                      //create a temporary storage variable to store the
                      //value of the '*' tile
                      //if the '*' tile was above or to the right of the
                      //tile being moved
                      int temp;
                      //sets the value of the temporary storage variable
                      //to the value of the '*' tile
                      temp = grid[besideRow][besideColumn];
                      //sets the value of the '*' tile to the value of the
                      //tile being moved
                      grid[besideRow][besideColumn] = grid[scanRow][scanColumn];
                      //sets the value of the tile being moved to the value of
                      //the '*' tile
                      grid[scanRow][scanColumn] = temp;
                      //return the boolean value true since the tile was moved
                      moveTile = true;
                    //if the '*' tile is above or to the right of the tile
                    //being moved, then swap the files
                    if(grid[besideRow2][besideColumn2]== -1){
                      //create a temporary storage variable to store the
                      //value of the '*' tile
                      //if the '*' tile was above or to the right of the
                      //tile being moved
                      int temp2;
                      //sets the value of the temporary storage variable
                      //to the value of the '*' tile
                      temp2 = grid[besideRow2][besideColumn2];
                      //sets the value of the '*' tile to the value of the
                      //tile being moved
                      grid[besideRow2][besideColumn2] = grid[scanRow][scanColumn];
                      //sets the value of the tile being moved to the value of
                      //the '*' tile
                      grid[scanRow][scanColumn] = temp2;
                      //return the boolean value true since the tile was moved
                      moveTile = true;
        //returns the boolean true if the tile was moved and false if the tile
        //was not moved.
        //the default value is false
        return moveTile;
      }This is my code.... it works when the reference point of [0][0] is at the bottom left but when i changed my to string method to set the reference point of [0][0] at the top left.... it stopped swapping the tiles... it did give the correct boolean however

    This is my code.... ... and quite a lot of code I might say (nicely documented though). I
    strongly (sic) suggest that you strengthen your preconditions a bit, i.e.
    don't just fill your grid[][] but keep track of the blank position also (just two
    member variables).
    Since you're dealing with a two dimensional thing, both a row and
    column index are more appropriate than a single index number, although
    the latter can easily be converted to the former. Let's denote the index
    pair of the blank cell as bx, by.
    Here's a simple method that determines whether or not an (x,y) pair
    denotes a valid index pair in the grid:boolean isValid(int x, int y, char v) {
       try {
          return grid[x][y] == v;
       } catch (ArrayIndexOutOfBoundsException aioobe) {  }
       return false;
    }... this method not just tests the validity of the (x,y) index values: it also
    checks whether or not the (x,y) cell contains a 'v', whatever 'v' may be.
    Now suppose you want to move a tile at position (x,y) to the blank
    position (xb, yb). Here's how you swap those two positions:boolean swap(int x, int y) {
       if (isValid(x, y, grid[xb][yb]) {
          char tmp= grid[xb][yb];
          grid[xb][yb]= grid[x][y];
          grid[x][y]= tmp;
          xb= x; yb= y; // update the blank cell position
          return true;
       return false;
    }The four neighbours of a cell (x,y) are easily found and a bit of logic
    operator hacking yields:boolean move(int x, int y) {
       return swap(x-1, y) || swap(x+1, y) || swap(x, y-1) || swap(x, y+1);
    }Finally, if you want to move a cell (x,y) containing a star '*' to the blank
    cell, all you have to do is this:public boolean moveTile(int x, int y) {
       return isValid(x, y, '*') && move(x, y);
    }Note that this last method is just a bit of makeup. You could join it with
    the (non-public) 'move' method if you want.
    Also note that a bit of functional decomposition and factoring results in
    a lot less code.
    kind regards,
    Jos

  • How do you search through configured Alternate Extensions to correct error message : The phone number or extension has already been assigned to some other object.

    When configuring a new Unity Voicemail Account I receive this message : The phone number or extension has already been assigned to some other object. I understand that this means that the 10 digit number I am trying to configure as the alternate extension for this user is already configured for another object with Unity.
    I need to search by the 10 digit number and determine where it is configured so I can change it and map to the correct end user.
    I have attempted to to search Users via DTMF Access ID using the 10 digit number with nothing being returned via that search.
    How do I Search all of the copnfigured Alternate Extensions within our Unity Server?

    A subscriber info dump is likely the fastest way.  If you're curious regarding other methods, you can also use the Data Link Explorer (CUDLE) tool which is in the Cisco Unity Tools Depot.  All extensions for all objects are referenced in the "DTMFAccessId" table.  The View menu has a Query Builder which you can use to compile a SQL query that searches for a digit string.  It's best to search for both the 10 digit string as well as an abbreviated string as Unity sees them essentially the same and they are usually should be associated with a single subscriber.  Once you find a match, you can use the "ParentObjectId" value associated with the DTMF access ID to look for a matching owner in the "GlobalSubscriber" table.  The ParentObjectId should match the SubscriberObjectId for a subscriber (assuming the DTMF access ID is assigned to a subscriber).  This is the same thing as looking at SQL; however, you are not directly accessing the DB so this is generally considered the safest way to browse and get a feel for where things are.
    Hailey

  • How to search through an excel spreadsheet for a number based on restrictions that you input as a user and print them out?

    Hi there guys
    I'm trying to write a labview program and i'm new to the program. I need the program done asap. First the user inputs the row number and then based on the row number it opens and reads an excel spreadsheet file which is just a table and it outputs the numbers corresponding to the column I ask for. How do I go about doing that? I saved the file as a .lvm so Labview could read it. Its a project for school and I have no idea how to start it. Any help would be greatly appreciated.
    Thanks guys a lot 

    Ummm... what file did you save as .lvm, and what does this have to do with an Excel file? To read/write Excel files you need to use ActiveX. There are a couple of shipping examples on how to do this in LabVIEW. Plus, this has been asked like a zillion times, so there's tons of examples in this forum if you just do a search. Plus, there's an Excel thread that has lots more examples.

  • Searching through arrays part 2

    lets say i have the following 2d array
    1 2 3 4 5
    6 7 8 9 10
    11 12 13 14 15
    how would i loop through all the elements and check to see if they are in order
    with my array being in the format [row][column] so [0][0] would be 11

    In your previous 2 threads regarding 2-dimensional arrays you have been given code for working with 2-d arrays, and references to the Java Tutorial's arrays section. What is it that isn't working? Post the problem code and someone will help, but I'm not willing to write the solution for you.

  • Searching through arrays part 4

    woohoo! thx to jos for helping me finish the first method
    now that i can swap the tiles
    1 2 3 4
    5 6 7 8
    9 10 11 -1
    how would i check to see if they are in sequential order with -1 being the last element

    package com.allmycode.first;
    public class Simple {
         public static void main(String[] args) {
              int[] array = new int[]{1,2,3,4,1,6,7,-1};
              int aux= Integer.MIN_VALUE;
              if ((array[array.length-1])!=(-1))
                   System.out.println("wrong last index");
              for (int i = 0; i < array.length-1; i++) {
                   if (array<aux){
                        System.out.print("Wrong inside loop" + "position: "+ i);
                        break;
                   aux=array[i];

  • Can you search through text in an InDesign book?

    I need to do a find/replace on a certain string of text throughout my book in InDesign (made up of multiple document chapters).  Is this possible?  Or do I need to open each document individually and do a find/replace?
    Thanks.

    You can do a Find/Change on all OPEN documents.

  • How to search text in the table?

    Suppose, I've selected some fragment in my document, and I need to find and replace some text in it. Everything is ok, untill I select a part of a table with this text. Does anyone has idea, how to search through the selected cells in the table? Or, just how to iterate them?
    Thanks!

    var doc = app.ActiveDoc;
    var tbl = doc.SelectedTbl;
    // Navigate to the first selected row.
    var row = tbl.FirstRowInTbl;
    while (row.ObjectValid() === 1) {
        if (row.id === tbl.TopRowSelection.id) {
            break;
        row = row.NextRowInTbl;
    // Process the selected rows.
    while (row.ObjectValid() ===1) {
        cell = row.FirstCellInRow;
        while (cell.ObjectValid() === 1) {
            if ((cell.CellColNum >= tbl.LeftColNum) && (cell.CellColNum <= tbl.RightColNum)) {
                // Do something here...
            cell = cell.NextCellInRow;
        if (row.id === tbl.BottomRowSelection.id) {
            break;
        row = row.NextRowInTbl;
    This should do what you want.
    Rick

  • How to search tables and views used in the code of oracle fmb 6i from another form???

    Hii guys, this is a very interesting question and i hope that it will have ample amount of answers.
    My requirement is to know the number of tables and views and backend functions/procedures which are used in the code written in the oracle forms 6i,
    all i want is to display whole views, tables or functions/procedures which are written  in the code of a particular fmb, i do have the path of that fmb and i want to read the code and search through it's entire code for the tables/views/backend procedures/functions written in the code. So how to search through the entire code of a particular form (6i) and make it display through another form.
    I am using oracle forms 6i.
    Please help me out....
    With Regards:
    Ankit Chandra

    Here is a modified dealForm.jsp that merges the 2 steps - both symbol submission and Yahoo convert is done by it. Play with it and add your DB code to it:
    <html>
    <head><title>IPIB Database Selection</title></head>
    <body bgcolor="#DFDFFF">
    <H1><CENTER>IPIB Database Selection</CENTER></H1>
    <font size=4>
    <%@ page language="java" %>
    <%@ page import="java.net.*,java.io.*,java.util.*" %>
    <%
    String symbol = request.getParameter("symbol");
    if (symbol != null) {
    String urlString = "http://finance.yahoo.com/download/javasoft.beans?SYMBOLS=" + symbol + "&format=ab";
    try {
    URL url = new URL(urlString);
    URLConnection con = url.openConnection();
    InputStream is = con.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line = br.readLine();
    StringTokenizer tokenizer = new StringTokenizer(line,",");
    String name = tokenizer.nextToken();
    name = name.substring(1, name.length()-2);
    String price = tokenizer.nextToken();
    price = price.substring(1, price.length()-2);
    %>
    <p>
    Original line from yahoo <%= line %>
    </p> <p>
    Name: <%= name %>
    </p> <p>
    Price: <%= price %>
    </p> <p>
    Pub DB processing code from dealLoad.jsp here
    </p>
    <%
    } catch (IOException exception) {
    System.err.println("IOException: " + exception);
    } else { %>
    <form action="dealForm.jsp"method="GET">
    <p>Enter Symbol: <input size="20" name="symbol">
    <inputtype="submit" value="Submit">
    </p></form>
    <% } %>
    </font>
    </body>
    </html>

  • How to search in 2d array in different direction

    the method will take a string argument and convert them into char and try to find them in a 2d array.
    It is more like a word puzzle(wordSearcher).Here's what i've done so far...
    public void find(String word)
    for(int a = 0; a < word.length(); a++) {
    char oneChar = word.charAt(a);
    String oneStringchar = String.valueOf(oneChar);
    // Searching through in South Direction
    for(int i = 0; i < g.length; i++) {
    for(int j = 0 ; j < g.length ; j++) {
    if (oneChar == g[i][j]) {
    canvas.draw(oneStringchar, (i * WORD_SIZE) + POS_X, (j * WORD_SIZE) + POS_Y);

    i dont know the code to wrtie a java program that
    searches for names and grades in a program...can
    anyone write the code that searches for names and
    grades in an array?Let me give you some facts:
    1. Yes, most of us can.
    2. No, most of us are not likely to write that code for you.
    3. It makes a difference HOW the names and grades are stored in the array
    Is this a 2D array, with names indexed by [0] and grades indexed by [i][1]. Or is this a 1D array with names indexed by [i*2] and grades indexed by [i*2 + 1]?
    Or is it two completely separate arrays, with the grades of a person indexed in the same position in a grades array as the names are indexed in the names array.
    this makes a big difference as to how you should proceed.
    By looking at your post, however, you haven't even given the slightest bit of thought to that, yet, because you didn't post that information.
    If you don't at least TRY to figure this out for yourself, you're not going to find much help here.
    - Adam

  • Searching through an array of objects

    Hi, I am currently working on an assignment where I have to create a class called Persons with data fields of Name(String),age(int),income(int).
    All the values including the string values for name and values for income and age are all randomly generated and are stored in an array of objects of class "Persons".
    The array size is user specified.
    What I must attempt to implement now is to make a search feature that lets the user search through the array of objects for a particular name.
    I'm having some bad luck trying to implement this feature.
    If anyone can help me, I would greatly appreciate that!
    Cheers.

    Hi, Thank you for the prompt reply.
    I do not yet know HOW to start this,I mean I know how to search for individual characters in an element of an array, but to search for whole strings I am quite unsure.
    public class Persons
        //data fields
        private String name;
        private int age;
        private int income;
        //Constructor for Class Persons
        public Person(String[] name,int[] age,int[] income)
              String[] tempName = name;
              int[] tempAge = age;
              int[] itempIncome = income;
        //Instance method for returning some basic values about personal data
        public void toString(Persons ofChoice)
            System.out.println("Persons Data");
            System.out.println("Name: " + ofIntrest.name);
            System.out.println("Age: " + ofIntrest.age);
            System.out.println("Income: $" + ofIntrest.income);
    }This is my Persons class code, but I am quite stumped how to search for whole strings at the time being.

Maybe you are looking for