Forums Register Login

Program to Access an Array Using a Command-Line Argument

+Pie Number of slices to send: Send
Hey everyone. I have this programming assignment with instructions below followed by my code. Will y'all take a look to make sure I'm on the right track? Thanks so much!

INSTRUCTIONS:
Purpose: To learn how to build and access an array.
Write a program that will read in a number from 0 to 25 and spell out that number. The program must also report any values that are out of range.
In other words, I want to type
java Say 22
and see
twenty-two



][/CODE][edit]Add code tags. CR[/edit]

[ November 07, 2008: Message edited by: Campbell Ritchie ]

[ November 07, 2008: Message edited by: Benjamin Chau ]

[ November 07, 2008: Message edited by: Benjamin Chau ]

[ November 07, 2008: Message edited by: Benjamin Chau ]

[ November 07, 2008: Message edited by: Benjamin Chau ]
[ November 07, 2008: Message edited by: Benjamin Chau ]
+Pie Number of slices to send: Send
Thank you for the e-mail. We have a policy of not answering questions by e-mail; everybody should be able to read the answer. And please maintain indentation with the code button; code is difficult to read without.

So what goes wrong when you try to compile that class? The error message "expected boolean found int" usually means you have used = when you are supposed to use ==. Does anything else go wrong?
And I think it would be better to print "number out of our range" than "invalid entry."
+Pie Number of slices to send: Send
And what does it say the purpose of the question is?
+Pie Number of slices to send: Send
And what is the purpose of the loop?

Henry
+Pie Number of slices to send: Send
I hadn't noticed the loop. Nor had I noticed there are { and } missing, and two ;s missing.
+Pie Number of slices to send: Send
Ok Campbell, I trimmed it down and edited it per the guidelines. And Henry, you're right - I don't need a loop after all. I wanted to limit the user to only numbers from 0 to 25. In review of the code, I don't need a loop at all, or even an if..else statement. I'll fix my code to reflect this. Is that y'all's thinking also?
+Pie Number of slices to send: Send
Well, what happen when you compiled it? You still have to fix the many compile errors.

Henry
+Pie Number of slices to send: Send
Henry,

I'm still having problems compiling. It has something to do with setting my envirornmental path variable correctly. No matter what I try, I can't seem to get it right. Still working on that. Thanks for asking though...

Benjamin
+Pie Number of slices to send: Send
 

Originally posted by Benjamin Chau:

I'm still having problems compiling. It has something to do with setting my envirornmental path variable correctly. No matter what I try, I can't seem to get it right. Still working on that. Thanks for asking though...




I would recommend that you don't write another line of code until you get the build environment going. Without this environment, you could be building crap without knowing it.

Henry
+Pie Number of slices to send: Send
 

Originally posted by Benjamin Chau:
I'm still having problems compiling. It has something to do with setting my envirornmental path variable correctly.


What, EXACTLY, is the text of the compiler error message? That tells you a LOT about what you need to start looking at.

if you get something like

'javac' is not recognized as an internal or external command,
operable program or batch file.


You need to work on your PATH. if you get something like

javac: file not found: fred.java
Usage: javac <options> <source files>
use -help for a list of possible options


it's a problem with you CLASSPATH. Other error can point to problems with your code. There is no way for anyone to help without you telling us what the real problem is.

Even once you get your environment working, I think you need to read the problem again. It specifically says "Purpose: To learn how to build and access an array." I don't see you building an array, although one could argue you are accessing the args[] array. I think if you continue with this algorithm, your instructor will probably mark you down.

But please heed Henry's advice. Get your environment working FIRST, and only then worry about your code.
+Pie Number of slices to send: Send
Fred,

It's the first one:

'javac' is not recognized as an internal or external command,
operable program or batch file.

Others have tried to help me out and I've done as their advice says (change the Environmental Path Variable) but I still can't get it right. I'm running XP Media Edition and here's exactly what I'm doing:

1) I pull up Control Panel then double-click the System icon.

2) I click on the Advanced tab, then the box that reads: Environment Variables.

3) I click the button New under the System variables space and when a box pops up I type in Variable name and the Variable value, using JAVA as the name and the following directory for the value (since that's where the Java software is located on my computer). Here's the exact directory I type in for the Variable value:

C:\Program Files\Java\jre1.5.0_06\bin

4) I repeat the exact same steps as above (3)) for the space that reads: User variables for my name.

5) I open my Command Prompt window and try to compile a program, javac HelloWorld, for instance. Then I get that error message again.

'javac' is not recognized as an internal or external command,
operable program or batch file.

Now when I open up the Command Window and look at the default Path Variable, I see the same directory as always, unchanged, despite all the steps I've taken as described above. Here's the default Path Variable that I see in Command Prompt that never seems to go away:

C:\Documents and Settings\my name>


Any suggestions would be greatly appreciated...

Benjamin
+Pie Number of slices to send: Send
I have answered on your other thread. You may need to reinstall Java.
+Pie Number of slices to send: Send
have you checked to be sure there really IS a "javac.exe" in that directory?
+Pie Number of slices to send: Send
 

Here's the exact directory I type in for the Variable value:

C:\Program Files\Java\jre1.5.0_06\bin



A "JRE", aka Java Runtime Environment, is used for running Java only. It doesn't include a Java compiler.

Henry
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1392 times.
Similar Threads
Running a Program from Elements in its Title
Assignment 1.4 (Say)
Change Due/Tendered Program
Multiplication Table
Leap Year program
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:38:24.