Upload
others
View
8
Download
0
Embed Size (px)
Citation preview
Assignment, part1: feedback and common mistakes
INFO-0010
Samuel HIARD
Some statistics
106 registered students 97 received submissions• Project is mandatory for the oral exam
5 did not compile• 1 was easily fixable
5 compiled, but with warnings• Use « -Xlint » in your compilation to display warnings
1 contained only compiled classes• Functionality testing possible, but not source code analysis
Automatic testing on all working submissions• GuessTester• Search for keywords in source code (guidelines)
25 completely graded
Results
For the 25 completely graded:
For the rest:• Over 93 working submissions
• 56 worked perfectly (GuessTester)
• 8 worked perfectly except for « CHEATER »
• 29 to be manually tested
0
1
2
3
4
5
6
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
occ
urr
ence
s
Grade
Manual testing
29 submissions to manually analyze
11 were analyzed so far• 4 had a problem with port usage
• 3 were « let-me-do-the-oral-exam » submissions
• 1 had wrong parameter usage
• 1 never sends « \r\n » in the client
• 1 doesn’t accept « TRY XX »
• 1 had a lot of source code, but nothing works
Outline of the presentation
Selected examples illustrating mis-conceptions(incl. source code when relevant) are shown today.
These examples are sorted according to thefrequency of the problem in the submissions, whenavailable.
Report (64%)
Report is evaluated mainly on two criterias: Presentation
• Nice frontpage
• Justified text
• Numbered sections
• No misprints/errors
• Images non blurry if any
Content• Most important : software architecture and control flow
• If several classes, at least explain what each class does
• A diagram is always better than a lot of text
Exceptions (52%)import java.net.*;import java.io.IOException;import java.io.InterruptedIOException;
public class GuessingServer {public static void main (String argv[]) throws Exception{
ServerSocket ss = new ServerSocket(13105);//init of the socket
try{while(true){
Socket accepter = ss.accept();//accept the connection of a clientClientWorker client = new ClientWorker(accepter);//create a thread
corresponding to the clientclient.start();//start the thread}
}catch(InterruptedIOException iioe){//exception handler for the timeoutSystem.err.println ("Remote host timed out during read operation");
}catch(IOException e){//any other exception for the threadSystem.err.println("ioexception:" + e);
}finally{//closing the socket
ss.close();}
}}
ALWAYS catch Exceptions!
Comments (~47% )(Don't focus on the code, but on what the code looks like)
public class GuessingGame{private boolean inProgress;private String secretPositions;private boolean[] showFilter;private int lives;private final ArrayList<Character> proposedLetters;
static{PredefinedWords.addWords();
}
public BattleshipGame(){proposedLetters = new ArrayList<Character>();
}
private void pickAWord(){final Random randomNumberGenerator = new Random(new Date().getTime());secretWord = PredefinedWords.alWords.get
(randomNumberGenerator.nextInt(PredefinedWords.iCapacity));showFilter = new boolean[secretWord.length()];
}
public void newGame(){inProgress = true;pickAWord();lives = 6;proposedLetters.clear();
}
public boolean inProgress(){return inProgress;
}
Comments!At least one introductory block at the beginning of the fileAt least one block for each functionAt least one line for each code block bigger than 8 lines
public int lives(){
return lives;
}
public int proposedLettersNumber(){
return proposedLetters.size();
}
public String secretWordWithQuestionMarks(){
StringBuilder secretWordWithQuestionMarksBuilder =
new StringBuilder(secretWord);
for(
int letter = 0;
letter < secretWord.length();
++letter
)
if(!showFilter[letter])
secretWordWithQuestionMarksBuilder.setCharAt(letter, '?');
return secretWordWithQuestionMarksBuilder.toString();
}
public String proposedLetters(){
StringBuilder proposedLettersStringBuilder = new StringBuilder();
for(Character letter: proposedLetters)
proposedLettersStringBuilder.append(letter);
return proposedLettersStringBuilder.toString();
}
TCP (~40%)
(This is the server)
byte msg[ ] = new byte [64] ;
//receiving header
int len = in.read(msg);
//Initializing the subroutine
RequestParser sub = new RequestParser(msg);
Respect the stream-oriented property of TCP
Do multiple reads if you use low-level primitives
Or use BufferedReader.readLine() !!
Naming (~38%)(This is the server)
ServerSocket ss = new ServerSocket(23011);
Scanner sc = new Scanner(System.in);
char rep = 'n';
while(rep != 'y'){
System.out.println("Waiting for a new connection to handle...");
Socket ts = ss.accept();
Worker w = new Worker(ts);
Thread t = new Thread(w);
t.start();
System.out.println("New connection handled.");
}
Use self-explanatory names for variables, methods and classes.
Time-outs (~28%)
serverSocket = new ServerSocket(Port);
clientSocket = serverSocket.accept();
input = new BufferedReader(clientSocket.getInputStream());
output= new PrintWriter(clientSocket.getOutputStream());
input.readLine();
Use Socket Time-outs (default : none)
GuessingServer.java
Archive ( ~26% ) "You will ensure your main class is named (…) located (…) at the root of
the archive, (…).“
“You will not cluster your program in packages or directories. All java files should be found in the same directory.”
Icons from Windows 8.1™
archive.zip
MyProjectFolder
src
report
GuessingClient.java
MyReport.pdf
archive.zip
GuessingClient.java
GuessingServer.java
MyReport.pdf
Not sanctioned for this project
Guidelines (~10% ) You will implement the programs using Java 1.8,
with packages java.lang, java.io, java.net and java.util.• import org.omg.CORBA.portable.UnknownException;
You will ensure that your program can be terminated at any time simply using CTRL+C, and avoid the use of ShutdownHooks• Runtime.getRuntime().addShutdownHook(new Thread() { …
The server listens on port 2xxx – where xxx are the last three digits of your Ulg ID• socket = new Socket(44444, port);
Respect the guidelines
And the rest
Not useful to show example
Forget to synchronize the access to shared data (if any)
Inconsistent indentation (~15%)
Multi-threading (~5%)
That's all for the first part
Keep on the good work!