Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

At the main method create a single dimension array

 
William Castillo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I NEED HELP!!!
I am currently working on a program for my Java class but I quite don't understand it. These are the instructions::::

"At the main method, create a single dimension array containing your "first name $ middle name % last name and ONE space" i.e. "George & Washington % Rodriguez "
NOTE: Every method dealing with your name, MUST be called from main, PASSING your name to it.
Using the for loop, if, else if, else, ||, and &&, printf, and any other command you want,
examine each character of your name and determine if it is:
a space, a vowel (a,e,i,o,u), a consonant (b,w,g, etc) the symbol % or the symbol $,
and using the current value of x in your for loop print:
"character [x] located at position x is a consonant" or
"character [x] located at position x is a vowel" or
"character [x] located at position x is a space" or
"character [x] located at position x is a not a vowel or a consonant or a space".
ie: My name is [George $ Washington % Rodriguez]
character [G] located at position 0 is a consonant
character [e] located at position 1 is a vowel
character [o] located at position 2 is a vowel
character [r] located at position 3 is a consonant
character [g] located at position 4 is a consonant
character [e] located at position 5 is a vowel
character [ ] located at position 6 is a space
character [$] located at position 7 is not a vowel or a consonant or a space
character [ ] located at position 8 is a space
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome..

First off:

"first name $ middle name % last name and ONE space" i.e. "George & Washington % Rodriguez "

So if middle name does not exist, no $ delimiter? (Look for clues like that).

Secondly:

TRY IT!

Put together your first attempt, analyze the requirements and story board it.

No one is going to do it for you.


WP
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice exercise,
start by writing the class and the main method. Inside of it create a single dimension array, containing the String required.
Show what you have done. Then we can go on.


 
Avinash Oak
Greenhorn
Posts: 15
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
william : go ahead,
Show us some code, then we debug.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12123
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EVERY single time I start writing java, I start by creating my class with a main method that prints "hello, Fred". it's seven lines - and i put my braces on lines by themselves.

I compile that, run it, and make sure it works. THEN i'd start with the next piece:

At the main method, create a single dimension array containing <something that looks like a string>

I wouldn't even worry about the specific stat in it at this point, I'd just try and declare it and put SOMETHING in it. I may even write a line of code to print out "Hey, I created the array" - knowing that I will delete that line of code later.

Then I'd add the next piece, compile and test it, etc.

I never never never write more than 5 lines of code without compiling and testing...and ideally only one or two.
 
William Castillo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I got so far:
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi William, and welcome to JavaRanch!
I've added code tags to the source code you posted to make things a bit more readable.
When you post a topic or reply containing source code - Java or otherwise - you can add these using the Code button.
Also, it's very helpful to post code snippets that compile and run, if at all possible.
For instance, in this case you've posted the code for the main() method and a method called myName(), but there's no surrounding class.
Now this may have been intentional, but it's better to include those bits of code, because some people might not pick up on that fact.
It just saves on confusion and gets you helpful replies more quickly.



 
William Castillo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I got this so far. But what I'm trying to accomplish is this:
character [W] located at position 0 is a consonant
character [i] located at position 1 is a vowel
character [l] located at position 2 is a consonant

I don't need the program done for me, I just need to understand the structure. Any sugestions?

Thank you.

 
William Castillo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tip on using the Code button Jelle. Learn something new everyday. Thanks to every one for your advices.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to be unclear on some of the basics, which is why I wouldn't recommend that you rush into this assignment just yet.
Take Fred's advice and start with a small application that compiles, runs and behaves as you expect it to.
If it does expand it - slowly, and make sure it keeps on compiling, running and behaving.
If it doesn't, well then you have something very specific you can ask us to help you with.

Just to get you started I've modified your code a bit and created a simple program that just prints a hello world message in several ways.
It covers some basic points that will be relevant to your program, like printing to the console, creating and accessing arrays, a basic for-loop and defining and invoking your own method.
 
William Castillo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jelle. I'll try that and move on little by little. I'll let you know how it goes.

Once again, thanks for the help.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48949
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Castillo wrote:Thanks for the tip on using the Code button Jelle. Learn something new everyday. Thanks to every one for your advices.
You’re welcome. You should also avoid long lines (evry link will give you different figures for exactly how long). I have changed your long line, which was quite easy because of the + operators, and you can see how it is done. It can be very difficult to read long lines.
 
William Castillo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I'm moving forward, but I'm getting an error in "myName.Length();" and "myName.charAt(x);". I just don't know how to get rid of this error, so I can run the program. Any body have any suggestion?
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's something i don't get

The first vowel " + Letter + " located at position " + x + "is a consonant."


Are you looking for a vowel or a consonant?

When do you call the method (poorly) named Name?


Anyway arrays don't have a method called Length() nor a method called charAt() but a variable called length


 
Campbell Ritchie
Sheriff
Pie
Posts: 48949
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Nicola Garofalo is saying is that this particular problem might be sorted out if you got rid of the [] in the type of the parameter for the Name method. I agree Name is a poor name for that method.
 
William Castillo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help. I made the changes you guys recommended and it got rid of all my errors, except when I declaring "Organizer();" in my main method. I don't know if I'm missing something inside the () or what.

 
Campbell Ritchie
Sheriff
Pie
Posts: 48949
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are calling that method, you need to pass it a String (not a String[]). Pass the String (myName) to it in the () where you call it. Why are you creating a String[] in the first place? You don’t appear to use it.
Unless you want a command-line argument, which you can find details of here and here. In that case you would use args rather than creating a new array.

I am afraid Organiser is no better a name for your method.
 
William Castillo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figure it out. I needed to put "Organizer(myName);". I was putting "Organizer();".

Thank you so much for all your help guys. This is my first time looking for help using a posting website. This one rocks!!!
 
Campbell Ritchie
Sheriff
Pie
Posts: 48949
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Castillo wrote: . . . Thank you . . . a posting website. This one rocks!!!
You’re welcome and thank you, too
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic