Sunali Anu

Greenhorn
+ Follow
since Jun 04, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sunali Anu

I used Collections.swap method and that worked.. Thanks for the posts..
16 years ago
Use Collection.swap method to do the swapping... That works...
16 years ago
I have a method which sorts the Array list by the Item Id. I am trying to print out the same after sorting, but my code doesn't seem to do anything. Not sure if the code is wrong or i am not knowing what to display after sorting. Should i create a new Arraylist to store the swapped and sorted values and then display that??

Please take a look at the code below:
Code:
---------------------------------------------------------------------------
public static void sortItemNum(ArrayList<Item> itm)
{
System.out.println("The records sorted by Item Number:");

for(int out=itm.size()-1; out>1; out--)
{// outer loop (backward)
for(int in=0; in<out; in++)
{// inner loop (forward)
if( itm.get(0).getItem().getId() > itm.get(1).getItem().getId() ) // out of order?
swap(itm.get(0).getItem().getId(), itm.get(1).getItem().getId()); // swap them

}

}

for(int k=0; k<itm.size(); k++)
{
System.out.println(insure.get(k));
}

}
private static void swap(int one, int two)
{
int temp = one;
one = two;
two = temp;
}
16 years ago
Thanks everyone for your inputs... That's clear now..
16 years ago
Can a class implement two interfaces that each contains the same method signature? Can some body explain with examples please...
16 years ago
Want to know from which class a String Class is inherited.
16 years ago
Nevermind... I figured it out.. I had questions about the ActionListeners needs to be implemented to do this... But i know what they are now... Thanks...
16 years ago
Can some body give me a sample program to add two text fields which takes numbers as the input and give me output by adding the two numbers upon clicking a 'add' button.

Thanks much.
16 years ago
How else can i tell the loop to scan through the Array List?
16 years ago
I have the following program:
public static void main (String[] args)
{
ArrayList name = new ArrayList();

name.add ("Jim");
name.add ("David");
name.add ("Eddy");
name.add ("Murphy");
name.add ("David");
name.add("Don");

System.out.println (name);

I have to find all of the Array list indices where 'David' occurs and print these. I will need to loop through the ArrayList getting each entry and checking to see if it is 'David'. I have to use the method .equals to compare Strings, not == (this can only be used for primitive data types), need help to convert the below program to use equals method..

for (int i=0; i<band.size(); i++)
{
String str = "David";
if (band.get(i) ==(str))
{
System.out.println("The Strings are equal");
}
else
{
System.out.println("The Strings are not equal");
}
}
16 years ago
Below is the code i changed it to use Array lists, the code after the while loop doesn't get executed and directly goes to the end of while loop to ask me the question if i have more bands to calculate? Not sure why? please suggest..


[ EJFH: Added "[CODE ]" tags. ]
[ June 11, 2007: Message edited by: Ernest Friedman-Hill ]
16 years ago
Please see the code below and I am trying to change the program to use ArrayLists instead of Arrays. When i changed the program to use ArrayLists, the program stops after reading the how many number of weeks?

Not sure wh? Please help..

public class TstAr {

/**
* @param args
*/
public static void main(String[] args) {


System.out.println("Give me no.of bands?");
int num = Keyboard.readInt();
TstAr[] ta = new TstAr[num];

for (int i=0;i<ta.length;i++)
{
System.out.println("Name of Band" + (i+1));
String n = Keyboard.readString();
ArrayClass ac = new ArrayClass(n);
ta[i] = ac;
}

System.out.println("How many weeks of sales?");
int numWks = Keyboard.readInt();

for (int i=0;i<ac.length;i++)
{
for (int j=0;j<numWks;j++)
{
System.out.println("How many boxes did BandBooster # " + (i+1) + "sell for week number " + (j+1));
int numBoxes = Keyboard.readInt();
ac[i].updateSales(numBoxes);
}
}



for (int i=0;i<ac.length;i++)
{

//toString
System.out.println(ac[i].toString());
}



}

}
16 years ago
If somebody can explain why a static method cannot refer to an instance varible? if possible please explain with an example...
16 years ago
I want to know the difference between the two. If some body could please help me with this.. Thanks.
16 years ago