Functional Prototype
The best way to start writing your project - and also help finish
up your design - it by writing a functional prototype.
This is a very simple and limited program that
implements a very small part of the solution.
During the Analysis Stage, you already prototyped the user-interface.
During the Design Stage, it's useful to protype some of the
file-handling features.
Start with VERY BASIC functions. Here are some suggestions:
- Write a sample text-file for one of the
lists in your design overview
- Write a method to search for something in the sample file
- Write a method to count something in the sample file
- Write a method to copy the ID strings into a List box
(e.g. all the names)
- Write a method to copy the ID strings into an array
- Write a method to sort the array
Here is an example for the Sport Team example design.
Sample File Game2009-12-15.txt |
Functional Prototype to Check Scores |
2009.12.15 away Paris won 59 40 Al 5 Bob 3 Carl 7 Doug 5 Ed 9 Fred 15 Greg 10 Hal 5 Ike 0 Joe 0 |
import java.io.*; public class Functional { public static void main(String[] args) { new Functional(); } public Functional() { checkTotal(); } public void checkTotal() { // Reads game.txt file, adds up all the players points // and checks whether the total matches the recorded score try { BufferedReader info = new BufferedReader( new FileReader("game2009-12-15.txt")); String date = info.readLine(); String place = info.readLine(); String opponent = info.readLine(); String result = info.readLine(); String ours = info.readLine(); String theirs = info.readLine(); int ourScore = Integer.parseInt(ours); int theirScore = Integer.parseInt(theirs); int addup = 0; while(info.ready()) { String name = info.readLine(); String points = info.readLine(); int p = Integer.parseInt(points); addup = addup + p; } System.out.println(ourScore); System.out.println(addup); if(addup == ourScore) { System.out.println("correct"); } else { System.out.println("wrong"); } info.close(); } catch(IOException ex) { System.out.println(ex.toString()); } } } |
If some of this programming work is difficult, it might be because you have
not clearly thought out the contents of your data-structures.