Solved

Passing hardcode data to method

Posted on 2013-06-19
2
370 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 84
micro services vs rest web services 16 81
what is a "java.lang.System Property"   ? 20 57
javap bin 2 25
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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now