• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Program i need help bad

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As it doesn't look this has anything to do with JSP. moved to the Java in General(beginner) forum.
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Erik Falt
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if(myString.indexOf(",") != -1)//still has a comma
 
Erik Falt
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I second what fred said and I probably should have mentioned that. It is very important to take small steps along the way.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic