DOC PREVIEW
USF CS 112 - Lecture Notes

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1ClassesObject-Oriented Design• Method for designing computer programs• Consider “objects” interacting in theprogram– Example: a zoo, a gradebookOOD Goals• Robustness– Gracefully handle failures• Adaptability– Evolve as necessary• Reusability– Many programs use same piece of codeOOD Principles• Abstraction– Abstract Data Types (ADTs)– Interfaces• Encapsulation– Information Hiding• Modularity– Easily plug together componentsWhat is a class?• Data and the methods that operate onthat data – collectively called members– Example: bank account class• Provide structure for organizing programsMethods• Typically, data (variables) declared private• Methods operate on data– accessors – read data, provide access todata but do not change it– mutators – change data• examples from bank account, zoo???– constructor – builds a new object2Writing Classes• Must be implemented in a file namedclassname.java– well…there are also inner classesBankAccount Class• public BankAccount(double balance);• public void withdraw(double amount);• public void deposit(double amount);• public double checkBalance();Creating and Using ObjectsBankAccount b = new BankAccount(500);//Type Name = new Type(constructor parameters);//how would you withdraw funds?Creating and Using Objects//how would you withdraw funds?b.withdraw(300);object_name.method_name(param list);Constructor• Special-case function called when anew object is created• Used to initialize member variables– Examples?• Default constructor takes no parametersFlight class• Think about the design of a class torepresent a flight…– Data members?– Methods?3Exercises1. Implement and test the Flight class.Scope• What is the scope of each of the variablesyou declared in your flight class?static• Static class member - a variable withscope the same as a class member– 1 per class, not per object• Example - car serial numberExercises1. Design, implement, and test aPassenger class. Make sure that youkeep track of the passenger’s frequentflyer


View Full Document

USF CS 112 - Lecture Notes

Documents in this Course
Structs

Structs

4 pages

Trees

Trees

25 pages

Strings

Strings

27 pages

Queues

Queues

3 pages

Trees

Trees

24 pages

Arrays

Arrays

5 pages

ArrayList

ArrayList

24 pages

Stacks

Stacks

2 pages

Stacks

Stacks

8 pages

Trees

Trees

24 pages

Stacks

Stacks

8 pages

Queues

Queues

16 pages

Queues

Queues

17 pages

Queues

Queues

17 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?