aspose file tools*
The moose likes Beginning Java and the fly likes Program i need help bad Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Program i need help bad" Watch "Program i need help bad" New topic
Author

Program i need help bad

Erik Falt
Greenhorn

Joined: May 16, 2005
Posts: 3
I have this program that i need to get done for school, and i am utterly lost. If someone could help me with it, the help would be greatly appreciated.

heres the template i was given:

public class StringParse
{
public static void main(String[] args)
{
// Variable for user input

// get the input from a user and remove the leading and trailing white spaces
// send the string to a method for manipulation

} // end main


public static void createAddress ( String address)
{
// variable for array of type string ( make it large enough to hold 35 strings)

// create a variable to hold a line of the address

// create a variable to hold an individual word or comma

// create a variable to hold the index of a space in a string

// create a variable to hold the index of the next comma in your string

// set a variable to be the index of your array and initialize it




// use a loop to go through the string -- a while loop that looks at the size of the string

while( ) // loop through the string while it is not empty
{
// remove white space

// look for the first comma in the string and set a variable with that value


// if you find a comma you need to pull off the part before it
if ( )
{
// if no comma is found you are at the last line
// set your variable to your entire string
// set your address string to empty
}
else
{
// otherwise you need to pull off the part up to the comma
// this will represent one line of the address
}


// while the part you removed has at least 1 character
while( )
{
// trim the current part

// find the first [space] in the string

// if no space is found than your string only contains the last word
// or character in that line of the address
// if it has a space you will need to pull the part of before the space


if ( )// no space found
{
// you will need to remove the empty spaces
// and enter that string into your array of strings
// set current part = to an empty string
}
else // space found
{
// pull off one word form the set
// set value in array
}

// remove the part of the user input that you have used already
// and entered into the array --basically your first line

// increment array variable


} // end while loop

// save the commas in the array
// this would be the comma that was at the end of the string you
// pulled of previously

// increment the array counter

// set the string to the remaining part not used yet
// you have a variable that knows where the comma is
// so use the substring method

} // end while

// Print out the array in proper format using a for loop
// to get through the array
// remember to return the line where you find a comma
// but do not print the comma

for ( ) // loop through the array you filled
{
if ( ) // you find a comma print something

else
// print something else
}// end for loop



} // end the method

} // end the class
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

As it doesn't look this has anything to do with JSP. moved to the Java in General(beginner) forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

what problems are you having? Are you getting a compile error, or are you not sure where to start? It seems like the steps are spelled out in a rather straight-forward manner, so give it a shot and if you have any problems, we'll be willing to answer them.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Erik Falt
Greenhorn

Joined: May 16, 2005
Posts: 3
I'll be the first to admit, im not good at java at all. I have the first part done with JOptionPane and everything, but when it comes to the if else statement where i have to find the commas, im done. Any help is appreciated.
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
if(myString.indexOf(",") != -1)//still has a comma
Erik Falt
Greenhorn

Joined: May 16, 2005
Posts: 3
Well, i see how that helps, but it still leaves me lost. While in school, Arrays totally confused me. I know i have to set some arrays, but i just dont know where.
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I'm not sure I can help you a whole lot more than the comments provided. Why don't you write as much as you can and if/when you get stuck post back with the code (please use code tags) and specifically what you are stuck on. The best way to learn is to start typing.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11312
    
  16

Originally posted by Steven Bell:
Why don't you write as much as you can and if/when you get stuck post back...


the only thing i'd add to this is DON'T write as much as you can before you try compiling/running things.

start off declaring the string for holding user input, compile that, and try running it. it probably won't do much, but if it compiles/runs, you know you've at least done that part right.

next, try and get the input string from the user. maybe add a line to print it back out, so you know you have it (this line would most likely be removed later). compile/run/fix/repeat until you're sure THAT works...

THEN try removing the leading and/or trailing white space, and output the line again...

THEN try passing the string into a method, and verify you GET the string into the method...

and so on.

i garantee that if you try and write the whole program before you try compiling it even once, you're head will explode when you see all the error messages you are BOUND to get (and i don't mean you specifically, i mean ANYBODY).

writing software is a very iterative process - write-compile-run-test-repeat. the less you write each time, the easier it is to find mistakes.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I second what fred said and I probably should have mentioned that. It is very important to take small steps along the way.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Program i need help bad