Question:
Help with java program?
Comp
2013-02-01 12:59:26 UTC
I have a project and I get it to do what i want but I still have bugs, so I have to redo the whole thing, how would you do it? posting important parts of it.

Just wanna know what should be doing what so I have a better idea, also Scanner can only be declared once, original command and input must be stored and saved.

Create a project called P1 that includes three classes:
1. A Command class that stores a command accepted from the user.
2. A NextCommand class that has a get() method that requests a command from the user and
stores it in a Command.
3. The P1 class that contains a main() method. The main method will use NextCommand to accept
commands from the user, will display the returned command, and will stop when an exit
command is received.

Legal commands
The following are legal commands:
· LET variable = expression
· DOC id “title” text
· PRINT expression
· DO filename
· HISTORY
· END
· # comment text

Command class
The Command class should have the following methods:

· Command(String string) creates an instance of a Command using one of the legal commands.
Note that case should not be significant when deciding on the command, so DO, do, Do, and dO
are equivalent. The case of the argument must not be changed.

· int getCommand() returns CMD_LET, CMD_DOC, CMD_PRINT, CMD_DO, CMD_HISTORY, or
CMD_END to indicate what command it is. The value CMD_INVALID reflects an unrecognized
command. The value CMD_COMMENT means a command that does nothing (e.g., a blank line
or a comment).

· String getArg() returns everything after the first word of the command. The separating space
must be discarded; if there are multiple spaces, discard them all. If there was nothing other than
the first word, it should return the empty string. (It could also return null if you prefer. Just
handle things appropriately elsewhere.) If an invalid command is entered, the argument should
be the entire command as entered, without changing case.

As an example, if the user entered the line “PRINT this expression” then getCommand() would return
CMD_PRINT and getArg() would return “this expression”.

NextCommand class
This class needs the following method:
(This method is supposed to be of type Command, so it needs to return a command, Im also a bit confused on this part.)

· Method get() accepts a command from the user and returns a corresponding Command. If the
user input ends (usually because of an end-of-file character), this method should assume and
thus act as if the user typed the command “END”.

P1 class
This class has the following method:
· main() uses NextCommand to request commands from the user. For each command received,
it prints out the command and its argument in exactly the format listed below. It loops until an
END command has been received. (It should print out that it got an END command before
exiting.)
Each command (including a comment) should generate a single line of output in the format
” or “” if there is no argument. Yes, the angle brackets are part
of the output.

Any help would be appreciated thanks in advance.
Three answers:
anonymous
2013-02-02 22:06:38 UTC
I can Answer Any Java Projects ,
?
2013-02-02 14:40:01 UTC
Hey I'm assuming you're in CS187 so email me if you want to work together. kevinhollerbach@gmail.com
Neunerball
2013-02-01 13:55:45 UTC
Nice try! We don't do your homework. We can help once you finished coding.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...