DOC PREVIEW
UVA CS 101 - Classes

This preview shows page 1-2-3-4-5-6-38-39-40-41-42-78-79-80-81-82-83 out of 83 pages.

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

Unformatted text preview:

ClassesPreparationReadyObject-oriented programmingDesign an air conditioner representationSlide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Static variables and constantsInstance variablesConstructorsSimple mutatorsSimple accessorsParametric mutatorsFacilitator toString()First class – ColoredRectangleSneak peek facilitator toString()Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Slide 43Slide 44Slide 45Slide 46BackgroundExampleSlide 49Slide 50Slide 51Class ColoredRectangle – initial versionColoredRectangle in actionSlide 54Slide 55Slide 56ColoredRectangle.java outlineInstance variables and attributesSlide 59Slide 60ColoredRectangle default constructorSlide 62Color constantsSlide 64Slide 65Graphical contextJava coordinate systemSlide 68Method invocationSlide 70Improving ColoredRectangleSlide 72A mutator methodMutator setWidth() evaluationSubtletiesOther mutatorsMutator usageAccessorsAccessor usageSpecific constructionSlide 81Seeing doubleSlide 83ClassesPreparation•Scene so far has been background material and experience–Computing systems and problem solving–Variables–Types–Input and output–Expressions –Assignments–Objects–Standard classes and methodsReady•Experience what Java is really about–Design and implement objects representing information and physical world objectsObject-oriented programming•Basis–Create and manipulate objects with attributes and behaviors that the programmer can specify•Mechanism–Classes•Benefits–An information type is design and implemented once and reused as needed•No need reanalysis and re-justification of the representationDesign an air conditioner representation•Context•Behaviors•AttributesDesign an air conditioner representation•Context–Repair person–Sales person–Consumer•Behaviors•AttributesDesign an air conditioner representation•Context – Consumer•Behaviors•AttributesDesign an air conditioner representation•Context - Consumer•Behaviors–Turn on–Turn of–Get temperature and fan setting –Set temperature and fan setting –Build – construction–Debug•AttributesDesign an air conditioner representation•Context - Consumer•Behaviors–Turn on–Turn of–Get temperature and fan setting –Set temperature and fan setting –Build – construction–Debug – to stringing•AttributesDesign an air conditioner representation•Context - Consumer•Behaviors–Turn on–Turn of–Get temperature and fan setting –Set temperature and fan setting – mutation –Build – construction–Debug – to stringing•AttributesDesign an air conditioner representation•Context - Consumer•Behaviors–Turn on–Turn of–Get temperature and fan setting – accessing –Set temperature and fan setting – mutation –Build – construction–Debug – to stringing•AttributesDesign an air conditioner representation•Context - Consumer•Behaviors–Turn on – mutation –Turn of – mutation –Get temperature and fan setting – accessing –Set temperature and fan setting – mutation –Build – construction–Debug – to stringing•AttributesDesign an air conditioner representation•Context - Consumer•Behaviors–Turn on – mutation –Turn of – mutation –Get temperature and fan setting – accessing –Set temperature and fan setting – mutation –Build – construction–Debug – to stringing•AttributesDesign an air conditioner representation•Context - Consumer•Behaviors–Turn on–Turn of–Get temperature and fan setting –Set temperature and fan setting –Build -- construction–Debug•Attributes–Power setting–Fan setting–Temperature settingDesign an air conditioner representation•Context - Consumer•Behaviors–Turn on–Turn of–Get temperature and fan setting –Set temperature and fan setting –Build -- construction–Debug•Attributes–Power setting–Fan setting–Temperature setting – integerDesign an air conditioner representation•Context - Consumer•Behaviors–Turn on–Turn of–Get temperature and fan setting –Set temperature and fan setting –Build -- construction–Debug•Attributes–Power setting – binary –Fan setting – binary –Temperature setting – integerDesign an air conditioner representation// Represent an air conditioner – from consumer view pointpublic class AirConditioner {// instance variables// constructors// methods}•Source AirConditioner.javaStatic variables and constants// shared resource for all AirConditioner objectsstatic public final int OFF = 0;Static public final int ON = 1;static public final int LOW = 0;Static public final int HIGH = 1;static public final int DEFAULT_TEMP = 72;•Every object in the class has access to the same static variables and constants–A change to a static variable is visible to all of the objects in the class–Examples StaticDemo.java and DemoStatic.javaInstance variables// individual object attributesint powerSetting;int fanSetting;int temperatureSetting;•Instance variables are always initialized as soon the object comes into existence–If no value is specified•0 used for numeric variables•false used for logical variables•null used for object variables•Examples InitializeDemo.javaConstructors// AirConditioner(): default constructorpublic AirConditioner() {this.powerSetting = AirConditioner.OFF;this.fanSetting = AirConditioner.LOW;this.temperatureSetting = AirConditioner.DEFAULT_TEMP;}// AirConditioner(): specific constructorpublic AirConditioner(int myPower, int myFan, int myTemp) {this.powerSetting = myPower;this.fanSetting = myFan;this.temperatureSetting = myTemp;}•Example AirConditionerConstruction.javaSimple mutators// turnOn(): set the power setting to onpublic void turnOn() {this.powerSetting = AirConditioner.ON;}// turnOf(): set the power setting to ofpublic void turnOf() {this.powerSetting = AirConditioner.OFF;}•Example TurnDemo.javaSimple accessors// getPowerStatus(): report the power settingpublic int getPowerStatus() {return this.powerSetting;}// getFanStatus(): report the fan settingpublic int getFanStatus() {return this.fanSetting;}// getTemperatureStatus(): report the temperature settingpublic int getTemperatureStatus () {return this.temperatureSetting;}•Example AirConditionerAccessors.javaParametric mutators// setPower(): set the power setting as indicatedpublic void setPower(int


View Full Document

UVA CS 101 - Classes

Documents in this Course
Classes

Classes

53 pages

Recursion

Recursion

15 pages

Iteration

Iteration

88 pages

PLEDGED

PLEDGED

6 pages

Objects

Objects

33 pages

PLEDGED

PLEDGED

11 pages

CS 101

CS 101

42 pages

Iteration

Iteration

92 pages

Classes

Classes

186 pages

Classes

Classes

208 pages

Hardware

Hardware

21 pages

Arrays

Arrays

70 pages

Load more
Download Classes
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 Classes 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 Classes 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?