Solved

Passing hardcode data to method

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.

757 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

21 Experts available now in Live!

Get 1:1 Help Now