LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] OT: Java Need Advice

[ILUG] OT: Java Need Advice

Gareth Eason bigbro at skynet.ie
Wed Mar 2 10:23:55 GMT 2011


	Hi,

	I'm not sure I completely understand the question but maybe I can point you
in the right direction.

	Arrays are (typically) useful for grouping lots of the *same* data type
together. So I can have an array of ints, or an array of strings, or an array
of characters.

	It sounds like you want to collect and store a number of different data types
(string, char, int, double, float, whatever) in one, easy to use object. I use
the word object deliberately :)

	Consider thinking about creating a class (the template for creating an
object) and putting your various datatypes in there, then instantiating an
object of that class for each time you want to ask and store the results of
the query. So in pseudo code:

class Answers {
   name   : string,
   age    : int,
   weight : float,
   height : double
}

	Then when you're capturing data from the questions you can create a new
object from class Answers and store your data in there. This also allows you
to create an array of Answers objects and store the responses from a bunch of
different question asking sessions :)

	Hope that helps.

	Best regards,
	-->Gar



On 27/02/11 14:04, Frank Murphy wrote:
> Playing with Arrays.
> 
> I'm uncertain if possible.
> 
> I will have two classes.
> 
> A.java
> B.java (contains public static void main (String [] args)
> 
> 
> A: has to ask the user 6 questions,
> answers will be  (string, int, double, boolean) values.
> Instead of using set JOptionPane("Blah blah blah")
> get return whatever (string, int, double, boolean) variable.
> 
> I'm thingking of making an array with the 6 questions,
> but can an array use both default and user set constructors\variables?
> 
> 
> 
> or would I need two arrays in A, one as a default constructor type,
> one as user input type.
> 
> eg:
> Array myArray = new Array[6];
> myArray[0] = "";
> 
> Array myArray = new Array[6];
> myArray[0] = JOptionPane("Blah blah blah");
> 
> B: If I can do A, I could then create an array in B,
>  to call the array in A.
> as I will have to compare up to 5, instances of A.
> Dearest etc.
> 
> 



More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell