Print object from Array list
Program
import java.util.*;
public class ArrayQuestion {
public static void main(String args[]) {
int inputQuestionnAireNum = 0;
int inputPostCode = 0;
int inputGender = 0;
int inputAge = 0;
int x=0;
ArrayList<QuestionnAire> questionArr = new ArrayList<QuestionnAire> ();
Scanner input = new Scanner(System.in);
do{
System.out.print("1 new entry or 0 print");
x = Integer.parseInt(input.nextLine());
if(x == 1){
//Questionnaire Number
System.out.print("Enter Questionnaire Number [ ] ");
inputQuestionnAireNum = Integer.parseInt(input.nextLine());
//Postal code
System.out.print("Enter Postal Code [ ] ");
inputPostCode = Integer.parseInt(input.nextLine());
//Age
System.out.print("Enter Age [ ] ");
inputAge = Integer.parseInt(input.nextLine());
//Gender
System.out.print("Enter Gender '1' for Male and '2' for for female [ ] ");
inputGender = Integer.parseInt(input.nextLine());
QuestionnAire qObject = new QuestionnAire(inputQuestionnAireNum, inputPostCode, inputAge, inputGender);
questionArr.add(qObject);
} else {
for (int i = 0; i < questionArr.size(); i++) {
System.out.println(questionArr.get(i));
} while(x != 0);
output
1 new entry or 0 print1
Enter Questionnaire Number [ ] 222
Enter Postal Code [ ] 111
Enter Age [ ] 12
Enter Gender '1' for Male and '2' for for female [ ] 1
1 new entry or 0 print0
QuestionnAire@4693c7how come the result is QuestionnAire@4693c7 instead of printing the value which i key in ???
http://java.sun.com/javase/6/docs/api/java/lang/Object.html#toString()
Similar Messages
-
Is it possible that object can be store in array list.
package{
// Importing object from flash libary
import flash.text.TextField;
import flash.display.Sprite;
// Creating class
public class Show extends Sprite {
//Attribute
private var txt:Array = new Array();
// Constructor
function Show()
txt[0]:TextField = new TextField();
addChild(txt[0]);
txt[0].width=320;
txt[0].height=25;
txt[0].x=0;
txt[0].y=0;
txt[0].border=true;
txt[0].text="nepalikto";
Error
Description : Label must be a simple identifier
Location : Above orange textcolor lineNot sure if this all is 100% technically correct but:
You only use datatyping if you actually create a variable. Like:
var myArray:Array = new Array();
if you do not declare the var with the var keyword, you can't use datatyping either.
// this is wrong
myArray:Array = new Array()
It is good practice to use datatyping whenever possible since it can help you debug an application:
Flash finds the possible errors in code where one variable contains different datatypes at different times which can be confusing
Flash helps with the codecompletion feature once a variable is typed so there's less chance of typos.
The items in the array, unlike CS4's new Vector datatype aren't typed. Probably has some memory usage reason in the onderlying C++ code but I'm not sure. If you have CS4 you could possibly use:
var txt:Vector.<TextField> = new Vector.<TextField>();
To tell you the truth I haven't used the CS4 Vector Datatype so I'm not sure if aside from faster code execution there's errorcheckings on it's contents like mentioned above.
Hope this helps some -
Error while activating the object from change list in IR
Hi Friends,
I am trying to activate a mapping object taken from History.But I am getting error "version management was unable to execute the last action because temporary internal lock has been set" while activating from change list.
Regards,
Suresh.Hi Suresh,
have a look at the integration builder start jsp. There is a Link "Administration". On this page, on the left side, you can click on "lock overview" and check if your object is locked. Then you can remove this lock.
Best Regards
Sven -
How to print contacts from iCloud (list vs separate sheets of paper)
How do you print a list of contacts from icloud without having each contact on one sheet of paper. Perhaps print with several vcard images on one sheet?
That's ok...I figured it out. I selected all contact by selecting all contacts then to the settings image and select print.
-
How can I print out an Array List in my GUI program?
I have an ArrayList of Objects which I want to print out in a TextArea in my GUI. I tried using setText(), but it seems like that can only handle strings. Does anyone know of an alternative method or some other way to get around this?
Ok, I have an object name Instrument which contains a double price, String name, int numberInStock. In my GUIFrame class which creates the GUI obviously, I have a button listener that should print out my ArrayList in a TextArea when clicked on a button.
Here is the code:
private class showIResponse implements ActionListener{
public void actionPerformed(ActionEvent e){
showText.setText(parseString(ali));
it is still giving me an error saying "cannot find symbol method parseString(java.util.ArrayList<java.lang.Object>)" -
Finding 'N' Maximum object from a list.
Hi,
Collections.sort(list,comparator), will sort all the elements in the list. Whereas it is waste of resource in my case.
I need to find only top N1 from the collection. Is there any way?
Assume I may pass list which contains 10000 elements but I need a list which contains only top 10 elements.
so that I can access like..
List MaxList = Collections.sort(list, comparator, 10);
If it is not in java, Is there any possible open source library for this.
Regards
MohanIf you don't need repeated extracts of different lenghts, then a simpler solutions that is only O(n) is possible than the ones mentioned in the other thread.
Simply iterate over the source set, maintaining a bucket of the 10 top elements found so far. For each source element, compare its value to the lowest in the bucket, and replace it if it's greater.
If the source set changes alot, it can make sense to maintain the bucket in parallel.
(This approach is probably only appropriate if the bucket size doesn't vary much and the bucket size is significantly smaller than the source set.) -
Hi guys, I'm pretty new to as3 and I'm trying to make a game where the player supposedly clicks on the stage and 3 towers which I've spawned dynamically should shoot towards the area. Everything works in terms of tower rotation, etc, but the bullets will not be removed from the stage when I exit the level into another scene. The boundary checking is fine, too.
Here's a part of the code in the Main.as file.
private function clickTower1(e:MouseEvent):void
for each (var tower1:mcTower1 in tower1Array)
var newLaser1:mcLaser1 = new mcLaser1();
newLaser1.rotation = tower1.rotation;
newLaser1.x = tower1.x + Math.cos(newLaser1.rotation * Math.PI / 180) * 40;
newLaser1.y = tower1.y + Math.sin(newLaser1.rotation * Math.PI / 180) * 40;
newLaser1.addEventListener(Event.ENTER_FRAME, laser1Handler);
tower1BulletArray.push(newLaser1); stage.addChild(newLaser1);
private function laser1Handler(e:Event):void
//Make laser move in direction of turret.
var newLaser1:MovieClip = e.currentTarget as MovieClip;
newLaser1.x += Math.cos(newLaser1.rotation * Math.PI / 180) * laser1Speed;
newLaser1.y += Math.sin(newLaser1.rotation * Math.PI / 180) * laser1Speed;
//Boundary checking if (newLaser1.x < -50 || newLaser1.x > 800 || newLaser1.y > 600 || newLaser1.y < -50)
newLaser1.removeEventListener(Event.ENTER_FRAME, laser1Handler); stage.removeChild(newLaser1);
tower1BulletArray.splice(0, 1);
I have a function called exitLevel, which basically, as the name states, exits the level when a button is clicked. It worked perfectly before I started coding the bullets.
private function exitLevel(e:MouseEvent):void
stage.frameRate = 6;
gamePaused = false;
clearLevel();
gotoAndStop(1, 'exitLevel');
btnExitLevel.addEventListener(MouseEvent.CLICK, levelSelect1);
private function clearLevel():void
stage.removeEventListener(Event.ENTER_FRAME, update);
stage.removeChild(buttonCreep1); stage.removeChild(buttonCreep2);
for (var i = creep1Array.length - 1; i >= 0; i--)
removeChild(creep1Array[i]);
creep1Array.splice(i, 1);
//trace ("Creep1 Removed");
for (var j = creep2Array.length - 1; j >= 0; j--)
removeChild(creep2Array[j]);
creep2Array.splice(j, 1);
//trace ("Creep2 Removed");
for (var k = tower1Array.length - 1; k >= 0; k--)
removeChild(tower1Array[k]); tower1Array.splice(k, 1);
for (var l = tower1BulletArray.length - 1; l >= 0; l--)
stage.removeChild(tower1BulletArray[l]);
tower1BulletArray.splice(0, 1);
After debugging, it says the error is at the end, where i try to remove the child from the stage. What is wrong? Sorry, I'm a beginner at as3 so any answers might have to be spoonfeeding... I'll try to learn and understand, though. Thanks!
I did take some of the code off of a guide on the web, and I don't understand it totally, so can someone explain to me what this code does as well? What is e.currentTarget? Thanks!
var newLaser1:MovieClip = e.currentTarget as MovieClip;
Here's the full .as file if anybody wants to take a look. http://pastebin.com/5ff4BQa5Hi, I managed to solve the errors (kind of) by using this code.
for (var i:int = tower1BulletArray.length - 1; i >= 0; i--)
if (tower1BulletArray.parent)
tower1BulletArray[l].parent.removeChild(tower1BulletArray[l]);
tower1BulletArray.splice(i, 1);
However, the problem still persists that the bullets stay in the screen after I change the scene. Any solution? Thanks! -
Can I create a network object from CIDR format or do I need to use IP - netmask?
Have a cisco ASA running ASA V 8.3
Wondering what the correct syntax is or even if it is possible to create a network object from a list of IP's in CIDR format?
Typically just do this:
Create network-object
object-group network name
network-object 1.2.3.0 255.255.255.0
Would like to do this:
network-object 1.2.3.0/24
thanks!Hi,
As far as I know the ASA does not support entering a network/subnet mask in such format in any of its configurations.
- Jouni -
Problem in jni getting object from methodst
a want to save an object gatin from java and save it into my list in c code
my probleme is when a call getobject more than one times it return null (in the first one it return the last object saved)
i dont understand why
this is my methods
to add object in my list
NIEXPORT void JNICALL Java_Matrice2_ajoutercell
(JNIEnv *env, jobject obj, jint lig, jint col,jobject objectadded){
AjouterCellule(objectadded ,lig,col,recupererAdresse(env,obj));
// this is a method created to save the ovject in my list
// ( in Ajoutercell a save my object like this
List->element = val;
struct list {....
jobject val
]*list;
the code work good if i use jint
--- and this is the method to getobject
JNIEXPORT jobject JNICALL Java_Matrice2_Getcell
(JNIEnv *env, jobject obj , jint lig, jint col){
return recuperercell(recupererAdresse(env,obj),lig,col);
// the method recuperercell get the object from my list
return List->valr;
i hope that some one can understand my code and help me
thanks ...i use newglobalref and it work ; but i have to delete every ref created when i delete or modify an object
thanks to you -
How do you print items from an array list that fit a certain condition?
I have an array list full of people. People can be set to single or married, is there anyway I can just display the people from the arraylist that are married? I've been reading through alot of stuff about arraylists and there doesnt seem to be anything on printing things depending on context.
thebigfish wrote:
I have an array list full of people. People can be set to single or married, is there anyway I can just display the people from the arraylist that are married? I've been reading through alot of stuff about arraylists and there doesnt seem to be anything on printing things depending on context.Have you tried simply iterating over the list, checking for your condition, and printing out the person's details?
for ( Person p : yourListOfPeople ) {
if ( p.isMarried() ) { // Assuming isMarried returns a boolean value determining if the person is married
System.out.println( p ); // Assuming you've overriden toString
} -
How can i check to see if an object is already in the array list?
while (res.next()) {
Schedule schedule = new Schedule();
customerName = res.getString("CUSTOMERNAME");
schedule.setCustomerName(customerName);
magName = res.getString("MAGNAME");
schedule.setMagName(magName);
System.out.println("NAME: " + customerName);
System.out.println("MAGNAME: " + magName);
if(!scheduleListH.contains(schedule)) //this won't work
scheduleListH.add(schedule);
}schedule object has 2 fields, customerName and MagName;
Basically i want to say, IF the scheudleList (which is an array list) contains an object schedule that has the same customerName and MagName as any of the objects in the array list, don't readd the object.
ANy help would be great!Thanks!
Oops I forogt I could use the .contains, i also tried that but still no luck.
There is no compiler error but here is an example of the output:
Populating scheudle list for HOLIDAY selection data structure:
NAME: Cory
MAGNAME: Merlin
NAME: Brandon
MAGNAME: Gondorf
NAME: Chris
MAGNAME: Houdini
NAME: Lokie
MAGNAME: Blaine
Sample SCHEDUEL H [Cory Merlin, Brandon Gondorf, Chris Houdini, Lokie Blaine]As you can see, There are 4 objects in the array list:
Cory Merlin
Brandon Gondorf
Chris Houdini
Lokie BLaine
Now this function is called everytime the user choses a new item in a combo box.
So if they go back to the previous selection, Holiday's, it shouldn't read add all the orginal things.
But if I go up and select the same item in the combo box it changes whats in the array list to the following:
Populating scheudle list for HOLIDAY selection data structure:
NAME: Cory
MAGNAME: Merlin
NAME: Brandon
MAGNAME: Gondorf
NAME: Chris
MAGNAME: Houdini
NAME: Lokie
MAGNAME: Blaine
Sample SCHEDUEL H [Cory Merlin, Brandon Gondorf, Chris Houdini, Lokie Blaine, Cory Merlin, Brandon Gondorf, Chris Houdini, Lokie Blaine]Here's my whole function if your interested and where I call it:
void populateSchedule(String holiday) {
Statement sta = null;
Connection connection6 = null;
try {
connection6 = DriverManager.getConnection(URL, USERNAME, PASSWORD);
sta = connection6.createStatement();
//getting the list of magicians from the selected holiday to see if any are free
ResultSet res = sta.executeQuery(
"SELECT CUSTOMERNAME, MAGNAME FROM SCHEDULE WHERE HOLIDAYNAME = '" + holiday + "'");
String customerName = " ";
String magName = " ";
System.out.println("Populating scheudle list for HOLIDAY selection data structure: ");
//this is where I add the waiting list objects to the array that will later be used
//to print out and shown to the user when they select the waiting list status
while (res.next()) {
Schedule schedule = new Schedule();
customerName = res.getString("CUSTOMERNAME");
schedule.setCustomerName(customerName);
magName = res.getString("MAGNAME");
schedule.setMagName(magName);
System.out.println("NAME: " + customerName);
System.out.println("MAGNAME: " + magName);
if(!scheduleListH.contains(schedule))
scheduleListH.add(schedule);
System.out.println("Sample SCHEDUEL H " + scheduleListH);
} catch (SQLException ex) {
System.out.println(ex);
ex.printStackTrace();
} finally {
try {
sta.close();
connection6.close();
} catch (SQLException ex) {
Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
//this is where i call in the GUI
private void specStatusComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String selectedItem = (String)specStatusComboBox.getSelectedItem();
String groupSelectedItem = (String) groupStatusComboBox.getSelectedItem();
if(groupSelectedItem.equals("Holidays"))
//get customer name and magician name from the Scheduel table
//use selectedItem (it will be a holiday name)
//magicDB.clearScheduleHList();
magicDB.populateSchedule(selectedItem);
ArrayList<Schedule> tempScheduleList = magicDB.getScheduleHListCopy();
outputTextArea.setText(" ");
outputTextArea.setText("CUSTOMER NAME" +"\t\t" + "MAGICIAN NAME" + "\n");
for(int i = 0; i < tempScheduleList.size(); i++)
outputTextArea.append(tempScheduleList.get(i).toString() + "\n");
} I'll reward the duke stars anyways because you have been a great help either way! -
Create Class objects from an Array of File Objects
Hi There,
I'm having extreme difficulty in trying to convert an array of file objects to Class objects. My problem is as follows: I'm using Jfilechooser to select a directory and get an array of files of which are all .class files. I want to create Class objects from these .class files. Therefore, i can extract all the constructor, method and field information. I eventually want this class information to display in a JTree. Very similar to the explorer used in Netbeans. I've already created some code below, but it seems to be throwing a NoSuchMethodError exception. Can anyone please help??
Thanks in advance,
Vikash
/* the following is the class im using */
class FileClassLoader extends ClassLoader {
private File file;
public FileClassLoader (File ff) {
this.file = ff;
protected synchronized Class loadClass() throws ClassNotFoundException {
Class c = null;
try {
// Get size of class file
int size = (int)file.length();
// Reserve space to read
byte buff[] = new byte[size];
// Get stream to read from
FileInputStream fis = new FileInputStream(file);
DataInputStream dis = new DataInputStream (fis);
// Read in data
dis.readFully (buff);
// close stream
dis.close();
// get class name and remove ".class"
String classname = null;
String filename = file.getName();
int i = filename.lastIndexOf('.');
if(i>0 && i<filename.length()-1) {
classname = filename.substring(0,i);
// create class object from bytes
c = defineClass (classname, buff, 0, buff.length);
resolveClass (c);
} catch (java.io.IOException e) {
e.printStackTrace();
return c;
} // end of method loadClass
} // end of class FileClassLoader
/* The above class is used in the following button action in my gui */
/* At the moment im trying to output the data to standard output */
private void SelectPackage_but2ActionPerformed(java.awt.event.ActionEvent evt) {
final JFileChooser f = new JFileChooser();
f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int rVal = f.showOpenDialog(Remedy.this);
// selects directory
File dir = f.getSelectedFile();
// gets a list of files within the directory
File[] allfiles = dir.listFiles();
// for loop to filter out all the .class files
for (int k=0; k < allfiles.length; k++) {
if (allfiles[k].getName().endsWith(".class")) {
try {
System.out.println("File name: " + allfiles[k].getName()); // used for debugging
FileClassLoader loader = new FileClassLoader(allfiles[k]);
Class cl = loader.loadClass();
//Class cl = null;
Class[] interfaces = cl.getInterfaces();
java.lang.reflect.Method[] methods = cl.getDeclaredMethods();
java.lang.reflect.Field[] fields = cl.getDeclaredFields();
System.out.println("Class Name: " + cl.getName());
//print out methods
for (int m=0; m < methods.length; m++) {
System.out.println("Method: " + methods[m].getName());
// print out fields
for (int fld=0; fld < fields.length; fld++) {
System.out.println("Field: " + fields[fld].getName());
} catch (Exception e) {
e.printStackTrace();
} // end of if loop
} // end of for loop
packageName2.setText(dir.getPath());
}It's throwing the exeption on the line:
FileClassLoader loader = new FileClassLoader(allfiles[k]);
I'm sure its something to do with the extended class i've created. but i cant seem to figure it out..
Thanks if you can figure it out -
Array of references to references to objects? Skip lists...
I'm trying to hammer out a SkipList ADT by tomorrow night. The structure of my SkipList is basically: A Skip list has a reference to the first SkipListNode. Each SkipListNode has an array of links, where a link of level 1 links to the next node that is at least level 1 (every node is at least level 1), and array of 2 links to the next node down the list that is at least that tall, etc. For the last tallest node in the list, it will have links that are null, as there are no nodes after it which can reach up to its higher level links.
My problem is that as I traverse the list looking for the insert position, I need to keep track of the taller links which may be 'cut-off' by the newly inserted node. Just as with a normal LinkedList, I would want to make the new node point to where these old links pointed, and point the old links to the new node. What I have been trying to do is build an array:
SkipListNode previousLinks[] = new SkipListNode[levelOfTallestNodeInSkipList];
As I traverse a SkipListNode, I over-write the previousLinks[i] with every level i link I encounter. For example say I'm in a level 5 node (currentNode) with key 15. I'm trying to inser key 17. I try the level 5 node's level 5 link and its null, so I would want to make previousLinks[5] = currentNode[5]. I then try currentNode's level 4 link, it's not null but it points to a node with key 47, which is past the insertion point for a node with key 17. So again, I want previousLinks[4] to REFER TO currentNode[4]. Etc, etc... I get down to currentNode's level 1 link and see it links to a node with key 16 and level 1. Ok, this is less than 17 so I make currentNode = key 16 node (which is lvl 1). Then I traverse currentNode's only link- a level 1 link- and see that it links to a node with key 18. BOOM: here's the insert point. I randomly select level 4 for the new node which will hold 17. This means that I will 'cut-off' the level four link of the node holding key 15. What I want to be able to do is:
/*connect new links to where old links point to*/
for (int k = 0; k < newNode.level; k++) {
if (k < current.level)
newNode.links[k] = previousLinks[k];
else
newNode.links[k] = null;
/*connect old links to newly created node*/
for (int k = 0;
k < Math.min(current.level, newNode.level); k++)
previousLinks[k] = newNode;
But this doesn't work. The previousLinks array seems to only hold the values which were copied from the earlier nodes, not references to the fields in the nodes which point further down the list. What I want is a C++ style array of pointers to fields in an object's array so that I can change where these fields point (refer).
I hope this post makes enough sense for someone to at least give me a clue... thanks.My skiplist implementation has a method to lookup a node. The resultant array of nodes has length the maximum height of the skiplist. At each level the array containes a reference to the node prior to the one I am looking for at that level. This allows me to patch all the relevant nodes when I add/remove an item to/from the skiplist.
My code might help give you the idea.
* Looks up the payload in the list returning an array
* of nodes that point to the element immediately before
* the desired element.
* @param target the node we are searching for
* @return and array of Nodes that are just prior to the
* node we are looking for.
private Node[] lookup(Node target)
Node[] update = new Node[MAX_HEIGHT+1];
int k = m_height;
Node p = m_header;
do
Node q = null;
while (((q = p.getNext(k) )!= null) && (m_comparator.lessThan(q, target))) p = q;
update[k] = p;
} while (--k >= 0);
return update;
} -
Dear All.
I want to Print Object List in Order , Please specify is there Standard form of Shop Paper Available.
I checked in Printing shop papers , its not , please pour some knowledge,
Regards,
N.Srinivashi
in standard you can use the shop paper 2010 for printing object list from order .kindly check it .for details please refer [Printing of shop paper|http://help.sap.com/saphelp_erp60_sp/helpdata/en/e9/8dc8b479fd11d58ce30000e8284931/frameset.htm]
regards
thyagarajan -
My printer is showing no errors and printed fine from my iPad, but it will not connect wirelessly to my mac mini. When I would try to print the printer status would remain at "idle" and the print queue would give an error message saying no printer was connected to the network. I searched for a driver update and couldn't find one so I decided to uninstall the software and then reinstall. I have done this and now the printer will not show up on the list where it should be to even install it durint set up. What can I do to resolve this issue?
add the printer IP without the HTTP
"192.168.1.x:"
Maybe you are looking for
-
I have a 2005 Jaguar xj8. When I tried to upgrade my 3gs to a 4g two years ago, I got a ticking noise in the speaker and no one on the other end could hear me. I had to go back to a 3gs. My phone is shot and I need to upgrade. Has there been a f
-
I had a bunch of junk entries in the address book on the mac, so I never synced the 2 when I had an iPhone 3GS. I got an iPhone 4 and even after deleting everything in the bunk address book, wasn't able to sync the iPhone 3GS's contacts (it had them
-
MB GUI locking up when waking from sleep
This doesn't happen every time, but sometimes when I wake the MB, the screen will freeze. The OS is still operating, I can ssh in to the machine. The cursor still responds, but I can't click on anything. The clock will be frozen at the time when the
-
I am using Log4J in a pageflow, but no log messages are getting printed on the weblogic console. Here is what I am doing - In a Pageflow I have the following code public static final String CLASS_ID = MyPageFlow.class.getName() + " - "; private stati
-
i downloaded a free james dean screensaver that is supposed to work with macs. it goes on my desktop, but when i go under screensavers, it wont open. when i open the desktop folder it says that there is nothing in there in terms of pictures. help! it