Solved

Passing hardcode data to method

Posted on 2013-06-19
2
381 Views
Last Modified: 2013-06-24
Please excuse my ignorance, as I've indicated, I am a beginner.

I've created a java class, DataIn to contain harcoded data.

I need to pass the list of data to the methods listed below.
class DataIn{
    private int DataInId;
    private int snpID;
    private int indID;
    private String inCode;
    private int total;
    private int count;
    private String inText;
    private String inLabel;
    private String ind_name

    private DataIn(int DataInId, int snpID, int indID. String inCode,
                       int total, int count, String inText, String inLabel)
   {
        this.DataInId  = DataInId, ;
        this.snpID,  = snpID,
        this.indID; = indID;
        this.inCode = inCode;;
        this.total = total;
        this.count = count;
        this.inText = inText;
        this.inLabel = inLabel;
        this.ind_name = ind_name;
    }


    DataIn[] dataItems =
   {
 
    new (13071, 1, 45, "9100", 4,  5,  "",    "OFFSITE", "TC"),
    new (13070, 1, 5,  "9100", 15, 5,  "-10", "COMMUTE", "INDEX"
    new (13068, 1, 31, "9100", 1,  2,  "",    "OFFSITE", "BOOKS"),
    new (13080, 1, 31, "8370", 1,  1,  "",    "OFFSITE", "BOOKS"),
    new (13086, 1, 31, "8999", 0,  0,  "",    "OFFSITE", "BOOKS"),
    new (13089, 1, 31, "6048", 3,  6,  "",    "OFFSITE", "BOOKS"),
    new (13091, 1, 22, "6048", 5,  2,  "-3",  "COMMUTE", "AUTHORS"),
    new (13069, 1, 22, "9100", 6,  3,  "-3", "LOCAL",   "AUTHORS"),
    new (13081, 1, 22, "8370", 8,  6,  "-2",  "LOCAL",   "AUTHORS")
   
 
   
   };


HOW DO I PASS THE DATA IN THE DATAIN CLASS CREATED ABOVE INTO THIS METHOD????

 public void getDataIn( pass the array  DataIn into this method)
    {
       

        // Get a list of all the books
          List<DataIn> dList   = getBooks(arrayitems, "BOOKS"),

               

    }
   
 HOW DO I ACCESS THE ITEMS PASSED TO THIS METHOD?????

    public List<DataIn> getBooks(List<DataIn> DataItems,String indrName)
      {
            List<(List<DataIn> > resultList = new ArrayList<(List<DataIn> >();
            
            for DataIn vo : DataItems, String
            {
                                    
              //IF indrName in the List = "BOOKS" ADD TO LIST                               
                        
             if (indrName = DATAIN LIST

                                    {                        
              resultList.add(vo);
             }
 
                    }
            
            return resultList;
      }
0
Comment
Question by:cookiejar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 39261010
You wouldn't normally have an array of type X defined in type X, so you need to look at that. Also, make sure all your variable names begin lower case
0
 
LVL 7

Accepted Solution

by:
gudii9 earned 500 total points
ID: 39261028
Here is good example


class Account{
  int a;
  int b;
 public void setData(int c,int d){
   a=c;
   b=d;
 }
 public void showData(){
   System.out.println("Value of a ="+a);
   System.out.println("Value of b ="+b);
 }
}
 
class ObjectArray{
   public static void main(String args[]){
     Account obj[] = new Account[2] ;
     //obj[0] = new Account();
     //obj[1] = new Account();
    obj[0].setData(1,2);
    obj[1].setData(3,4);
    System.out.println("For Array Element 0");
    obj[0].showData();
    System.out.println("For Array Element 1");
     obj[1].showData();
  }
}




http://www.javatutorialhub.com/java-arrays.html


Hope this helps solving your issue
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question