• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Array Constructor

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What constructor is most efficent to use to store the data of the file before extracting the data into an object?

I hope I am saying it correctly.
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't recall java having an Array class. It does have an "Arrays" class, but I don't think that class has a public constructor.

Henry
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.lang.reflect.Array or java.sql.Array?
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeff Albertson:
java.lang.reflect.Array or java.sql.Array?



I knew while typing the response, that someone would call me on that ...

Henry
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by c york:
What constructor is most efficent to use to store the data of the file before extracting the data into an object?

I hope I am saying it correctly.


I'm still confused about the original question. By "constructor" do you actually mean "data structure"?
 
c york
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I may not have been clear. Let me try again.

I have a file that I am trying to extract into an object using a constructor and populate the object(that is related to a class- using an array list) with the data .

I have created the object, but unsure what constructor to use.
 
Sheriff
Posts: 28346
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unclear? Yes, I agree.

I have a file that I am trying to extract into an object using a constructor...

Now, are you saying that this object uses a constructor and you are trying to extract into it, or that you are trying to use a constructor to extract into the object, or something else? Shorter and less gramatically-complex sentences might help. And I think we are all baffled why you are insisting on constructors here, although that should become clear when your question becomes clear.
 
c york
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am confused myself.
You are correct is it - use a constructor to extract into the object.
 
c york
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is use a constructor to extract into the object.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I usually ask in a situation like this is that the person try to describe what they need to accomplish, not how they're trying to do it. For example, in this case, you might say "I have a text file, and I want to read it in so that each line is a separate String", or something like that. Avoid terms whose meanings you're not 100% sure of, and I believe (forgive me) that "constructor" is in that category.
 
c york
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a text file that I am trying to use a constructor to extract the data into an object. I have looked at the String constructor and I am not sure which one to use and how to get the data into the object that was created.
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by c york:
I have a text file that I am trying to use a constructor to extract the data into an object. I have looked at the String constructor and I am not sure which one to use and how to get the data into the object that was created.



Wow... It took a long while, but I think I finally got the question.

There is no way to contruct a string that is automatically mapped to the data in a file. However, there are a few options that will allow you to open a file and read strings from them. Take a look at the FileInputStream, FileReader, and RandomAccessFile classes.

Henry
 
c york
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reading and writing the file has been done. I am now using the output file that was created and need to store the output into a class that contains the following for ex.
public String getT1_CNT() {
return t1_CNT;
}
/**
* @param t1_cnt The t1_CNT to set.
*/
public void setT1_CNT(String t1_cnt) {
t1_CNT = t1_cnt;
}

So, I created an object. I need to get the data into the object created and into the class which is another java file.
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C. York, I have carefully read the previous 12 threads, and still I can figure out what your question mean.

At times, I believe the word "constructor" is related to the Object Oriented Concept of constructors, that's to say, the method executed when you instantiate a new object. But after reading the whole question, I have impression that you may be referring to something else, like a method responsible to constructing something.

Whatever the case, your question as well as your previous example are both inintelligible for me.

Would you please explain me your question as if I were a 5 years old kid?
 
c york
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought we were suppose to be nice. Sorry, the subject is in reference to "constructor", however, the last reply did not mention it. It is a continuation of what I am trying to accomplish.

Where are the people with compassion?
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by c york:
I thought we were suppose to be nice. Sorry, the subject is in reference to "constructor", however, the last reply did not mention it. It is a continuation of what I am trying to accomplish.

Where are the people with compassion?



C. York,

Trust me. We are not trying to be mean. We seriously do *not* have any idea what you are talking about !!

Think about it... This is a long running thread with a lot of people. Do you really think that many people can be mean for so long?

Henry
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed. At this point I, for one, am personally invested in seeing you solve your problem. I'm very curious to see how this gets resolved.

But note that I asked you to restate your question without using the word "constructor", and yet you just repeated the same statement, and included the forbidden word. As a result, we haven't been able to test my belief (apparently shared by Edwin) that you mean something different by the word "constructor" than we are understanding.

To make this perfectly clear: a constructor is a special form of a Java method that takes the same name as the class in which it appears and has no return type. It can be used only in an object creation expression. In the following



the part in bold is the constructor, and you use it like this:

A myA = new A();

OK, now we all know what a constructor is.

In your last post, you say "I need to get the data into the object created and into the class which is another java file." So to me, it sounds as if you're reading a file, and you want to take the data in the file and call a buch of "setX()" methods on an instance of some class. That would just look like (assuming one object property per line in the file, only one object, and skimping on error handing:



So, are we getting closer? Nothing I've written here is particularly specific to constructors, nor is it related to arrays.
 
c york
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that was explained to me earlier. I am a java beginner and the first place were I learned about "constructor" was in the java.sun.com api website; this was all I knew and I was confused by the way someone explained it to me.

Now I understand and I can see the light at the end of the tunnel. Please forget the subject "Array Constructor" -- the way it was explained to me was not clear.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now that the term "constructor" is clear, can you please explain WHAT you want to do. Don't worry about HOW to do it. That's what we are here to help you with. Also, you should avoid using the word "constructor" in your explanation since a constructor is a detail about HOW to accomplish the task.

So to help you get started, you might want to write some thing like this:

"I need to write a program that reads text from a file. And then..."

Please fill in the details from there about WHAT you need to do then we will help you figure out HOW to do it.
 
c york
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The description for the exercise is as follows:
In this exercise, we will take the exercise 2 program and modify it. We will extract the applicant�s demographic information and some transaction related information from the EFT file. The information extracted will then be stored in an Applicant object. The Applicant class will be provided. In your application, you will need to create the Applicant object using correct constructor and populate the object with extracted values. You also need to implement the toString() method that will be used when output the Applicant object to a file.
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So if I understand correctly, you have been given a complete class called Applicant that has some constructors and presumably some methods for adding values, and what you need to do is create a new instance of the Applicant class, read some data from a file, add this data to your Applicant instance, and write information to another file using the String obtained by calling toString() on your Applicant instance. Is that correct?
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have the source code for the Applicant class ? If so can you post it or if it is too large just post the first line of any constructors (i.e. any methods called Applicant that don't have a return type specified). See EFH's earlier post for an example.

Don't forget to put the code in CODE tags.
[ April 07, 2006: Message edited by: Joanne Neal ]
 
c york
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the Applicant class is very long. Here are the first few lines.
import java.io.*;

public class Applicant {
private String t1_LEN_1;
private String t1_VER;
private String t1_CNT;
.......

/**
* @return Returns the t1_CNT.
*/
public String getT1_CNT() {
return t1_CNT;
}
/**
* @param t1_cnt The t1_CNT to set.
*/
public void setT1_CNT(String t1_cnt) {
t1_CNT = t1_cnt;
}
/**
* @return Returns the t1_LEN_1.
*/
public String getT1_LEN_1() {
return t1_LEN_1;
}
/**
* @param t1_len_1 The t1_LEN_1 to set.
*/
public void setT1_LEN_1(String t1_len_1) {
t1_LEN_1 = t1_len_1;
}
.........
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a line in the Applicant class that looks something like
There may be some parameter declarations between the ()
e.g.

These are the constructors. Can you post any line that looks anything like this.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, all that we know for sure about this class so far is that the variable names aren't very descriptive, and the documentation is no help. But is does show that there are at least two getXXX() and setXXX() methods, I presume that when you extract whatever demographic information is contained in the file you have to read from, you will have to call one or more of these methods. According to your instructions, you will also have to implement a toString() method that does something useful. Maybe you could show us the constructors that you have to work with, and as Joanne said, please dont forget to use code tags.
 
c york
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the Applicant method looks like this in the Applicant class.



public Applicant() {
}

The constructor that I am using is in the Applicant2 file:


public class Applicant2 extends Applicant{


public Applicant2(){
super();
}
public String ToString() {// Just for testing

return ("Printing String");
}

}

And the main method in the Exercise 3 file where I open the file -
public class Exercise3{
public static void main(String[] args)
{

Applicant2 appob = new Applicant2();
appob.ToString();
}
}

This approach is to help with testing; before reading the output file.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Does it look exactly like that, with no implementation? Are there any other constructors?

Also concerning your toString() method, Java is case sensitive so if you want to override the toString() method that your class inherits, you must use a lower-case t (toString() insted of ToString()). If you are using Tiger, one of the cool new features is using annotations to indicate that you intend to override a method.



BTW: I see you took a shot at using the code tags, thanks for that. For future referecnce the code goes between the tags like this. (without the spaces in the tags)
[ code]
//code goes here
[ /code]
[ April 07, 2006: Message edited by: Garrett Rowe ]
 
c york
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, there is no implementation. The only constructor is the one that I created.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So now you create an Applicant and then use the setXXX methods to add the data you read from the file e.g.
 
And then the flying monkeys attacked. My only defense was this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic