data structures , algorithms , modules nouns. data-items...

24
IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (1/24) For Stage B of the project, you must produce a plan for : Data Structures , Algorithms , Modules that you will need in your program. The following methodology is recommended: (1) Nouns for Data-structures (Data members) In your user-stories and goals, find NOUNS. These represent data-items or data-structures. The little things are data-items, especially if there will be many copies. Collections or bigger things are data-structures. For example, a name is a data-item, but a list of names is a data structure - probably an array. If a list is permanent, it needs to be stored in a file. (2) Verbs for Algorithms (Methods) In your user-stories and goals, find VERBS. These represent things to do - algorithms. When you identify an algorithm, try to link it to a data-item or data-structure. For example, rather than "find a name", it should be "find a name in the user file" or "find a name in the names array". Try to group the algorithms together with the data-structure(s) affected. When possible, include parameters, pre-conditions, post-conditions, and results (return values). (3) Modules (Classes) Once the data-structures and algorithms are identified, GROUP these together into cohesive modules. Cohesive means the ideas belong together. In a program for a video-rental store, the customer database should be separate from the video database, and these should form separate classes. The task of renting a video will use both of these classes, but it should be in a third class - e.g. the cash-register class. What Order to Do It You can develop these ideas in any order. You might try to list all the data-structures first, then add the methods to the data-structures, and finally group data-structures into cohesive classes. But you probably won't think of everything the first time around, so you will go back and add more. If you can think ahead, and object-oriented programming makes sense to you, you might start with the classes rather than starting at the data-structures end. Classes correspond roughly to areas of the problem/solution. In the video-rental store, the customers are clearly a separate area from the videos, so it is easy to think of a customers class and a videos class. In any case, you probably need several iterations in the development process. You can start by making simple lists without worrying too much about organizing the lists. Then take your list and start grouping things together, putting algorithms together with data-structures and grouping them roughly into classes. Once everything is listed and grouped, start adding details - parameters for algorithms, sample data, pseudo-code for algorithms, and diagrams for data-structures and class relationships. Most people will think about many things at once - data-structures, then algorithms, then back to data-structures, then invent a class, etc. Most students will find it productive to set a clear goal, like "list all data-structures" and write something down, then work on another goal. If you try to "do it all in your head" you are likely to get lost and confused, and waste lots of time "starting over". Be sure to produce lots and lots of rough notes, and keep them to include in the appendix.

Upload: others

Post on 22-May-2020

24 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (1/24)

For Stage B of the project, you must produce a plan for :

Data Structures , Algorithms , Modules

that you will need in your program. The following methodology is recommended:

(1) Nouns for Data-structures (Data members)

In your user-stories and goals, find NOUNS. These represent data-items or data-structures. The little things are data-items, especially if there will be many copies. Collections or bigger things are data-structures. For example, a name is a data-item, but a list of names is a data structure - probably an array. If a list is permanent, it needs to be stored in a file.

(2) Verbs for Algorithms (Methods)

In your user-stories and goals, find VERBS. These represent things to do - algorithms. When you identify an algorithm, try to link it to a data-item or data-structure. For example, rather than "find a name", it should be "find a name in the user file" or "find a name in the names array". Try to group the algorithms together with the data-structure(s) affected. When possible, include parameters, pre-conditions, post-conditions, and results (return values).

(3) Modules (Classes)

Once the data-structures and algorithms are identified, GROUP these together into cohesive modules. Cohesive means the ideas belong together. In a program for a video-rental store, the customer database should be separate from the video database, and these should form separate classes. The task of renting a video will use both of these classes, but it should be in a third class - e.g. the cash-register class.

What Order to Do It

You can develop these ideas in any order. You might try to list all the data-structures first, then add the methods to the data-structures, and finally group data-structures into cohesive classes. But you probably won't think of everything the first time around, so you will go back and add more.

If you can think ahead, and object-oriented programming makes sense to you, you might start with the classes rather than starting at the data-structures end. Classes correspond roughly to areas of the problem/solution. In the video-rental store, the customers are clearly a separate area from the videos, so it is easy to think of a customers class and a videos class.

In any case, you probably need several iterations in the development process. You can start by making simple lists without worrying too much about organizing the lists. Then take your list and start grouping things together, putting algorithms together with data-structures and grouping them roughly into classes. Once everything is listed and grouped, start adding details - parameters for algorithms, sample data, pseudo-code for algorithms, and diagrams for data-structures and class relationships.

Most people will think about many things at once - data-structures, then algorithms, then back to data-structures, then invent a class, etc. Most students will find it productive to set a clear goal, like "list all data-structures" and write something down, then work on another goal. If you try to "do it all in your head" you are likely to get lost and confused, and waste lots of time "starting over". Be sure to produce lots and lots of rough notes, and keep them to include in the appendix.

Page 2: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (2/24)

== Preliminary Design - Due Friday 26 Oct 2007 ==

You must produce a preliminary design consisting of:

• Classes - a list of classes - names and brief descriptions. For each class, list the following:

• Data-structures - list of data-structures for this class - names and brief descriptions - some sample data will make the descriptions easier.

• Algorithms - list of algorithms - names and brief descriptions - specify any data affected by the algorithm

Clearly specify where files and Abstract-Data-Structures will be used.

== Finished Design - Due Friday 16 Nov 2007 ==

This starts with the preliminary design, and expands it to include:

Data-Structures

This must include:• diagrams (e.g. tables for arrays, files with record structures, arrows for linked-lists work, etc) • sample data showing normal data, abnormal data, and limits (e.g. max and min values).

Algorithms (Methods)

Descriptions of algorithms must include:• method name• parameters (including types and sample values)• return type and sample values• pre-condtions and post-conditions• sufficient pseudo-code to allow the Java program code to be written easily - standard algorithms

such as search and sort do not require detailed pseudo-code, but problem specific and non-standard algorithms do require pseudo-code

Modules (Classes)

The complete list of modules must be presented in a hierarchical chart, showing relationships between modules (how they interact) as well as the names of all the data structures and methods contained in that module. The chart may be either:

• Boxes with lines connecting them - or -

• A text outline

The text outline is considerably easier to create because it can be typed and edited quickly, and it is easier to fit more on a page. The graphical chart is easier to view.

A composite presentation is a good compromise - a graphical chart showing the names (and a short description) of the classes, and a text-outline with the data and method contents of the classes.

Page 3: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (3/24)

== Example Design Process for Reading Helper ==The following pages document the recommended process for designing data-structures, algorithms, and modules based on user-stories and goals. Some parts are shown in greater detail than others.

(Step 1) Start with a user-story and identify nouns and verbs.

The user story for "Read an Assignment" has highlighted some nouns and verbs. User actions and interface elements are in <angle brackets>.

Nouns: document, vocab-list, server, user-action, log-file

Verbs : display , record

<Interface> : click , scrollable-box

(Step 2) Identify some data-structures, algorithms, and [modules] corresponding to step (1):

Data-Structures : Document - an .html file VocabList - a RandomAccessFile containing VocabRecord records VocabRecord - String word, String definition

Algorithms : Load, Display a DocumentLoad, Save, Edit, Sort a VocabList

(Step 3) We can produce a small, preliminary version of a class hierarchy with the ideas so far. [Square brackets] identify classes.

[Reading]Interface - see analysis section for appearanceLoad and Display the DocumentLoad the VocabListReact to user-clicks and Display vocab definition

[Document]Load, Display

[VocabList]Load, Save, Edit, Sort

[Vocab]String WordString Definition

Task: Read an Assignment User : Student

Interface : Reading-HelperInput : readable document and vocabulary list from (server)Output : document is *displayed* in a <scrollable box>Actions : user <scrolls> up and down, <clicks> on vocab words Automation : interface *displays* HTML or RTF doc properly, *records* user actions in a (log-file)

Page 4: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (4/24)

The same 3 steps above must be repeated (iterated) through other user stories and goals, extracting new ideas. As the list of data-structures, algorithms, and classes grows, the hierarchy (step 3) will grow longer and more complex. Some things may get added later and require changes to the hierarchy shown above. For example, the user story mentions "recording user actions in a log-file" - this was forgotten and will probably be added later.

The document and vocabulary list are crucial data-structures for this application. They must be saved in files on the server. Since the two are connected, we could put them together in a single class - e.g. a DocWithVocab class. But there are essential algorithms that are quite different for the two structures. So it is preferable to make a [Document] class, a [VocabList] class, and make a third class called [Reading] that contains a Document and a VocabList. Then we get a hierarchical design with one class connected to two others.

Some algorithms come directly from user-stories. Others come "out of our heads", especially "standard" algorithms. For example, a vocabulary list probably needs to be sorted, even though the user never requested it. So we can add a sort() method to the VocabList class.

In some applications, it makes sense to read a task and produce a corresponding [class]. That happened here with the - Read an Assignment - task.

Meeting Your Goals (?)The assessment criteria require that the design "fully support the processes needed to achieve the objectives of the solution (criterion A2)..." Students should re-read their goals occasionally to ensure that the design supports the objectives they wrote during the Analysis Stage.

"Meeting your goals" here is talking about the goals of the solution. YOUR goals as a student are to get a good grade on your project. To meet YOUR goals, be sure to READ the assessment criteria and DO all thie things required.

== Sections / Users / Tasks ==

One approach to organizing the design work is to break up the solution into smaller areas. The System Design Chart for the Reading Assistant shows that there are separate modules for teachers and students.

Another way to break down the solution is to look at the data-files that will be stored, and create a "wrapper class" for each type of data file. That means a Vocabulary List file is accessed through a [VocabList] class that can includes the file access commands (RandomAccessFile, seek, etc) and the needed methods (Load, Save, Edit. Sort). In the next step, we show a preliminary list of classes derived from the System Design Chart. If the System Design Chart was well done, it is quite easy to name the corresponding classes.

Page 5: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (5/24)

(Step 4) Candidates for Major Classes

Reading Assistant - System Design Chart

(Step 5) Smaller, Reusable Classes

The classes listed above are associated with user-tasks. Some smaller classes can be re-used by various larger classes. For example, the [VocabList] class will use a [Vocab] class to represent each record in the file, e.g:

[Vocab]String word String definitiongetWord() --> StringsetWord(String w) --> boolean

check that w is not emptyif not empty

word = format(w) // format shortens w to max length of word return true // means successfulelse return false // w was not acceptable

getAll() return word + "\n" + definition // this is easily displayed in a JEditPanegetDefinition() --> StringsetDefinition(String d) --> boolean

definition = format(d) // format shortens to max length of definition

Doc ServerReading

Documents+

VocabularyLists

ESL Student Reading Helper

Doc toRead

VocabHelp

Teacher Vocabulary List Writing Tool

Reading Doc New

VocabEntry

Student Data Files Login Names+PW Reading Sessions Data Individual Reading Lists

Teacher Review Student Records

Manage individualreading assignment lists

See which words thestudent(s) clicked on

Teacher – Manage Reading DocumentsReading documents are typed, copied,scanned and saved using standard software

- Teacher Interface - VocabWriter - Document - VocabList - StudentReviewer - Student Interface - Reader - Document - VocabList

(Student Files) - Login - ReadingList - ReadingSession

(Doc Server) - Document - VocabList

Page 6: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (6/24)

This small [Vocab] class could merely contain data fields, but it is better if it at least validates data before recording it. As described above, the setWord and setDefinition methods ensure that the size of the String does not exceed the maximum size permited.

Responsibilities and Encapsulation

CRC stands for Class, Responsibility, and Collaboration. The responsibility issue is important during the design stage. Here is an example question:

• The Vocab entries must be saved into a data-file. WHICH class will do the saving? That is, which class actually contains the save method?

The save method could be part of the Vocab class. This is a bit like a book that can put itself onto a library shelf. That sounds a bit strange. Another possibility is having the save method in the VocabList class. That seems a bit more sensible. We could put the save method in the main Teacher class, and make a [Save] button on the interface. But we could also have a [Save] button on the interface without necessarily having the save method in the same class.

The concepts of encapsulation and ADT say that methods should exist in the same class as the data they operate on. So the save method should NOT be in the Teacher class. It's usually a good idea to put methods in the lowest level class possible, to improve the chances of RE-USE. This means save should be in the Vocab class. However, if the vocabulary files are text-files, it won't be possible to save a single Vocab entry. So the VocabList class should do the saving, since it must save the entire list - the best location for the save method is in VocabList. VocabList will have the responsibility for saving Vocab entries. Then it probably makes sense for it to take responsibility for loading and editing.

What about displaying definitions? Since the user interface will be managed by the Teacher or Student class, we want those class to control contain the display methods. The VocabList class wouldn't have access to the controls where the data will be displayed.

For all the methods, we need to choose a class (or classes) for them. Thinking about responsibility is helpful when choosing a class for a method. Another important issue is that methods should be in the same class with the data they operate on. This isn't a rule - data can be transferred using parameters. But it improves organization and simplifies reuse if the methods are encapsulated with the corresponding data.

Moving Ahead

You probably have a variety of things written down, as well as lots of ideas in your head. At this point you should try to name everything that is important, and then organize all these things into classes. Using the list of classes from the previous page as a starting point, we can start putting methods into [classes] together with their corresponding data-structures. At this point it is sufficient to simply write names, but if you have ideas about algorithms and sample data, you might as well write them down as you think of them. At this point it is only a rough draft - it can be polished up later.

When writing lists of data-structures and methods into the classes, refer frequently to the documentation from Stage A, especially the System Design, Interfaces, and User Stories.

Page 7: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (7/24)

===== Version 1 ==========[ Teacher Interface ] - VocabWriter

* Document * VocabList

* JEditorPane for reading [Document]* JEditorPane for displaying [Vocab]

loadDocument - choose a document and load it into reading boxloadVocabList - load list of Vocab definitions for the documentshowAll - display entire list of words and definitionshandleClick - respond to teacher clicking a word

displayVocab - display vocab and definition (if they exist already) webLookup - display web-site definition of clicked word editVocab - edit definition saveVocab - save new (or changed) Vocab into VocabList

storeVocabList - save finished VocabList into file

- StudentReviewer* String student - name of current student* ReadingList - a reading list for a specific student* ReadingSessions - entire list of all reading sessions, loaded from a text-file* Choice students - list of all student names* List assignments - displays list of assignments for this student* List sessions - displays list of Reading Sessions for current student* TextArea session - displays one reading session for the current student

loadStudents - load students list from student accounts fileloadAssignments(String name) - load list of assignments for one student loadSessions(String name) - load list of ReadingSessions for one studentdisplaySession(sessionID) - display data from one session. SessionID is name+date+docaddNewStudent - add a new student name + password to student accounts filechangePassword(String name) - change a student password - no password required

as this is only available from the teacher interface

- AssignmentListEditor* String student - name of current student* Choice students - list of all student names* ReadingList assignments - list of assignments for this student* ReadingList allAssignments - all reading assignments (same as all documents)

loadStudents - load students list from student accounts fileaddNewStudent – add a new student tot he list, with a default passwordloadAssignments(String name) - load list of assignments for one student loadAllAssignments - load list of all assignmentsaddAssignment - respond to a click and add an assignment to the listremoveAssignment - respond to a click and remove an assignment from the listsaveAssignments - save revised assignments list back into student's reading list file

Page 8: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (8/24)

[ Student Interface ] - Reader * Document * VocabList

login - login student, check passwordgetAssignments - load list of reading assignments for this studentloadDocument - choose a document and load it into reading boxloadVocabList - load list of Vocab definitions for the documentdisplayDefinition - respond when user clicks a word - display Vocab definitionsaveSession - save student name,doc name, date, and list of words clicked into Sessions file

(Student Files) - Login

String[1000][2] students - 2-D array containing name and password for each student int studentsMax - number of data items stored in students array

load - loads all data from a sequential text-file (sorted)save - save all data back into sequential text-file (must be sorted first)getPassword(String name) - search for name and return matching passwordchangePassword(String name, String oldPassword, String newPassword)

- search for name, check that oldPassword is correct, change to newPassword reject passwords that are too short or too long, or contain invalid characters

addStudent(String name, String password, String masterPassword) - adds a new name, insert alphabetically, reject duplicate names

reject request if masterPassword is incorrectremoveStudent(String name, String masterPassword)

- remove student record, shorten the list, reject if masterPassword is incorrectsort - sort array alphabetically by name. This should never be necessary,

but an administrator can run it if something has gone wrong

- ReadingList* String[1000] titles - the list of document titles* int titlesMax - number of titles in array

addTitle - add a new title to the list - no duplicates

- ReadingSessions* Session[100000] sessions - list of all reading sessions, loaded from file* int sessionsMax - number of items in sessions array

load - load all reading session data into the sessions array

(Doc Server) - Document

load(JEditPane display) - loads document into display box

Page 9: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (9/24)

- VocabListVocab[1000] vocabs - array of Vocab items - each has a word and a definitionint vocabsMax - number of words in vocabs array

load - load words and definitions into vocabs arraylookUp(String word) --> return defintionsave(Vocab voc) - put a word and definition into vocabs array

must insert alphabetically, or replace existing wordstore - store all words and definitions into text-file

- ListMerger* VocabList[100] lists - array of small VocabLists* VocabList newList merge(VocabList listA, VocabList listB) --> VocabList

- merges two sorted lists and produces a new sorted list

mergeAll - merges all the VocabLists in lists uses merge to merge 2 lists, then uses merge again to merge newList with next list

- ReadingList* String[10000] titles – list of all reading assignments* int titlesMax - number of items in titles

(Re-usable classes) - Vocab

* String word

* String definition

getWord() --> StringsetWord(String w) --> boolean

check that w is not emptyif not empty word = format(w) // format shortens w to max length of word return true // means successfulelse return false // w was not acceptable

getAll() return word + "\n" + definition // this is easily displayed in a JEditPanegetDefinition() --> StringsetDefinition(String d) --> boolean

definition = format(d) // format shortens to max length of definition

- ReadingSession * String name - name of student* String document - name of document read• String date - date of reading session

* String began - time session began * String ended - time session ended * String[500] words - list of words clicked by the student * int wordsMax - number of items in words list

Page 10: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (10/24)

=========== Section B Version 2 =================Data Structures (Assessment B1)The program will require the following data structures :

Reading Document , Vocabulary List , Vocab-Item , Reading List , Reading Sessions , Student Login Data

-- Reading Documents --A Document consists of a normal document in either .HTML, .TXT or .RTF format. Other formats (e.g. MS Word .DOC) are not supported. These will be stored as individual files on a local server or a web-site, so documents may be used from public web-sites. The names and locations of the files is flexible, so the user can organize their documents in folders as they wish. The documents can be prepared with standard editors, like WordPad, FrontPage, Notepad, etc. There are no special markers or extra content required. Here are three sample files, as they would be displayed:

=== HTML ====

Stage D + Completed Project (all sections) : Monday 5 Mar 2006

A list of guidelines for each section is available at : http://ibcomp.fis.edu/projects/newproj/projectstart.pdf

Be sure to get started early and correctly. If you do a bad job starting, the rest of the project (lasting 10 months) can go badly.

=== TXT ===

RankCountryGDPDate of Information~~~~1World$ 51,480,000,000,0002004 est.~~~~2European Union$ 11,050,000,000,0002004 est.~~~~

=== RTF ===

2.3 MultithreadingTo help us in ensuring that all our event handling code gets executed only from within the event-dispatching thread, Swing provides a very helpful class that, among other things, allows us to add Runnable objects to the system event queue.

Runnable trivialRunnable

= new Runnable()

{

public void run() {

doWork();

}

};

The limitations on displayable file types is caused by the use of JeditorPane for the display.

Page 11: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (11/24)

-- Vocabulary List --A VocabList is stored in a structured HTML file. There will be one VocabList file for each document file (above). For convenience, these are stored in the same folder with the corresponding document (except for public web-site documents, which still require the vocab files to be stored locally). By using HTML for storage, the VocabList file can use various fonts and colors and can include pictures.

There is a record for each vocabulary word in the document. Each entry contains 2 fields - the word and the definition. The records are separated from each other by the delimiter “~~~”. Each word is surrounded by |bars| . Here is a sample file containing four vocabulary words :

complex , disease , hollow , hospital

<html>

<head>

</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">

<p>|complex|</p>

<p>it has many details and many connections between the details -<br>it is difficult

to understand</p>

<p><i>&quot;The math problem is very complex - I cannot solve it.&quot;</i></p>

<p>~~~</p>

<p>|disease|</p>

<p>illness or sickness - a medical disorder</p>

<p><i>&quot;Old people have many diseases.&quot;</i></p>

<p><i>~~~</i></p>

<p>|hollow|</p>

<p>empty inside, for example a ball filled with air</p>

<p><i>&quot;He is so stupid, it seems like his head is hollow.&quot;</i></p>

<p>~~~</p>

<p>|hospital|</p>

<p>a building where sick people stay for a few days and receive treatment -<br>when

they feel better, they leave the hospital</p>

<p><i>&quot;He is hurt - we must take him to the hospital.&quot;</i></p>

<p>~~~</p>

</body>

</html>

Beginning and end of records are marked by bars and squiggly lines, created when the teacher module stores the vocabulary file. Since this uses standard HTML for storage, the file can be re-edited later with a standard HTML editors – e.g. to improve the appearance, add graphics, etc. But the teacher's module will provide sufficient tools for basic formatting and adding graphics (possibly in raw HTML).

Page 12: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (12/24)

-- Vocabulary Item --A singleVocabItem contains a word and a definition. When the user clicks on a word, the program will search through the entire VocabList for the matching word. If it finds the word, it will extract the HTML code for that record and display it in the help box, by constructing a complete HTML document, like this:

-- VocabItem Source Code -- <html>

<head>

</head>

<body>

<p><b>disease</b></p>

<p>illness or sickness - a medical disorder</p>

<p><i>&quot;Old people have many diseases.&quot;</i></p>

</body> -- VocabItem Display --diseaseillness or sickness - a medical disorder

"Old people have many diseases."

-- Reading List --

The ReadingList file contains reading assignments for all the students. This is a RandomAccessFile with a record for each assignment. The records are added as they are assigned – the file is not sorted. Whenever a student looks at their reading assignments, the records for that student will be retrieved and sorted by Date Due. If a record is deleted (probably due to an error by the teacher), the file will be shortened, so there is never any extra empty space. Each record contains : Student Name [60 chars] Date Assigned [20 chars] Date Due [20 chars] Location of Doc [200 chars]

All fields are stored as UTF Strings. Dates are stored as: YYYY-MM-DD (simplifies sorting)

The Location field must contain a complete (absolute) path or URL (not a relative address).

A sample file is shown at the right.

Kohl, Helmut2005-10-252006-01-31http://www.cnn.com/030205/....

Kohl, Helmut2005-11-302005-12-15\\main\docs\AChristmasCarol.rtf

Jones, Christiana2005-11-302005-12-15\\main\docs\AChristmasCarol.rtf

Claus, Santa2005-12-052005-12-25\\main\docs\MyPresents.html....

** note – there are not actually blank spaces between records in the real file – they are added here for easier readability **

This part is copied from the VocabList.|bars| are changed to <b>bold</b> tags

The program adds the document tags.

Record #0

Record #1

Record #2

Record #3

Page 13: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (13/24)

-- Reading Sessions --

The ReadingSessions file keeps track of when each student reads each assignment. This saves a record every time a student opens a document. It is a “log” file, stored in a simple text file – a separate text-file for each student. Each time the student opens a document, the date, time and name of the document are appended to the text-file. Then each time the student clicks on a vocabulary word, that word is appended to the file. If the student clicks the same word several times, it will be recorded again each time. Sessions are separated by “~~~” - written at the beginning when a document is opened.

Record Structure: ~~~ Student Name Date (YYYY-MM-DD) Time (hh:mm) Doc Location vocab word vocab word vocab word .......Although the student's name is used to name the file, the student's name is also written into the file for convenience, in case the sessions from several students need to be merged into a larger file. A sample file is shown at the right.

~~~Claus, Santa2005-12-2421:15\\main\docs\MyPresents.htmlxylophoneklingelxylophonesynthesizerxylophone~~~Claus, Santa2005-12-2508:30\\main\docs\AChristmasCarol.rtf~~~Claus, Santa2005-12-2509:40http://www.cnn.com/frontpagepartisanevolutionaryrevolutionary

In the second session (AChristmasCarol), Santa did not click on any vocabulary words. In the first session he was obviously have trouble understanding the word “xylophone” .

-- Student Login Data --

The Login data file is a RandomAccessFile containing the name and password for each student. This file is kept sorted alphabetically by student name, so new names must be inserted in the correct position.

The student names are recorded in the format : Last, First . Each field is stored as a UTF String, 60 chars and 40 chars respectively.

Part of a sample file is shown at the right.

...Claus, SantarudolphKohl, HelmutmotorcycleJones, ChristianafootballKim, Suea-pAssword:can!be2SAFE...

Page 14: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (14/24)

Internal Data Structures (arrays, etc)For sample data, refer to the description of the corresponding data files (above).

[ Teacher Interface ]• Session – a class to store one record from ReadingSessions file

ClassString StudentName

String Date (YYYY-MM-DD) String Time (hh:mm) String Doc Location String[1000] words = list of vocab words clicked

• Assignment - a class to store one record for a reading assignment Class

String StudentNameString DateAssigned (YYYY-MM-DD)String DateDue String (YYYY-MM-DD)String Location

- VocabWriter• VocabList – String[] array containing VocabItems that the teacher typed in. These will be

written into the VocabList file when [save] is clicked.

- StudentReviewer• Assignments – String[] array - list of assignments for one student

Each String contains the address of a document.

• Sessions – array of Session objects, loaded from ReadingSessions file – for one student

- AssignmentListEditor• Assignments – String[] array - list of assignments for this student.

Each String contains address of a document.

• AllAssignments – String[] array – list of all assignment titles – loaded from the ReadingList file (without duplicates).

[Student Interface]- Reader

• VocabList – a single String containing the entire contents of the VocabList file

• ReadingList - String[] array – list of document titles for this student

Page 15: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (15/24)

(rounded boxes are data structures that could be encapsulated into reusable classes or ADTs)

Assignment

Session

Teacher Interface

VocabWriter

StudentReviewer

ReadingList Editor

StudentInterface

Reader

ListMerger

Login

Modular Organization (B3)

Document

Reading List

Vocab

Vocab List

Reading Sessions

Page 16: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (16/24)

Hierarchical Classes and Algorithm Pseudocode (B3 + B2)[ Teacher Interface ] - VocabWriter

* Vocab[] VocabList * JEditorPane for reading [Document]* JEditorPane for displaying [Vocab]

loadDocument - choose a document and load it into reading box

fileName = EasyApp.chooseFile()use Document.load

loadVocabList - load list of Vocab definitions for the documentopen fileread entire contents into one Stringparse file to retrieve individual VocabItems – Strings containing word + definition

storing these itmes in the VocabList array

showAll - display entire list of words and definitions

String text = “”;

for (int x=0;x < vocablist.max; x++){ vocab v = vocablist.getVocab(x); text = text + v.getWord() + “\n” + v.getDefinition + “\n”;}display HTMLheader + text + “</body>”

handleClick - respond to teacher clicking a word displayVocab - display vocab and definition (if they exist already)

get selected text from reading webLookup - display web-site definition of clicked word

run “explorer “http://www.wordweboline.com/search.pl?w=”+word+”\”” editVocab - edit definition

user types (or copies from web) definition into editing boxthey can type html codes if they wish, e.g. <b>...</b> or <p> or <img ...>

saveVocab - save new (or changed) Vocab into VocabList

get text from definition editing box

copy vocab definition text into vocabList

storeVocabList - save finished VocabList into filesort VocabList alphabeticallyinfo = HTML headerfor each entry in VocabList

info = info + word + definition + squigglessave entire info String into file

mergeLists - can merge two vocabList files to produce a new fileCopy contents of two files into two VocabListsmerge use storeVocabList to save into a new file

Page 17: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (17/24)

- StudentReviewer* String student - name of current student* ReadingList - a reading list for a specific student* ReadingSessions – Session[] array loaded from a text-file, for one student * Choice students - list of all student names* List assignments - displays list of assignments for this student* List sessions - displays list of Reading Sessions for current student* TextArea session - displays one reading session for the current student

loadStudents - load students list from student accounts fileopen Login filefor each record

read student nameadd name to students list

close file

loadAssignments(String name) - load list of assignments for one student

open ReadingList filefor each record

read thisNameif thisName matches name

read document locationextract document name (remove path)add documnt name to assignments list

endifend loopclose file

loadSessions(String name) - load list of ReadingSessions for one student

open ReadingSessions file for nameread squiggles while file.ready

info = new Sessionread info.studentNameread info.dateread info.timeread info.locationc = 0repeat

read info.words[c]c++

until vocab == squiggles

end loopclose file

displaySession(sessionID) - display data from one session. SessionID is name+date+docFind SessionID in sessionsCopy data fields into display box

Page 18: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (18/24)

addNewStudent - add a new student name + password to student accounts fileinput newNameinput newPasswordsearch Login file for matching nameif newName found

print error messagequit

elseinsert name,password into Login file

Sort the file (this is a safety measure, shouldn't really be necessary)

insertNewStudent(newName, newPassword)open Login filesearch for a record where name > newName at position Pjump to end of filerepeat

copy record ahead one positionmove back one record

until position P

write newName, newPassword into record P

removeStudent(badName)search in Login file for matching nameif found

from this position forward, copy each record back one positionthen shorten file by 1 record

sortLoginFileBubbleSort (should never need this, but provided as utility)

changePassword(String name) - change a student password - no password requiredas this is only available from the teacher interface

input newNameinput newPasswordsearch Login file for matching nameif newName found

write new password into existing record

Page 19: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (19/24)

- AssignmentListEditor* String student - name of current student* Choice students - list of all student names* ReadingList[] assignments - list of assignments for this student* ReadingList[] allAssignments - all reading assignments (same as all documents)

loadStudents - load students list from student accounts fileopen Login filefor each record

read nameadd name to students list

close file

loadAssignments(String name) - load list of assignments for one student open ReadingList filefor each record

info = new Assignementread info.studentNameread info.dateAssignedread info.dateDueread info.locationif (info.studentName matches name)

add info to assignments listcopy entire list into display box

loadAssignments - load list of all assignmentssame as loadAssignments(name), but copy all records into allAssignments

addAssignment - respond to a click and add an assignment to the fileinput data fieldscheck whether same location appears in assignments listif not

append new record to ReadingList file

removeAssignment - respond to a click and remove an assignment from the listuser clicks on assignment, then [delete] keyask “are you sure”

if yes thensearch for matching record in ReadingList fileif found

move following records ahead one positionshorten file be 300 bytes

Page 20: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (20/24)

[ Student Interface ] - Reader * Document * VocabList

login - login student and check password

repeatinput nameinput password

open Login filesearch for student nameif found

read correctPasswordif password matches correctPassword

start applicationelse

output :”wrong password”

elseoutput “cannot find user name”

until successful

loadAssignments - load list of reading assignments for this studentsame as AssignmentListEditor.loadAssignments(String)

loadDocument - choose a document and load it into reading boxset source file address in JeditorPaneappend to readingSessions file: squiggles, studentName, date, time, location

loadVocabList - load list of Vocab definitions for the documentsame as VocabWriter.loadVocabList()

displayDefinition - respond when user clicks a word - display Vocab definitionappend word to readingSession fileword = get selected text from JeditorPanesearch for word in vocabListif found

display word and definition in boxelse

open web-site dictionary to display definition

Page 21: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (21/24)

(Re-usable classes)- Assignment

* String StudentName* String DateAssigned (YYYY-MM-DD)* String DateDue String (YYYY-MM-DD)* String docLocation

makeDateString(int year, int month, int day) staticvalidate dateconvert year, month, day to Stringsadd leading 0 if necessary to make 2-digit month and dayreturn yearString + “-” + monthString + “-” + dayString

setDateAssigned(int year, int month, int day) DateAssigned = makeDateString(year,month,day)

setDateDue(int year, int month, int day) DateDue = makeDateString(year,month,day)

setStudentName(String name)Check that name exists in the Login fileif okay

StudentName = name

setDocLocation(String fileName)Location = fileName

- Session extends Assignment String date (YYYY-MM-DD) String time (hh:mm) String[1000] words = list of vocab words clicked

int wordsCount = 0

setDate(int year, int month, int day)date = makeDateString(year,month,day) (inherited)

setTime(int hour, int minutes)change hour, minutes to Strings, add leading 0 if neededtime = hourString + “:” + hourMinutes

addWord(String word)wordsCount = wordsCount + 1words[wordsCount] = word

Page 22: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (22/24)

- Vocab* String word

* String definition

getWord() --> String

setWord(String w) check that w is not emptyif not empty word = format('|' + w + '|') // add bars and P tags for structured data file

getAll() return word + "\n" + definition // this is easily displayed in a JeditPane

getDefinition() --> Stringreturn definition

setDefinition(String d) check that d is not emptyif oka y definition = format(d)

format(String info) --> Stringreturn “<p>” + info + “</p>” // add Paragraph tags

Page 23: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (23/24)

Mastery Factors

Adding data to RandomAccessFile

There are 2 RandomAccessFiles in the design: ReadingList and Student Login.

AssignmentListEditor.addAssignment will append a new record at the end of ReadingList.

StudentReviewer.insertNewStudent will insert a new student record in alphabetical order into the Login file.

Deleting fromRandomAccessFile

AssignmentListEditor.removeAssignment will delete an assignment record from ReadingList, shortening the file by one record.

StudentReviewer.removeStudent will remove a student record from the Login file, shortening the file by one record.

Searching in RandomAccessFile

StudentReviewer.loadAssignments must search through ReadingList to find records matching a specific student name.

Reader.login must search for a student name in the Login file. Assignment.getStudentName must search for a student name in the Login file. StudentReviewer.changePassword must search for a student name in Login and then change the password.

Recursion not doneMerging two sorteddata-structures

VocabWriter.merge will merge two VocabList files (text files) to produce a new text file. This is useful because several small vocabulary lists can be combined to make a larger list to use with a new document. Then the teacher can keep the useful words and delete those that don't apply to the document, rather than rewriting the entire vocabulary list for that document from scratch.

Polymorphism AssignmentListEditor has methods .loadAssignments(String) to load assignments for one student, and .loadAssignment() to load all assignments. This makes .loadAssignments polymorphic by virtue of differing parameter lists. Reader also has a .loadAssignments() method, but this uses the current student name to load only assignments for that student.

Inheritance Session extends AssignmentAssignment contains data about students and documents.Session adds data about the date and time.Assignments are recorded in the ReadingList file, whereas Sessions are recorded in the text-file ReadingSessions. Session also adds a list of the words that the student clicked during the reading session.

Encapsulation Assignment and Session and Vocab contain private data members with corresponding get.. and set.. methods. These methods protect against bad data being recorded in the objects.

Parsing a text-file Vocabulary List (VocabList) files are HTML text files, cleanly formatted to impose a record-structure. The HTML can be displayed directly in a browser window. But the record structure is parsed by VocabWriter.loadVocabList and Reader.loadVocabList to create a

Page 24: Data Structures , Algorithms , Modules NOUNS. data-items ...ibcomp.fis.edu/projects/newproj/docsB.pdf · Data Structures , Algorithms , Modules that you will need in your program

IB Comp Sci IA Project Stage B – ver 1 by Dave Mulkey, Germany, 2005 (24/24)

list of vocabulary words for a document.Hierarchical compositedata-structure

StudentReviewer.ReadingSessions is an array of Session objects.VocabWriter.VocabList is an array of Vocab objects.

Five SL mastery items Simple loops are used in all the Load methods.Assignment, Session, and Vocab are used as data record structures.VocabList and ReadingSessions are arrays.There are lots of user-defined methods.There are lots of methods using parameters, e.g. LoadAssignments(StudentName) and DisplaySession(SessionID) both in StudentReviewer.

ADT #1 Add and Retrieve data

none

ADT #2Handling ends

none

ADT #3Many error-handlers

none

ADT #4All methods, robust

none