urgent help needed

Reply

Join Date: Mar 2006
Posts: 7
Reputation: parvin1987 is an unknown quantity at this point 
Solved Threads: 0
parvin1987 parvin1987 is offline Offline
Newbie Poster

urgent help needed

 
0
  #1
Mar 30th, 2006
hello
I,ve wrote a program but it doesn,t work correctly
please help me
i want to sort some strings based on the number that should be entered at first of each string for example the strings that you enter should be in this form:
12_hello
it means you should enter a number and then _ then a string
for example if you enter
5_allow
4_how
23_hi
the output should be
4_how
5_allow
23_hi

but my program can't do this
i will write my program here

please correct it for me
thanks in advance

Parvin


package sort;

import javax.swing.*;

public class arraySort
{
static String[] minStrSoFar = new String[1024];
static String sortStr[] = new String[1024];
static int j;
//***
//this method sorts entered strings based on the number that have been entered before ***//


public static void selectSort(int [] enterNum,int number,String part2[])
{
// initialize the variables
int posMin=0;
int temp;
int k;
String tempStr = new String ();



for(int i = 0;i<number -1 ; i++)
{

posMin = findPosMin(enterNum, i, number, part2);

if (posMin != i)
{
//this part sorts the part of string that is made up of numbers
temp = enterNum[i];
enterNum[i] = enterNum[posMin];
enterNum[posMin] = temp;

//this part sorts the part of string that is made up of characters
tempStr = part2[i];
// part2[i] = minStrSoFar[i];
// minStrSoFar[i] = tempStr;
part2[i] = sortStr[i];
sortStr[i] = tempStr;

}//end of if
JOptionPane.showMessageDialog(null,part2[i]);
}//end of for

}//end of selectSort method


//this method find the position of minimum between entered numbers

public static int findPosMin(int[] enterNum , int i,int number,String part2[])
{

minStrSoFar[i] = part2[i];
int posMinSoFar = i;

for( j =i+1 ;j<number ;j++)
{
if(enterNum [j] <enterNum[posMinSoFar] )
{
posMinSoFar = j;
minStrSoFar[i] = part2[j];
}//end of if

}//end of for
sortStr[i]=minStrSoFar[i];
return posMinSoFar;

} //end of findPosMin method

}//end of class arraySort



package sort;

//***
// this program sorts some strings that begins with number( based on their number)****//
import javax.swing.*;
import java.util.StringTokenizer;

public class sortString
{

public static void main(String[] args)
{
//initialize the variables
int number;
String stringNumber = JOptionPane.showInputDialog("how many string do you want to enter?");
number = Integer.parseInt(stringNumber);
String string[] = new String[number];
String part1[] = new String [number];
String part2[] = new String [number];
int enterNum []= new int[number];
int i;
for( i = 0; i<number; i++)
{
string[i] = new String();
part1 [i] = new String();
part2[i] = new String();
string[i] = JOptionPane.showInputDialog("enter your string");

StringTokenizer st = new StringTokenizer(string[i],"_");

//seperating 2 parts of the string
part1[i] = st.nextToken();
part2[i] =st.nextToken();
enterNum[i] = Integer.parseInt(part1[i]);

}//end of for
arraySort.selectSort(enterNum,number,part2);

}//end of main method
}//end of sortString class
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 3
Reputation: parvin2 is an unknown quantity at this point 
Solved Threads: 0
parvin2 parvin2 is offline Offline
Newbie Poster

Re: urgent help needed

 
0
  #2
Mar 30th, 2006
nobody wants to help me?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: urgent help needed

 
0
  #3
Mar 30th, 2006
Originally Posted by parvin2
nobody wants to help me?
Don't bump the thread. People will help you when they are ready.

You're on the right track though, you've tokenised the original string splitting it into two parts. Then you are sorting the string according to its integer. I'll have a look at it later.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC