import javax.swing.JFrame; /** *Boundry class for addresses it does the interaction between the user and the address classes. */ public class AddressBoundry { private FullAddress _fullAddress; public AddressBoundry() { _fullAddress = new FullAddress(); } /** *Asks the user to fill in his address. */ public void setAddress() { //I am not using the overloaded constructor here because this is a cleaner way of programming. //Storing the address in untyped structures like Strings and then puttin them into the typed structure (FullAddress) feels strange. //But I did define the constructors so you can easily change this code into. //String firstName = UserIO.getStringFromUser("Please enter your first name:"); //.... //_fullAddress = new FullAddress(firstName,secondName,phoneNumber, houseNumber ......) _fullAddress.firstName = UserIO.getStringFromUser("Please enter your first name:"); _fullAddress.secondName = UserIO.getStringFromUser("Please enter the second name:"); _fullAddress.phoneNumber = UserIO.getStringFromUser("Please enter your phone number:"); _fullAddress.housenumber = UserIO.getIntFromUser("Please enter your house number:"); _fullAddress.streetName1 = UserIO.getStringFromUser("Please enter your street name:"); _fullAddress.streetName2 = UserIO.getStringFromUser("Please enter your postal code:"); _fullAddress.cityName = UserIO.getStringFromUser("Please enter the name of the city you live in:"); } /** *Shows the short adress to the user. */ public void viewShortAddress() { //I know this is a redundant cast I could just as well just access the full address. //but it shows the full address is rely a short address with a little extra. ShortAddress shortAddress = (ShortAddress)_fullAddress; AddressOutput addressOutput = new AddressOutput(shortAddress,false); addressOutput.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); addressOutput.setSize( 275, 180 ); addressOutput.setVisible( true ); /* System.out.println("Short address:"); System.out.println( shortAddress.firstName ); System.out.println( shortAddress.secondName ); System.out.println( shortAddress.phoneNumber ); **/ } /** *Shows the full adress to the user. */ public void viewFullAddress() { AddressOutput addressOutput = new AddressOutput(_fullAddress,true); addressOutput.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); addressOutput.setSize( 275, 180 ); addressOutput.setVisible( true ); /* System.out.println("Full address"); System.out.println( _fullAddress.firstName ); System.out.println( _fullAddress.phoneNumber ); System.out.println( _fullAddress.secondName ); System.out.println(_fullAddress.housenumber ); System.out.println(_fullAddress.streetName1 ); System.out.println(_fullAddress.cityName ); **/ } /** * Asks the user the question whether or not he wants to see the short address */ public boolean UserWantsToSeeShortAddress() { String answer = ""; boolean result = false; answer = UserIO.getStringFromUser("Do you want to see the short address? (y/n)"); result = (answer.compareToIgnoreCase("y")==0); return result; } }