• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Introduction to Computer Science

Module 10. Classes and Objects

In the previous module, we introduced the concept of object-oriented programming and presented a new type of problem suitable to solve with this approach. This module aims to present a complete picture on using Java for object-oriented programming by practice on the exercise of designing a Phone book directory. Through a set of short and concise presentations, we will introduce the concept of the class, object (state, behavior and identity), and abstraction, and define the correct syntax and provided functionalities in Java that we can use to implement classes and objects of different types and applications.

Designing classes

Constructors

Setters and Getters

Static properties and methods

Comparison

Textual representation of objects

Code for the Phone Book application

Here is the complete implementation of the Person class.

Using this implementation, we can implement a PhoneBook class that has the phone book storage and management functionalities. The main method of the class will implement the main user interface.

Each time the user wants to add a new person in the contacts, the add method is called to create a new Person object with the desired information and stored in the contacts list.

If the user instead wants to retrieve the contact information of a given person’s first and last name, we can invoke the find method, which will search for the person in the contacts, and display the desired information. If the person is not found, it should display an error message.

We can also remove a person from the contacts using the remove method. The search method over the contacts list remains the same, where instead of only reading the information we now set this entire element in the array to null. After we remove the person from contacts, we also decrement the number of contacts defined in the Person class.

Please inspect the example implementation and attempt to develop your own solution to the phone book application.

 

 

Primary Sidebar

List of Contents

  • Course Description
  • Module 1. Introduction to Computers and Programming
  • Module 2. The Java language
  • Module 3. Variables and Data Types
  • Module 4. Logical expressions and conditional executing
  • Module 5. Characters and Strings
  • Module 6. Loops
  • Module 7. Arrays
  • Module 8. Methods
  • Module 9. Introduction to the Object-Oriented Programming Paradigm
  • Module 10. Classes and Objects
  • Module 11. Inheritance and Polymorphism
  • Module 12. Interfaces and Abstract Classes
  • Module 13. Exception handling
  • Module 14. File I/O
  • Module 15. Recursion
  • Instructions for software installation
  • Self-assessment quizzes

Footer

This website has been created by Duygu Ataman, Devesh Devendra and Akash Harikrishanan. We thank New York University professors Craig Kapp, Anasse Bari and Gizem Kayar for sharing their feedback and resources to implement a successful online learning platform.

Contact

E-mail: ataman@nyu.edu

www.duyguataman.com

Dr. Duygu Ataman

Assistant Professor and Faculty Fellow, Courant Institute for Mathematical Sciences

Copyright © 2025 · eleven40 Pro on Genesis Framework · WordPress · Log in