Solved

Passing hardcode data to method

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

617 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