Beruflich Dokumente
Kultur Dokumente
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