Sie sind auf Seite 1von 3

Assessment Specification: A company holds addresses of its clients in a text file with the following format:MNT1 Joe Stegman=187

West Street=Coventry=CV12-3AL FEM5 Beth Hemeryick=3 Chapel Lane=Birmingham=B33-7QP MET4 Jim Taylor=50 Jefferson Avenue=Stafford=ST4-7HJ Records from this list are extracted by entering a four character code (the "selector"). The symbols in the code must match exactly for a record to be selected - but a star (*) in the code matches any symbol. Examples of how "selector" matches the code on the input record:Selector M*** M*** FE** FE** ***5 ***5 Code MNT1 FEM5 MET4 FEM5 MET4 FEM5 Matches? Yes No No Yes No Yes

The addresses are to be printed onto address labels which have the following format:A xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxx B xxxxxxxxx xxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx B xxxxxxxxx xxxxxxxxxxxx C xxxxxxxxxxxxxxxx xxxxxxxxxxxxx A

The left and right margins (A) are five characters wide The horizontal gap (B) between labels is 2 characters The vertical gap (C) between labels is 2 lines Each label is 35 characters wide and 6 lines deep. There are three labels across the page. You should assume that a non-proportional font is being used, that is each character has the same width. At the start of printing the labels the first row of labels should indicate the start and the selection criteria used. At the end of the run, the last row of labels should indicate END and the number of labels printed.

You are required to produce a working Java program that meets the specification given above documented as described above and to hand in a written report [50%] that:1. Describes the main functions that your program will have to carry out. [5%] 2. Describes a plan of action that you will use to complete the program to the specification given above. [5%] 3. Describes the program and data structure that you intend to use in this program. [10%] 4. Contains an annotated listing of your completed program. [15%] 5. Describes the test data you will use with your program. [10%] 6. Contains an annotated printout of the results of using your test data. [5%]

Stater Program ** Note that this starter program is INCOMPLETE. You will need to ensure that you fully understand how it functions before making changes to it. The starter program consists of four classes:-

A sample datafile called "Label_data.DTA" that contains records in the correct format is available for your use. It should be copied into the subdirectory that contains your source code for this project. A sample of the data is shown below:MNT1 FEM5 MET4 MEA4 MWA2 Joe Stegman=187 West Street=Coventry=CV12-3AL Beth Hemeryick=3 Chapel Lane=Birmingham=B33-7QP Jim Taylor=50 Jefferson Avenue=Stafford=ST4-7HJ John Adey=104 Corporation Street=Wednesbury=W. Midlands=B98-2BA Keith Goodall=235 Staverley Road=Birmingham=B17-3JS

Class Test
public class Test { public static void main(String[] arg){ LabPrinter myPrinter = new LabPrinter(); try{ myPrinter.getAddressesFromFile(); } catch (Exception e) {System.out.println(e); }//end try }//end method main() }// end class Test

Class LabPrinter
import java.io.*; import java.util.Scanner; import java.util.Vector; public class LabPrinter { Vector<Address> addressList; Label [] labels; public LabPrinter(){ addressList = new Vector<Address>(); labels = new Label[3]; }//end constructor LabPrinter() public void getAddressesFromFile() throws java.io.IOException, java.io.FileNotFoundException { String inputLine; Scanner sc = new Scanner(new File("Label_data.DTA")); while (sc.hasNextLine()){ inputLine = sc.nextLine(); System.out.println(inputLine); // print completed line if it matches }//end while }//end method getAddressesFromFile() public void addAddress(String inputLine){ addressList.add(new Address(inputLine)); }//end method addAddress() }//end class LabPrinter

Class Label
public class Label { Address anAddress; public Label(Address anAddress){ this.anAddress = anAddress; }//end constructor Label public String getLine(int i){ return anAddress.line[i]; }//end method getLine(i) }//end class Label

Class Address
public class Address { String selectionCode; String[] line; public Address(String inputLine){ selectionCode = inputLine.substring(0,4); line = new String[6]; for(int i=0; i<6; i++) line[i] = ""; }//end constructor Address(String) public boolean compare(String target){ char t, f; int count = 0; for(int i=0; i<=3; i++){ t = target.charAt(i); f = selectionCode.charAt(i); if (t == f ) count++; } // next i return (count == 4); }// end method compare() }//end class Address

Sample Data (File Labels_data.DTA)


MNT1 FEM5 MET4 MEA4 MWA2 MNA1 MST5 MEA FWJ6 MEA1 MSA1 MEA4 MNT3 FWA MEM7 MSA2 MET3 MWT MEM8 MST3 MEA1 MEA5 MNA3 FSM4 MEN2 Joe Stegman=187 West Street=Coventry=CV12-3AL Beth Hemeryick=3 Chapel Lane=Birmingham=B33-7QP Jim Taylor=50 Jefferson Avenue=Stafford=ST4-7HJ John Adey=104 Corporation Street=Wednesbury=W. Midlands=B98-2BA Keith Goodall=235 Staverley Road=Birmingham=B17-3JS Stanley Dicklin="Dunaromin"=12 High Street=Bridgnorth=Shropshire=DY45-7PZ Charles Chapman=83 Wood End Drive=Wolverhampton=WV23-7GS Alan Jennings=23 Enville Road=West Bromwich=B63-4ER Valerie Ellis=12 Wheeler Avenue=Birmingham=B20-2TY John Dunn=28a Rushkin Avenue=Wombourne=Nr Dudley=West Midlands=DY34-8HS Peter Boyer=3 Wood Street=Walsall=WS16-4NS Vincent Field=Flat 6=35 Thornhill Avenue=Leicester=LE45-3MQ Edward Williams=3 Shakley Road=Willenhall=WS22-6GA Pauline Conroy=8 Hagely Road=Birmingham=B23-9AC Trevor Haynes=236 Cannock Road=Walsall=WS12-4KS John Paul Satre=24 Hall Street=Coventry=CV23-8AP Steven Riley=155 Redicap Heath Road=West Bromwich=B98-6OY Ronald Winters=21 Apsley Road=Birmingham=B7-5SM Alan Bates=21 King Avenue=West Bromwich=B98-4WP Ron Vannelli=67 Prospect Way=Birmingham=B43-6JW Rene Descartes=123 Rue de la Plage=Paris=FRANCE Henry Crun=156 Pentonville Road=Coventry=CV10-5GS Peter Rabbit=124 Farm Lane=Alcester=B99-5EP Iris Price=52 Grove Vale Avenue=Birmingham=B30-6LY Monty Stratus=93 Leicester Road=Manchester=M17-9FU

Das könnte Ihnen auch gefallen