CISC 3115
Introduction to Modern Programming Techniques
Lab #3
Defining Classes

How to Develop and Submit your Labs

Lab 3.1 — A Class Named Name (Name)

Here is a working Name class with the following behavior: Your job is to make the following changes: Sample Test Run

For example if the file names.text contains:

Edwards             	Steven              
Carter              	Joshua              
Carter              	Joshua              
Jackson             	Anthony             
Carter              	Barbara             
Evans               	Edward              
White               	Christopher         
White               	Christopher         
Taylor              	Michelle            
Baker               	Melissa             
Young               	Anthony             
Hall                	Michael             
the program should produce the following output:
name: Steven Edwards
formal: Steven Edwards
official: Edwards, Steven
initials: S.E.

name: Joshua Carter
formal: Joshua Carter
official: Carter, Joshua
initials: J.C.

Duplicate name "Joshua Carter" discovered
name: Anthony Jackson
formal: Anthony Jackson
official: Jackson, Anthony
initials: A.J.

name: Barbara Carter
formal: Barbara Carter
official: Carter, Barbara
initials: B.C.

name: Edward Evans
formal: Edward Evans
official: Evans, Edward
initials: E.E.

name: Christopher White
formal: Christopher White
official: White, Christopher
initials: C.W.

Duplicate name "Christopher White" discovered
name: Michelle Taylor
formal: Michelle Taylor
official: Taylor, Michelle
initials: M.T.

name: Melissa Baker
formal: Melissa Baker
official: Baker, Melissa
initials: M.B.

name: Anthony Young
formal: Anthony Young
official: Young, Anthony
initials: A.Y.

name: Michael Hall
formal: Michael Hall
official: Hall, Michael
initials: M.H.

---
12 names processed.

Some Guidance and Notes

Submitting to CodeLab

Lab 3.2 — A Phone Number Class (PhoneNumber)

Using the Name class of Lab 3.1 as a guide, code a PhoneNumber class and its associated main. The class should have the following state: and the following behavior: Sample Test Run

For example if the file numbers.text contains:

(356)153-9460
(290)261-7625
(761)321-9457
(724)091-7819
(759)301-3133
(072)023-0203
(060)075-3782
(060)075-3782
(369)348-9660
(844)824-5853
(692)839-8466
(216)386-2922
the program should produce the following output:
phone number: (356)153-9460
area code: 356
exchange: 153
line number: 9460
is toll free: false

phone number: (290)261-7625
area code: 290
exchange: 261
line number: 7625
is toll free: false

phone number: (761)321-9457
area code: 761
exchange: 321
line number: 9457
is toll free: false

phone number: (724)091-7819
area code: 724
exchange: 091
line number: 7819
is toll free: false

phone number: (759)301-3133
area code: 759
exchange: 301
line number: 3133
is toll free: false

phone number: (072)023-0203
area code: 072
exchange: 023
line number: 0203
is toll free: false

phone number: (060)075-3782
area code: 060
exchange: 075
line number: 3782
is toll free: false

Duplicate phone number "(060)075-3782" discovered
phone number: (369)348-9660
area code: 369
exchange: 348
line number: 9660
is toll free: false

phone number: (844)824-5853
area code: 844
exchange: 824
line number: 5853
is toll free: true

phone number: (692)839-8466
area code: 692
exchange: 839
line number: 8466
is toll free: false

phone number: (216)386-2922
area code: 216
exchange: 386
line number: 2922
is toll free: false

---
12 phone numbers processed.

Some Guidance and Notes

Submitting to CodeLab

Lab 3.3 — A Phone Book Entry Class (PhonebookEntry) (Approval)

Hopefully you're getting the idea now. This lab has you using composition on the Name and PhoneNumber classes of the previous two labs to create a third, more complex class named PhonebookEntry. The basic structure is the same — only now you will be employing methods of the previous two classes when coding this new class. The state for this class is: and the behavior is:

Submitting to CodeLab

  • Even though your PhonebookEntry class is dependent upon the Name and PhoneNumber classes, you should only submit the PhonebookEntry class to CodeLab.

    Sample Test Run

    For example if the file phonebook.text contains:

    Edwards             	Steven              	(356)153-9460
    Carter              	Joshua              	(290)261-7625
    Carter              	Joshua              	(761)321-9457
    Jackson             	Anthony             	(724)091-7819
    Carter              	Barbara             	(759)301-3133
    Evans               	Edward              	(072)023-0203
    White               	Christopher         	(060)075-3782
    White               	Christopher         	(060)075-3782
    Taylor              	Michelle            	(369)348-9660
    Baker               	Melissa             	(844)824-5853
    Young               	Anthony             	(692)839-8466
    Hall                	Michael             	(216)386-2922
    
    the program should produce the following output:
    phone book entry: Steven Edwards: (356)153-9460
    Dialing Steven Edwards: (356)153-9460
    
    phone book entry: Joshua Carter: (290)261-7625
    Dialing Joshua Carter: (290)261-7625
    
    Warning duplicate name encountered "Joshua Carter: (761)321-9457" discovered
    phone book entry: Joshua Carter: (761)321-9457
    Dialing Joshua Carter: (761)321-9457
    
    phone book entry: Anthony Jackson: (724)091-7819
    Dialing Anthony Jackson: (724)091-7819
    
    phone book entry: Barbara Carter: (759)301-3133
    Dialing Barbara Carter: (759)301-3133
    
    phone book entry: Edward Evans: (072)023-0203
    Dialing Edward Evans: (072)023-0203
    
    phone book entry: Christopher White: (060)075-3782
    Dialing Christopher White: (060)075-3782
    
    Duplicate phone book entry "Christopher White: (060)075-3782" discovered
    phone book entry: Michelle Taylor: (369)348-9660
    Dialing Michelle Taylor: (369)348-9660
    
    phone book entry: Melissa Baker: (844)824-5853
    Dialing (toll-free) Melissa Baker: (844)824-5853
    
    phone book entry: Anthony Young: (692)839-8466
    Dialing Anthony Young: (692)839-8466
    
    phone book entry: Michael Hall: (216)386-2922
    Dialing Michael Hall: (216)386-2922
    
    ---
    12 phonebook entries processed.
    

    Some Guidance and Notes

    • Coding a class that uses composition
      • In particular, the chaining of methods calls from the outer class to the corresponding methods of the instance variable's class.
    • The duplicate entry vs duplicate name emphasizes the notion of object equality.