15
1 G54PRG Programming Lecture 1 Amadeo Ascó Adam Moore Example Project

Example Project

  • Upload
    shiro

  • View
    30

  • Download
    0

Embed Size (px)

DESCRIPTION

Example Project. Previously. GUI Example Switch. Overview. Study a problem and discompose it. Overview. Write a simple Address Book Application Each entry should be able to store the following information about an address: Street name Number City Postcode Country - PowerPoint PPT Presentation

Citation preview

Page 1: Example Project

1

G54PRG ProgrammingLecture

1

Amadeo Ascó Adam Moore

Example Project

Page 2: Example Project

2Amadeo Ascó , Adam Moore

Previously

• GUI Example– Switch

Page 3: Example Project

3Amadeo Ascó , Adam Moore

Overview

Study a problem and discompose it

Page 4: Example Project

4Amadeo Ascó , Adam Moore

Overview

• Write a simple Address Book Application– Each entry should be able to store the following

information about an address:• Street name• Number• City• Postcode• Country• Occupants - each occupant should have a first name,

last name, date of birth and title (Mr, Ms, Miss, Mrs)

Page 5: Example Project

5Amadeo Ascó , Adam Moore

Overview

– The application should be able to perform at least the following functions:

• Add a new address• Delete an existing address• Display an address• Add a new occupier record• Delete an existing occupier record• Display any addresses on a given city• Display any addresses on a given postcode• Display addresses for a particular occupier

Page 6: Example Project

6Amadeo Ascó , Adam Moore

Data

• Write a simple Address Book Application– Each entry should be able to store the following

information about an address:• Street name• Number• City• Postcode• Country• Occupants - each occupant should have a first name,

last name, date of birth and title (Mr, Ms, Miss, Mrs)

Address Book

address

occupant

Page 7: Example Project

7Amadeo Ascó , Adam Moore

Data

• Address– Street name

• Is the address a street name?• Has the address a street name?

– Number• Is the address a number?• Has the address a number?

– City• Is the address a city?• Has the address a city?

No

Yes member variable

No

Yes member variable

No

Yes member variable

Page 8: Example Project

8Amadeo Ascó , Adam Moore

Data

• Address– Postcode

• Is the address a postcode?• Has the address a postcode?

– Country• Is the address a country?• Has the address a country?

– Occupants• Is the address the occupants?• Has the address the occupants?

No

Yes member variable

No

Yes member variable

No

Yes member variable

s

Page 9: Example Project

9Amadeo Ascó , Adam Moore

Data

• Addresspublic class Address { private String mstrStreetName; private int miNumber; private String mstrCity; private String mstrPostcode; private String mstrCountry; private Vector<Occupant> mOccupants;

public Address(String strStreetName, int iNumber, String strCity, String strPostcode, String strCountry) { mOccupants = new Vector<Occupant>(); } // Constructor ()

...} // end class Address

public class Address { private String mstrStreetName; private int miNumber; private String mstrCity; private String mstrPostcode; private String mstrCountry; private Vector<Occupant> mOccupants;

public Address(String strStreetName, int iNumber, String strCity, String strPostcode, String strCountry) { mOccupants = new Vector<Occupant>(); } // Constructor ()

...} // end class Address

Page 10: Example Project

10Amadeo Ascó , Adam Moore

Occupant

• Occupant– First name

• Is the address a first name?• Has the address a first name?

– Last name• Is the address a last name?• Has the address a last name?

– Date of birth• Is the address a date of birth?• Has the address a date of birth?

No

Yes member variable

No

Yes member variable

No

Yes member variable

Page 11: Example Project

11Amadeo Ascó , Adam Moore

Occupant

• Occupant– Title (Mr, Ms, Miss, Mrs)

• Is the address a title?• Has the address a title?

– Addresses• Is the address a last name?• Has the address a last name?

No

Yes member variable

No

Yes member variable

s

Page 12: Example Project

12Amadeo Ascó , Adam Moore

Data

• Occupierpublic class Occupier { private String mstrFirstName; private String mstrLastName; private Date mBirthDate; private Vector<Address> mAddresses;

public Address(String strStreetName, int iNumber, String strCity, String strPostcode) { mAddresses = new Vector<Address>(); } // Constructor ()

...} // end class Address

public class Occupier { private String mstrFirstName; private String mstrLastName; private Date mBirthDate; private Vector<Address> mAddresses;

public Address(String strStreetName, int iNumber, String strCity, String strPostcode) { mAddresses = new Vector<Address>(); } // Constructor ()

...} // end class Address

?Occupier(String strFirstName, String mstrLastName, Date birthDate) { Occupier(String strFirstName, String mstrLastName, Date birthDate) {

Page 13: Example Project

13Amadeo Ascó , Adam Moore

Data

• Occupierpublic class Occupier { private String mstrFirstName; private String mstrLastName; private Date mBirthDate; private Vector<Address> mAddresses;

public Occupier(String strFirstName, String mstrLastName, Date birthDate) { mAddresses = new Vector<Address>(); } // Constructor ()

...} // end class Address

public class Occupier { private String mstrFirstName; private String mstrLastName; private Date mBirthDate; private Vector<Address> mAddresses;

public Occupier(String strFirstName, String mstrLastName, Date birthDate) { mAddresses = new Vector<Address>(); } // Constructor ()

...} // end class Address

Occupier(String strFirstName, String mstrLastName, Date birthDate) { Occupier(String strFirstName, String mstrLastName, Date birthDate) {

Page 14: Example Project

14Amadeo Ascó , Adam Moore

Data

• Address Book is a class AddressBook– Data

• Contains Addresses Vector of Addresses

– Need functionality; methods• Add new addresses• Remove existing address• Load from file• Save to file

AddRemoveLoadSave

Page 15: Example Project

15Amadeo Ascó , Adam Moore

Data

• Occupier Book is a class ListOccupiers– Data

• Contains Occupiers Vector of Occupiers

– Need functionality; methods• Add new occupier• Remove existing occupier• Load occupiers from file• Save occupiers in to fileSave

LoadRemoveAdd