public class PrintAddressLabel { public static void main ( String[] args) { System.out.

println ( "\nName: David Willmore" ); System.out.println ( "Period: 7\n\n" ); // Raw Data String address1 = "Jeff Yost\n9525 Main Street\nFairfax, VA 22032"; String address2 = "David Willmore\n5007 Mignonette Court\nAnnandale, VA 22003"; String address3 = "Robert Otto\nSuite 555 West\n1030 15th St. NW\nWashington, DC 20005"; // Parsing address 1 AddressInfo obj1 = new AddressInfo ( address1); System.out.println ( obj1.getFirstLine() ); System.out.println ( obj1.getSecondLine() ); System.out.println ( obj1.getThirdLine() ); // Parsing address 2 AddressInfo obj2 = new AddressInfo ( address2); System.out.println ( obj2.getFirstLine() ); System.out.println ( obj2.getSecondLine() ); System.out.println ( obj2.getThirdLine() ); // Parsing address 3 AddressInfo obj3 = new AddressInfo ( address3); .out.println ( obj3.getFirstLine() ); System.out.println ( obj3.getSecondLine() );

System.out.println ( obj3.getThirdLine() ); // Testing toString method System.out.println ( "\n\nProperly Formatted Output: " ); System.out.println ( obj1.toString() ); System.out.println ( obj2 ); System.out.println ( obj3 ); } // main } // PrintAddressLabel

/** * Name: David Willmore * Period: 7 * Date: 13 October 2011 * * File: AddressInfo.java * Description: This is the AddressInfo class. */ public class AddressInfo { private String myFirstLine; private String mySecondLine; private String myThirdLine; public AddressInfo ( String dataLine ) { int posOne = dataLine.indexOf ( '\n' ); myFirstLine = dataLine.substring ( 0, posOne ); String remain1 = dataLine.substring ( posOne+1 ); int posTwo = remain1.indexOf ( '\n' ); mySecondLine = remain1.substring ( 0, posTwo ); String remain2 = remain1.substring ( posTwo+1 ); myThirdLine = remain2; } // Constructor // Accessors: public String getFirstLine () { return myFirstLine; } public String getSecondLine () { return mySecondLine; } public String getThirdLine () { return myThirdLine; } // Override public String toString ()

{ String str = ""; str = str + "\n\n"; str += myFirstLine; str += "\n"; str += mySecondLine; str += "\n"; str += myThirdLine; return str; } // Override } // AddressInfo

Sign up to vote on this title
UsefulNot useful