Client Server Programming Assignment

Production DiaryTemplate/Example

Student Name/Number:

You should write a production diary/essay at least 1500 words. This diary is a record of your programming planning and development. The diary may be used to confirm that you have written this code yourself.


For each diary entry, the type of things you should record are:

  • Dates and times
  • Sources of information/reference
  • Problems encountered and how you solved them (showing code examples where required)
  • How you would extend the application
  • Any design used e.g. UML diagrams.
  • Version development showing how the code developed
  • Full explanation of your protocol

======

Your entry goes here.

An example of a diary entry

  • Need to take nasty if/else construct out of Protocol and replace with more readable/manageable switch statement.

Ref.

Can't remember switch syntax. Googled "java switch case" got useful ref:

Identify allowed states. (See Diagram Below)

Can use existing values … e.g. WAITING, ANOTHER etc. switch is easy 'cos states are int already so …

switch (state) {

case WAITING : theOutput = hello(); break;

Identify what to do in each state and make a simple class diagram entry to show methods for each state

WAITING : starting state , no input reqd.

+ hello( ) : String

Set current joke; send a greeting string; change state to SENTKNOCKKNOCK

SENTKNOCKKNOCK; need input ("Who's there?")

+ sendClue(String) : String

If input incorrect output a helpful message and stay in same state

Else send first clue (name) and change state

Other states .. OK can read if/else code form original and translate but need to write out method names for reference (consistency) …

+ hello( ) : String // awakening!!

+ sendClue(String) : String // got Who's there? OK

+ sendJoke(String) : String // got name who? OK

+ sendClue(String) : String // got Y or n

+ sendAnother (String) : String// need to quit on n or

else go to hello()

CODE:

switch (state) {

case WAITING : theOutput = hello() ; break;

case SENTKNOCKKNOCK : theOutput = sendClue(theInput); break;

case SENTCLUE : theOutput = sendJoke(theInput); break;

case ANOTHER : theOutput = sendAnother(theInput); break;

}

return theOutput;

Sample method:

private String sendClue(String theInput) {

if (theInput.equalsIgnoreCase("Who's there?")) {

theOutput = clues[currentJoke];

state = SENTCLUE;

} else {

theOutput = "You're supposed to say \"Who's there?\"! " +

"Try again. Knock! Knock!";

}

return theOutput;

}

OK – code all compiled OK. Code Version: V4.2

Finished before time!!