AllExperts > Experts 
Search      

Java

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Java Answers
Question Library

Ask a question about Java
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Artemus Harper
Expertise
I have a BS in computer science and am working towards a Masters degree.

Experience
I have experience in Core Java, good background in Java swing/gui, some experience with JNI, Java reflection, and Java java.nio.* knowledge of Java bytecode and annotations. Basics in c++ and c#
 
   

You are here:  Experts > Computing/Technology > Focus on Java > Java > string variable, user input

Topic: Java



Expert: Artemus Harper
Date: 5/26/2008
Subject: string variable, user input

Question
QUESTION: Hello,

I'm supposed to ask the user for the manufacturer, model, etc... of an aircraft. The answers to the questios should be saved as strings in respectively 'Man', 'Mod', etc...

How can I save the users answers? I know how to save numerical answers (int and double), but I don't know what to do now...

Please help!!

TY

ANSWER: When you save something numerically, it is converted from a string to some other kind of data. Instead of doing the conversion, you simply take the sting the user enters.

How you do this depends on how you are getting the user input.

E.g. if you are getting from the user's console (and using Java 1.6)

String man = System.console().readLine("Enter manufacturer");

---------- FOLLOW-UP ----------

QUESTION: I'm using ConTEXT.
I'm getting the input with the command
System.out.println("Enter the manufacturer: ");

Should it then be:
System.out.println("Enter the manufacturer");
Man = in1.readLine();

and then use the same way for model, etc... or other way?

Afterwards I'm supposed to put all the information of the several aircraft in a "JAVA Vector or List"....
Small explanation, for I can't find it in the book....


TY!!!  

Answer
Yes, you can do the same for a model. Then you want to create a class that can keep all of these variables, and store these into a list, such as ArrayList.

You can find the documentation for ArrayList here:
http://java.sun.com/javase/6/docs/api/java/util/ArrayList.html

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.