Problems Using an Array of Objects

I have taken some time off from java and have aparently forgot something. I have a program which has one parent class "Car" with three child classes"Sedan", "Sport", "Suv" and one interface. The "Car" class contains three accessor and mutator methods, and the child classes also have three accessor and mutator methods. In my main I create an array Car[] carArray = new Car[6]; and instantiate. I can call the methods of the parent class but am unable to call the methods of the child classes. I need a little help to get me in the right direction to get these cobwebs out of my skull. Here is a sample of what I'm doing:
//from my main method
Car[] carArray = new Car[3];
carArray[0] = new Sport("Chev", "Camaro", 1995, 4500.67, 120000);
carArray[1] = new Sedan("Ford", "Taurus", 1997, 3689.55, 40000);
carArray[2] = new Suv("Honda", "Pilot", 2003, 6955.99, 67000);
for(int i = 1; i < carArray.length(); i++)
    carArray.getYear(); //getYear() is from the parent "Car" class and works just fine.
carArray[i].getValue(); //getValue() also from the parent "Car" class and works just fine.
carArray[i].getMiles(); //getMiles() from parent "Car" class and works.
carArray[i].getMake(); //getMake() is part of the child class and gives me an error: "cannot find symbol. symbol: variable getMake()
carArray[i].getModel(); //getModel() is also a part of the child classes and also cannot find symbol.
{code}
I have imported my package with my parent and child classes correctly and have tried putting them all in the same folder, so I think I have a failure in logic. Can someone help me straighten this out in my head? :) Much thanks

"Is it A or B"?
"Yes"
Meaning "either one."
The parent class doesn't have to be abstract as far as Java is concerned, but it seems to me you'd want it to be abstract. Will you ever be creating just a plain old Car (as opposed to a Sedan or Suv)?
You just said "doesn't work," without providing any details about what you tried or what the exact problems was, so it's impossible to offer any specific, concrete advice. Here's an example that shows one way things might fit together.
   * inteface, to define the type, with 3 methods: add(), iterator(), and contains()
  public interface List {
    boolean add(Object obj);
    Iterator iterator();
    boolean contains(Object obj);
   * abstract base class, to implement methods that don't depend on specific implementations
   * (just contains() in this case
  public abstract class AbstractList implements List {
    public boolean contains(Object obj) {
      for (Iterator iter = iterator(); iter.hasNext ();) {
        if (iter.next ().equals (obj)) {
          return true;
      return false;
   * concrete subclass
   * provides concrete methods that depend on the specific implementation
  public class ArrayList extends AbstractList {
    private Object[] elements = new Object[256];
    int size = 0;
    public boolean add(Object obj) {
      if (size == elements.length) {
        // create a larger array and copy over existing elements
      elements[size++] = obj;
      return true;
     * anonymous inner class that implements Iterator
    public Iterator iterator() {
      return new Iterator() {
        private int nextIndex = 0;
        public boolean hasNext () {
          return nextIndex < size;
        public Object next () {
          return elements[nextIndex++];
  }A few things to note:
0. The above are based on the classes of the same names in java.util, but are stripped down for simplicity. If something doesn't look right (like missing methods on List and Iterator) it was done to keep the example clean and simple.
1. We could skip either the interface or the abstract class or both, or the abstract base class could be concrete. Java doesn't care. We do what makes sense for our design.
2. Here we define an interface because we want to define a pure type with no implementation. Anybody anywhere can implement a List however they want, and as long as it meets the contract of our interface, it can be used by any code expecting a List.
3. We define the base class AbstractList because there are methods that have a reasonable default implementation that can be reused by subclasses. In this case, contains() doesn't do anything that depends on the specific implementation, so it can be defined in the base class. All the subclasses can use that implementation of contains(). Of course, any subclass is still free to override contains() to provide its own implementation if it wants.
4. An implementation of List can extend the base class, AbstractList, but it doesn't have to. It could just implement List and provide its own implementation of contains().
5. The base class is abstract because some methods don't have a default implementation that can be reused. Both add() and iterator() depend on the specifics of the implementation. They both need direct access to the internal backing store. If we had another concrete implementation, LinkedList, its backing store would be a privately defined class of Node that contains the elements and pointers to previous and next. There would be no array, and add() and iterator() would be written very differently. There's no way we could have written add() and iterator() in a way that would have worked for both backing stores.
6. All methods in an interface are public and abstract, even if you don't declare them that way.
7. A class that implements an interface or extends an abstract class must provide implementations for all the abstract methods in both, or else must be itself declared abstract.
8. When a class extends another class, it also implicitly implements all the interfaces that the parent class does.
9. A class with one or more abstract methods must be declared abstract, but any class can be declared abstract, even if it has no abstract methods.
Edited by: jverd on Mar 27, 2010 9:12 AM

Similar Messages

  • Please Help!-Problem using Image[ ] array

    Hi everyone,
    I have this real confusing bug in my code which i am not able to fix.
    Image[] tmpImg = new Image[Img.size()];   /initializing an image array tmpImg
                for(int i=0; i<Img.size(); i++) {          //i require this display the image a number of times
                try{
                       icon = Image.createImage("/Icon.png");
                       im = new ImageItem("Image", icon,ImageItem.LAYOUT_CENTER,"image"); //using a imageItem to display the image in a form
                       form.append(im);
                       icon2 = Image.createImage("/Icon2.png");
                           im2 = new ImageItem("Image2",icon2,ImageItem.LAYOUT_CENTER,"image"); //using another imageItem to display the second image
                      form.append(im2);
                       if (imageValue.elementAt(i) == "availableImage") {
                           tmpImg[i] = icon;  //assigning the value to the image array based on a condition from a String Vector
                      if (imageValue.elementAt(i) == "offlineImage") {
         tmpImg[i] = icon2;   //assigning the value to the image array based on a condition from a String Vector
                      } catch(IOException err) {}
           System.out.println(tmpImg[0]);
           System.out.println(tmpImg[1]);
           System.out.println(tmpImg[2]);
           System.out.println(tmpImg[3]);
           return tmpImg;
       }My problem is that when i try to print tmpImg[0], tmpImg[1] etc all the values are printed null. But the Image is created and being displayed on a ImageItem. but i am not able to assign the image to the image array 'tmpImg' which is within an if condition.
    Can anyone tell me why is this so. I would be grateful
    Thank You

    Thank u deepspace
    I got a lil' frustrated, so completely did not think that way. The code is working now
    Thanx again

  • One problem using TI to catch Objects allocation

    To get objects allocated during runtime, I use byecode intrumentation, JNI function interception, and VM Object Allocation Event of TI. But I still miss the allocation of many objects, about 15% of all the heap objects. why this happens, the objects missed are "[I", "[B","[C","[S","Ljava/lang/Class",and "Ljava/lang/Object".
    My experiments are based on Eclipse3.2 and JDK1.5.9 to catch objects allocation During the process from the beginning of Eclispe's start  to the successfully running of a simple app developed in Eclipse.
    please help to give some hints. Thanks in advance.
    Message was edited by:
            danvor                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    You don't say much about your instrumentation. Do you insert code after each newarray byte code so that you get a notification when arrays are allocated. If not, that should help explain the array objects you are missing. There were a few issues with the VMObjAlloc event in 5.0 that were resolved in 6.0. You might want to check that release to see if you get more events for objects that can't be detected with instrumentation.

  • Problem using different plugins via OBJECT tag

    Hi all,
    before installing JRE 1.5.0_06 everything was well. I had 3 different JREs (1.3.1_02, 1.3.1_08, 1.4.2_06) installed on one Windows system which could be invoked in Internet Explorer 6 for an applet as described in http://java.sun.com/j2se/1.5.0/docs/guide/plugin/developer_guide/version.html
    example:
    <HTML>
    <HEAD>
    <TITLE>Java Plugin 1.3.1_08</TITLE>
    </HEAD>
    <BODY>
    Java Plugin 1.3.1_08:�
    <OBJECT classid="clsid:CAFEEFAC-0013-0001-0008-ABCDEFFEDCBA" width="150" height="25">
    Plugin missing
    <PARAM name="code" value="HelloWorld.class">
    </OBJECT>
    </BODY>
    </HTML>
    (Note: The output of my HelloWorld class is the VM's version number.)
    After installing 1.5.0_06 it doesn't work anymore. The new 1.5.0_6 is always used. Does anybody have a clue?
    Thanks in advance
    Peter

    I've seen a similar problem that didn't seem to exist with JRE 1.5.0_05 but does with 1.5.0_06. On the JRE 1.5.0_06 workstation the Windows registry contains CAFEEFAC-... entries for what looks to be all 1.3/1.4/1.5 JREs and points them all to the 1.5.0_06 JRE plugin dll, even though there is still a 1.4 JRE on the workstation. So even when you specify an OBJECT tag with a classid such as classid="clsid:CAFEEFAC-0014-0001-0010-ABCDEFFEDCBA" that should load the 1.4 plugin by design, the 1.5 plugin is loaded. This seems to defeat the multi-version JRE support. The JRE 1.5.0_05 workstation on the other hand didn't overwrite CAFEEFAC-... Windows registry entries for previous JREs, and properly loads a specfic JRE's plugin when specified by a CAFEEFAC-... classid in the OBJECT tag.

  • Problem using IMAQ Array to Color Image vi

    I am doing some pixel manipulation & while going from an image to an Image Pixels (U64) array using IMAQ Color Image to Array VI I cannot see the image once it is modified.
    I am...
    1) converting the image to the 64 bit pixel data using IMAQ ColorImage to Array.vi
    2) doing the manipulation
    3) converting back to an image using the IMAQ Array to ColorImage.vi using the 64 bit input.
    What I get is...
    1) a black image with data behind it... meaning... if I take the magnifier tool and go to the approximate locations of my image where I expect to find the manipulated data, it is there.
    2) cast that image to a 32 bit image & still get a black image for the output.  The data however is no longer there and appears to have been stripped.  
    3) no error's out of any VI's...
    TIA  

    With Vision 2009 situation is not better.
    It happened because U64 image displayed in full scale. So, if you have full range of intensities (from 0 to 65535), then you can see something. But if your intensities in small range, for example, 0...255 in all channels, then you will see black image.
    Feel differences:
    It should be possible to map U16 values into U8 display range  with given range (like IMAQ WindDisplay Mapping does), but right now this feature available for I16 images only, not for U64. What you can do is following - map each channel to U8 (with linear LUT, for example), put channels together, then display 32 bit RGB instead of U64.
    Andrey.

  • MICR printing problem using the Crystal ReportDocument object in C# app

    We developed a small C# windows program 6 months ago that reads a bank draft record and uses a Crystal Report form to print the draft (using ReportDocument() object and the PrintToPrinter() method).  This has been working fine for 6 months. (using .Net 2.0 Framework and Crystal Reports .Net plugin included with VS 2005 on client machine - CRRedist2005_X64.msi)
    Now the requirements have changed to put a MICR line at the bottom ot the draft check and print.  We have updated a similar Crystal draft report form and printed from Crystal Viewer - this works fine.  But when we update the Crystal report form used in the C# application, with the same MICR commands, using the same MICR printer, and the same user trying the print, it does not work.  The MICR commands are printed on the draft just like regular text, instead of being interpreted by the printer as MICR commands.  Must be something within the Crystal Reports .Net redistributable that is causing it to work incorrectly because it works correctly from the same users PC using Report Viewer.
    Note:  The MICR field on the Crystal Report contains the following chars:
           &%STHPASSWORD$&%SMD' MICR '$&%STQ$
    When we print, the above chars just print out like text
    Can anybody help with any suggestions ?
    Are they any hotfixes that address this issue of PCL commands not recognized on printer?

    The app that is working is a C++ vendor app, however the Crystal piece is seperate piece that uses the Crystal Report Viewer to pull up the draft report. The print button is then hit within Crystal Report Viewer and the draft prints correctly.
    - so the above app is using the Report Designer Component (craxdrt.dll) and as such it is not using the .NET assemblies...
    For the app that is not working, we are not using Crystal Report Viewer, but are using the ReportDocument object, from the Crystal .Net Redistributable (referenced above), embeded into our C# app. The app executes a PrintToPrint command against the identical Crystal report, however, running it this way, the MICR command that is embeded into the report is not recognized by the MICR printer. The output seems to jumble the MICR command that I posted earlier in the thread and does not keep the command in a readable format for the MICR printer.
    - the above is not using the Report Designer Component (craxdrt.dll). It is using the .NET assemblies and thus the .NET framework.
    Have you been able to get .NET to recognize / see the fonts in that label I mentioned on  6/27/08?
    Ludek

  • Problem using an array of MCs for a menu

    I'm creating an animated menu using a series of MCs and wrote
    a function to reset them back to frame 1 whenever you choose a new
    menu item. I couldn't get it to work so I did a trace to see if I
    could even get the value of the current MC's frame & I get
    "undefined". I only have 2 MCs in the array right now to keep
    things simple. Any idea of what I'm doing wrong?

    Hi,
    there is a simple way to achieve that.. Put all your buttons
    in one mc and call that mc buttonsMc.
    With a for in loop you will be able to do what you want. Ill
    post a version that will escape the movieclip button that is
    pressed; mainly because usually you want to reset all the other
    buttons but not the one pressed. You just have to pass as a
    parameter the name of the movieclip button to the function .. here
    is the code:

  • BI XI - problem using SEND/TO Business Objects Inbox?

    It seems the user search (Look For:) function is not working, so we can never have any users in the "Available Recipients" box to select.
    Anyone else experience this problem and found what is the cause?

    I think by default this is disabled. If you add view access to everyone in the CMC\folders\user folders. It should work.
    Regards,
    Tim

  • Problem using associative arrays in vb6 with ORAOLEDB for Oracle 10g

    The following vb6-code works fine with MS OLEDB (in MDAC 2.8) but not with Oracles OLEDB for 10g. Any suggestions for making it work?
    'vb6-code:
    Set rs = New ADODB.Recordset
    Set rs.ActiveConnection = oConn 'oConn is already initiaded - code not included here.
    rs.Source = "{call PCK_PW_RF_PERSON.P_PW_BIRTHDAY('BURSDAG','2008','01',{resultset 200000, PARAM1,PARAM2,PARAM3})}"
    rs.LockType = vntLockType
    rs.CursorLocation = adUseClient
    rs.CursorType = vntCursorType
    rs.Open
    Databaseobjects involved:
    PACKAGE "PCK_PW_RF_PERSON" IS
    TYPE     tpv_param1     IS TABLE OF VARCHAR2     INDEX BY BINARY_INTEGER;
    TYPE     tpv_param2     IS TABLE OF VARCHAR2     INDEX BY BINARY_INTEGER;
    TYPE     tpv_param3     IS TABLE OF VARCHAR2     INDEX BY BINARY_INTEGER;
    PROCEDURE P_PW_BIRTHDAY
         pv_i_sreportid          IN VARCHAR2,
         pv_i_year          IN VARCHAR2,
         pv_i_month          IN VARCHAR2,
         PARAM1               OUT tpv_param1,
         PARAM2               OUT tpv_param2,
         PARAM3               OUT tpv_param2
    IS
         CURSOR X IS select '1' AS PARAM1,'2' AS PARAM2,'3' AS PARAM3 FROM DUAL;
         i NUMBER DEFAULT 1;
    BEGIN
         FOR c IN X LOOP
              PARAM1(i)           := c.PARAM1;
              PARAM2(i)           := c.PARAM2;
              PARAM3(i)          := c.PARAM3;
              i := i + 1;
         END LOOP;
    END P_PW_BURSDAG;

    I receive this error:
    "ORA-06550: line 1, column 111:
    PLS-00201: identifier 'PARAM1' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored"

  • Array of objects in class private data and calling overridden VIs on these objects?

    Hello
    I am developing part of an application using the actor framework and have run into problems.
    I have a several actors and will try briefly describe them and their intended functionality. All actors are started by a Controller actor and in the actor core for the controller I have the possibility to do a lot of intiliazation etc.
    Logger:
    Has a message (Send Log Message) that other actors can use to write to the log. It is supposed to take a string input and a log level (error, warning, debug etc). This message chain sends data to the actor core with a user event.
    The Actor Core of Logger is supposed to save the incoming message to a log, but should be able to do it in several different ways (file, database, email or whatever).
    Logger Output:
    Abstract class that has a dynamic dispatch vi called "Write Output" that all it's children are supposed to overwrite.
    Logger Output File
    Child of Logger Output and overwrites "Write Output" to save the string to a file on disk.
    Problem:
    I want to be able to set up the actor core for Logger once and for all but still be able to create new children of "Logger Output" and have them be handled in the Logger actor core.
    My idea was to have Logger use an array of objects as private data and initialize this array in the Controller actor core.
    In the logger actor core I could then auto index the array and use each element (each Logger Output child) and the abstract "Write Output" vi to get the correct functionality.
    HOWEVER, I cannot get this to work properly and I think I have misunderstood something or stared myself blind on this problem. I have tried 3 different methods when it comes to private data for Logger.
    1. Labview Object
    2. Array of Labview Object
    3. Array of Logger Output Object
    Of these 3 methods, I can only get the first one to work and that doesn't accomplish what I want in the end (being able to add more classes without changing private data / actor core for Logger).
    I have included 3 screenshots that show snippets of 2 of the actor cores and the private data. File names should correspond to my description above.
    The screenshot "Logger actor core.png" shows a very fast test of the 3 different methods I described above. Each of the 3 tunnel inputs to the event structure can be wired to the "Reference" input of "To More Specific Class", but only method 1 (Labview Object) works.
    If you need additional information / screenshots or whatever please ask.
    Thanks in advance
    Attachments:
    Logger ctl.PNG ‏8 KB
    Logger actor core.PNG ‏25 KB
    Controller Actor Core.PNG ‏11 KB

    Thanks for the reply and sorry for the confusing OP. It was meant as a quick test and a way to skip making 10+ screenshots .
    I updated the actor core for the Controller and Logger to be less confusing (hopefully) and attached 2 screenshots.
    I agree with you that it would be a good idea to make a message for the controller that can launch new children of the L" abstract actor, but for these tests I have just launched it the easy way (dragging it to the controller actor core).
    Both Logger Output and Logger Output File are actors and in Logger Output there is a dynamic dispatch vi called Write Output that I want to override in all its children.
    The problem is when I run the actor core of Logger (see the screenshot) only the abstract version (the one in Logger Output) of Write Output is executed, not the overridden version from Logger Output File.
    When I did the same thing with the actor cores looking like the did in my original post, then the correct overridden version got executed when I used the method with one Labview Object in private data (not any array or an array of Logger Output objects).
     EDIT: I just tried to have the Logger private data be a single Logger Output object and writing the Logger Output File to that piece of private data in the Controller and the correct Write Output override method gets called now. So apparently I have done something stupid when it comes to creating the array of Logger Output objects and writing them in the controller? The private data is in the Logger actor so I have simply right clicked and chosen "New VI for Data Member Access" and chosen "Write" for "Element of Array of Logger Output Objects".
    Attachments:
    Controller Actor core updated.PNG ‏10 KB
    Logger actor core updated.PNG ‏24 KB

  • H:dataTable value as array of Strings vs array of objects

    I'm trying to use a h:dataTable with an h:inputText as one of the columns. If my bean returns an array of Strings, then the h:dataTable can't update them. (I added a submit button that just updates the fields and returns to the current page.) If I use an array of objects, in this case a simple wrapper class, it works. Why is this?
    This won't work:
    public class EmailBean {
        private String[] m_emails;
        public String[] getEmails() {
            return m_emails;
        public void setEmails(String[] emails) {
            m_emails = emails;
    }But this will:
    public class EmailBean {
        private Email[] m_emails;
        public EmailBean() {
            m_emails = new Email[] {
                    new Email("[email protected]"),
                    new Email("[email protected]"),
                    new Email("[email protected]")
        public Email[] getEmails() {
            return m_emails;
        public void setEmails(Email[] emails) {
            m_emails = emails;
    }

    public class Email {
        private String email;
        public Email(String email) {
            this.email = email;
        public String getEmail() {
            return email;
        public void setEmail(String email) {
            this.email = email;
    }For the one that uses the Email class, I use this:
    <h:dataTable value="#{emailTestBean.emails}"
                                  var="email">
         <h:column>
              <f:facet name="header">
                   <h:outputText value="Email Address" />
              </f:facet>
              <h:inputText value="#{email.email}" />
         </h:column>
         <f:facet name="footer">
              <h:commandButton value="Submit" />
         </f:facet>
    </h:dataTable>Otherwise I don't need the extra ".email":
    <h:dataTable value="#{emailTestBean.emails}"
                                  var="email">
         <h:column>
              <f:facet name="header">
                   <h:outputText value="Email Address" />
              </f:facet>
              <h:inputText value="#{email}" />
         </h:column>
         <f:facet name="footer">
              <h:commandButton value="Submit" />
         </f:facet>
    </h:dataTable>

  • Passing array of objects from java to oracle.

    Hi,
    We have the following structure in oracle.
    We have a nested table type of varchar2(50).
    type var_tab is table of varchar2(50);
    We have one object type with one member as varchar2 and another one as var_tab type.
    type attribute_obj is object(
    attrib_name varchar2(100)
    ,attrib_val var_tab
    Then we have table type of that object type,
    type table_tab is table of attribute_obj;
    Then we have one object type with one member as varchar2,another member as integer and another one as table_tab type.
    type prod_obj is object(
    pr_name varchar2(100), tb_flag integer
    ,pr_attrib table_tab
    Then we have table type of this object type,
    type prod_tab as table of prod_obj;
    So, the total structure is something like this;
    'OS','OS_NAME', 'Windows'
    'Linux'
    'UNIX'
    'OS_VERSION','XP'
    'RED HAT'
    'SOLARIS'
    so, basically we have
    x prod_tab:=prod_tab();
    x(3):=prod_obj('OS',0,table_tab(attribute_obj('OS_NAME',var_tab('Windows','Linux','UNIX')),attribute_obj('OS_VERSION','XP','RED HAT','SOLARIS'))));
    And this how we call the procedure ---
    all_prod_comb_pkg.sp_main(x)
    The procedure deifinition is -
    procedure sp_main ( p_prod_arr prod_tab);
    Please suggest a way so that we can implement the same structure in Java and then call the procedure using that array of objects.
    regards,
    Dipankar.

    Dipankar,
    There's a separate example of how to map Oracle OBJECTs to JDBC STRUCTs.
    Study that one and combine the two. Not difficult (in my opinion :-)
    Or search the JDBC forum for the words "STRUCT" and "ARRAY".
    (What, you want me to do your coding for you?)
    Good Luck,
    Avi.

  • Array in object overwrite problem

    Hi
    hope you can help me with this as i've already been using too much time solving it myself :)
    I got a Board class which have an ArrayList<ArrayList<Integer>> as attribute. The Board class is controlled from my service class. I need to create a lot of boards which all needs different ArrayList<ArrayList<Integer>> input, so i made a for loop which creates the Boards. The problem is however when i change the variable i used to create the object the values also change inside the object even though the create method have already been called. English isn't my native language so it's a bit hard to explain :) Please ask if there's something you don't understand.
    thanks in advance!
    I made a temporary solution by making a 3d arraylist so i won't have to overwrite any values but thats not rly a good solution as it's starting to give me problems elsewhere.
    the method that creates the boards is Service.importCSV()
    model.Board
    package model;
    import java.util.ArrayList;
    public class Board {
         private String controleNumber;
         private ArrayList<ArrayList<Integer>> numbers = new ArrayList<ArrayList<Integer>>();
         private ArrayList<ArrayList<Integer>> remainingNumbers = new ArrayList<ArrayList<Integer>>();
         public Board(String controlenumber, ArrayList<ArrayList<Integer>> numbers) {
              this.controleNumber = controlenumber;
              this.numbers = numbers;
              this.remainingNumbers = numbers;
         public String getControlenumber() {
              return controleNumber;
         public void setControlenumber(String controleNumber) {
              this.controleNumber = controleNumber;
         public ArrayList<ArrayList<Integer>> getNumbers() {
              return numbers;
         public void setNumbers(ArrayList<ArrayList<Integer>> numbers) {
              this.numbers = numbers;
         public void setRemainingNumbers(ArrayList<ArrayList<Integer>> remainingNumbers) {
              this.remainingNumbers = remainingNumbers;
         public ArrayList<ArrayList<Integer>> getRemainingNumbers() {
              return remainingNumbers;
         public String toString() {
              return String.valueOf(controleNumber);
    }service.Service
    package service;
    import gui.MainFrame;
    import java.io.BufferedInputStream;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import ramdao.BoardDao;
    import model.Board;
    public class Service {
         private static ArrayList<Integer> numbers = new ArrayList<Integer>();
         public static List<Board> getAllBoards() {
              return BoardDao.getAllBoards();
         public static Board createBoard(String controleNumber, ArrayList<ArrayList<Integer>> numbers) {
              Board board = new Board(controleNumber, numbers);
              BoardDao.store(board);
              return board;
         public static void deleteBoard(Board board) {
              BoardDao.remove(board);
         public static Board checkFor(int checkFor) {
              for(Board board : getAllBoards()) {
                   System.out.println(board.getRemainingNumbers());
                   for(ArrayList<Integer> row : board.getRemainingNumbers()) {
                        for(int i=0;i<row.size();i++) {
                             if(numbers.contains(row.get(i))) {
                                  row.remove(row.get(i));
                   if(checkFor==1) {
                        for(ArrayList<Integer> row : board.getRemainingNumbers()) {
                             if(row.size()==0) {
                                  return board;
                   else if(checkFor==2) {
                        if(board.getRemainingNumbers().get(0).size()==0 && board.getRemainingNumbers().get(1).size()==0) {
                             return board;
                        else if(board.getRemainingNumbers().get(0).size()==0 && board.getRemainingNumbers().get(2).size()==0) {
                             return board;
                        else if(board.getRemainingNumbers().get(1).size()==0 && board.getRemainingNumbers().get(2).size()==0) {
                             return board;
                   else if(checkFor==3) {
                        if(board.getRemainingNumbers().size()==0) {
                             return board;
                   System.out.println(board.getRemainingNumbers()  );
              return null;
         public static ArrayList<Integer> oneToGo(int rows, ArrayList<Integer> numbers) {
              //TO-DO
              return null;
         public static void importCSV(ArrayList<String> buff) {
              ArrayList<ArrayList<ArrayList<Integer>>> allNumbers = new ArrayList<ArrayList<ArrayList<Integer>>>();
              int line = 0;
              String controleNumber = "";
              String[] splitLine = new String[10];
              for(int i=0;i<buff.size();i++) {
                   //adds the split buff to splitLine
                   for(int q=0;q<buff.get(i).split(";").length;q++) {
                        if(buff.get(i).split(";")[q].equals(""))
                             splitLine[q]="0";
                        else
                             splitLine[q]=buff.get(i).split(";")[q];
                   if(line==0) {
                        allNumbers.add(new ArrayList<ArrayList<Integer>>());
                        ArrayList<Integer> row = new ArrayList<Integer>();
                        allNumbers.get(allNumbers.size()-1).add(row);
                        controleNumber=buff.get(i).split(";")[0];
                        for(int q=buff.get(i).split(";").length;q<10;q++) {
                             splitLine[q]="0";
                        for(int q=0;q<9;q++) {
                             row.add(Integer.valueOf(splitLine[q+1]));
                   else if(line==1) {
                        ArrayList<Integer> row = new ArrayList<Integer>();
                        allNumbers.get(allNumbers.size()-1).add(row);
                        for(int q=buff.get(i).split(";").length;q<9;q++) {
                             splitLine[q]="0";
                        for(int q=0;q<9;q++) {
                             row.add(Integer.valueOf(splitLine[q]));
                   else if(line==2) {
                        ArrayList<Integer> row = new ArrayList<Integer>();
                        allNumbers.get(allNumbers.size()-1).add(row);
                        for(int q=buff.get(i).split(";").length;q<9;q++) {
                             splitLine[q]="0";
                        for(int q=0;q<9;q++) {
                             row.add(Integer.valueOf(splitLine[q]));
                        createBoard(controleNumber, allNumbers.get(allNumbers.size()-1));
                        line=-1;
                   line++;
         public static ArrayList<String> readFile(File file) {
              FileInputStream fileInputStream = null;
              ArrayList<String> buff = new ArrayList<String>();
              String line;
              try {
                   fileInputStream = new FileInputStream(file);
                   BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
                   BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(bufferedInputStream));
                   while ((line = bufferedReader.readLine())!= null) {
                        buff.add(line);
              catch (IOException ex) {
                   Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
              finally {
                   try {
                        fileInputStream.close();
                   catch (IOException ex) {
                        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
              return buff;
         public static void addNumber(int number) {
              numbers.add(number);
         public static ArrayList<Integer> getNumbers() {
              return numbers;
    }

    Tried the code but it's full of compiletime errors. I changed it a little but still got
    Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems:
         board cannot be resolved
         row cannot be resolved
         line cannot be resolved
         board cannot be resolved
         board cannot be resolvedwith the following code
    public static void importCSV(ArrayList<String> buff) {
              ArrayList<ArrayList<ArrayList<Integer>>> allNumbers
              = new ArrayList<ArrayList<ArrayList<Integer>>>();
              String[] splitLine = new String[10];
              String controleNumber;
              for(int i=0;i<buff.size();i++) {
                   int line = i % 3;
                   // split the buffer into fields
                   String[] splitBuf = buff.get(i).split(";");
                   int start = 0;
                   if(line==0) { // new board
                        ArrayList<ArrayList<Integer>> board = new ArrayList<ArrayList<Integer>>();
                        controleNumber = splitBuf[0];
                        start = 1;
                   ArrayList<Integer> row = new ArrayList<Integer>();
                   // fill row from the buffer fields...
                   for(int b = start, last = start+9; b < last; b++) {
                        if(b >= splitBuf.length || splitBuf.length() == 0)
                             row.add(0);
                        else
                             row.add(Integer.valueOf(splitBuf[b]));
              }This is my main problem:createBoard(controleNumber, board);
         board.clear();
         row.clear();The board that i created using the createBord method doesn't hold any numbers because i cleared the arrays i used to create it *after* creating it.
    got my software construction teacher to help me today :)
    works!     public static void importCSV(ArrayList<String> buff) {
              ArrayList<ArrayList<Integer>> board = new ArrayList<ArrayList<Integer>>();
              ArrayList<Integer> row = new ArrayList<Integer>();
              String controleNumber = "";
              int line;
              for(int i=0;i<buff.size();i++) {
                   line = i % 3;
                   String[] splitBuf = buff.get(i).split(";");
                   int start = 0;
                   if(line==0) { // new board
                        board = new ArrayList<ArrayList<Integer>>();
                        controleNumber = splitBuf[0];
                        start = 1;
                   row = new ArrayList<Integer>();
                   // fill row from the buffer fields...
                   for(int b = start, last = start+9; b < last; b++) {
                        if(b >= splitBuf.length || splitBuf[b].length() == 0)
                             row.add(0);
                        else
                             row.add(Integer.valueOf(splitBuf[b]));
                   board.add(row);
                   if(line==2) {
                        createBoard(controleNumber, board);
         }Edited by: Briam on Apr 12, 2010 12:37 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Thread use to find max and min in an array of objects??

    Hello everyone,
    I need to find the min and max int value in a array of Objects.
    This has to be done using threads--like divide the entire array into 10 or so blocks and find the local min and max in each block., Each block is run on a thread and finally comparing them to find the global max and min.How should I do this? I am new to Java programming and in particular to threads.
    Thanks for your time and patience in answering this newbie question.
    JP

    Hi,
    if i understand your problem, you have a big array with a lot of int values and you need to create a few arrays with a part of the big one in each, next each in a thread find the max and the min, next return the max and the min of each thread and compare these max and min to obtain the globals max and min?
    In that case you can create a class in which is your big array. you create a second class implementing Runnable, in its creator you put the instance of the
    first class and 2 int which are the beginning and the ending index. in this class add a method run in this method you create a loop to compare the current value to the max and min values, and you replace if you need to do. In the first class you put the main where you create a few instance of the second class in a thread :
         private Thread threadName = new Thread(new SecondClass(this, start, end));
    Next you start all these thread:
    threadName.start();
    At the end of the run method of the second class you have to write your result in the max and min fields of the first class(int type, you have to create it)
    Write it only if it's necessary (if the current max is > than the already existing max).
    I think it's complete!
    Sorry if it's not really easy to understand, I'm french, but you can answer if you have more questions.
    S�bastien

  • How to pass a array of object to oracle procedure using callable

    Hi,
    I am calling a oracle stored procedure using callable statement which has IN and OUT parameter of same type.
    IN and OUT are array of objects. (ie) IN parameter as Array of Objects and OUT parameter as Array of Objects
    here are the steps i have done as advised from oracle forum. correct me if i am in wrong direction
    ORACLE types and Stored Procedure
    CREATE OR REPLACE
    TYPE APPS.DEPARTMENT_TYPE AS OBJECT (
    DNO NUMBER (10),
    NAME VARCHAR2 (50),
    LOCATION VARCHAR2 (50)
    CREATE OR REPLACE
    TYPE APPS.DEPT_ARRAY AS TABLE OF department_type;
    CREATE OR REPLACE package body APPS.insert_object
    IS
    PROCEDURE insert_object_prc (d IN dept_array, d2 OUT dept_array)
    IS
    BEGIN
    d2 := dept_array ();
    FOR j IN 1 .. d.COUNT
    LOOP
    d2.EXTEND;
    d2 (j) := department_type (d (j).dno, d (j).name, d(j).location);
    END LOOP;
    END insert_object_prc;
    END insert_object;
    JAVA CODE
    Value Object
    package com.custom.vo;
    public class Dep {
    public int empNo;
    public String depName;
    public String location;
    public int getEmpNo() {
    return empNo;
    public void setEmpNo(int empNo) {
    this.empNo = empNo;
    public String getDepName() {
    return depName;
    public void setDepName(String depName) {
    this.depName = depName;
    public String getLocation() {
    return location;
    public void setLocation(String location) {
    this.location = location;
    to call stored procedure
    package com.custom.callable;
    import com.custom.vo.Dep;
    import oracle.jdbc.OracleCallableStatement;
    import oracle.jdbc.OracleConnection;
    import oracle.jdbc.OracleTypes;
    import oracle.jdbc.pool.OracleDataSource;
    import oracle.sql.ARRAY;
    import oracle.sql.ArrayDescriptor;
    import oracle.sql.Datum;
    import oracle.sql.STRUCT;
    import oracle.sql.StructDescriptor;
    public class CallableArrayTryOut {
    private static OracleDataSource odcDataSource = null;
    public static void main(String[] args) {
    OracleCallableStatement callStatement = null;
    OracleConnection connection = null;
    try {
    odcDataSource = new OracleDataSource();
    odcDataSource
    .setURL("......");
    odcDataSource.setUser("....");
    odcDataSource.setPassword("....");
    connection = (OracleConnection) odcDataSource.getConnection();
    } catch (Exception e) {
    System.out.println("DB connection Exception");
    e.printStackTrace();
    Dep[] dep = new Dep[2];
    dep[0] = new Dep();
    dep[0].setEmpNo(100);
    dep[0].setDepName("aaa");
    dep[0].setLocation("xxx");
    dep[1] = new Dep();
    dep[1].setEmpNo(200);
    dep[1].setDepName("bbb");
    dep[1].setLocation("yyy");
    try {
    StructDescriptor structDescriptor = new StructDescriptor(
    "APPS.DEPARTMENT_TYPE", connection);
    STRUCT priceStruct = new STRUCT(structDescriptor, connection, dep);
    STRUCT[] priceArray = { priceStruct };
    ArrayDescriptor arrayDescriptor = ArrayDescriptor.createDescriptor(
    "APPS.DEPT_ARRAY", connection);
    ARRAY array = new ARRAY(arrayDescriptor, connection, priceArray);
    callStatement = (OracleCallableStatement) connection
    .prepareCall("{call insert_object.insert_object_prc(?,?)}");
    ((OracleCallableStatement) callStatement).setArray(1, array);
    callStatement.registerOutParameter(2, OracleTypes.ARRAY,
    "APPS.DEPT_ARRAY");
    callStatement.execute();
    ARRAY outArray = callStatement.getARRAY(2);
    Datum[] datum = outArray.getOracleArray();
    for (int i = 0; i < datum.length; i++) {
    oracle.sql.STRUCT os = (oracle.sql.STRUCT) datum[0];
    Object[] a = os.getAttributes();
    for (int j = 0; j < a.length; j++) {
    System.out.print("Java Data Type :"
    + a[j].getClass().getName() + "Value :" + a[j]
    + "\n");
    connection.commit();
    callStatement.close();
    } catch (Exception e) {
    System.out.println("Mapping Error");
    e.printStackTrace();
    THE ERROR
    Mapping Errorjava.sql.SQLException: Inconsistent java and sql object types
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
    at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1130)
    at oracle.sql.StructDescriptor.toOracleArray(StructDescriptor.java:823)
    at oracle.sql.StructDescriptor.toArray(StructDescriptor.java:1735)
    at oracle.sql.STRUCT.<init>(STRUCT.java:136)
    at com.custom.callable.CallableArrayTryOut.main(CallableArrayTryOut.java:48)

    You posted this question in the wrong forum section. There is one dedicated to Java that was more appropriate.
    Anyway here is a link that describes what you should do.
    http://download.oracle.com/docs/cd/B19306_01/java.102/b14355/oraarr.htm#i1049179
    Bye Alessandro

Maybe you are looking for

  • Help with exporting images

    HI I have recently shot a wedding with two bodies.  Forgot to sync the bodies before hand and so left with images at massively different times.  in lightroom i then changed to view by capture time and amended all the wrongly timed images.  i am then

  • Can't connect itunes to my remote speakers thru airport express

    After having updated the latest itunes 7.3 my itunes does not recognize anymore my remote speakers and does not connect to them. Have resetted my airport, to no avail. still, itunes does not recognize it. please advise what to do as it is very annoyi

  • What are the content conversion parameters for this structure

    Hi All, The below file is the text file. what are the content conversion parameters are required and what is the structure to create in the IR to convert into xml. Schedule D - District/Port List (by District Code) [Produced13APR11] District |    Por

  • Title 3D in FCE 3.5?

    Is title 3D included in FCE HD 3.5? I upgraded today and a project from FCE 3.0 with a title 3D in it was asking for the plug in. I checked and it's in the Library/Application Support/Boris (don't know the full folder) folder but it won't let me choo

  • Table look up using value from customer exit variable

    I have a customer exit variable, CURRMON, which the user enters in the format MM/YYYY. From this entry, I would like to do the following to calculate and display the number of business days in the selected month: Do the following to get Business Days