Unformatted text preview:

Programmer-Defined TypesLoan ObjectProperties ClassificationRead-Only Vs Editable, Dependent Vs Independent1-Way Vs. 2-Way DependenciesTop-Down ProgrammingBottom-up Programming in BMISlide 8Loan InterfaceA Loan RepresentationStored Vs ComputedLoan AlgorithmSetting and Getting Stored PropertySlide 14Getting and Setting Computed Property (edit)Getting and Setting Computed Property (edited)Getting and Setting Computed Property(soln)Slide 18Slide 19Slide 20Modified Loan InterfaceMiddle-Out ProgrammingAnother Loan RepresentationConversion Errors with Principal Repn.No Conversion Errors with YearlyInterest Repn.Loan PairPrimitive Vs. Object PropertiesLoan Pair Interface (edit)Loan Pair Interface (edited)Typing ObjectsKinds of TypesLoan Pair Interface (soln)Loan Pair Interface: RestrictedTyping an ObjectProgrammer-defined Vs Predefined TypesSpace Efficient RepresentationSlide 37Getter MethodDefault Values for VariablesInvoking methods on nullSlide 41ObjectEditor Display of NullHow to initialize object variable?Initialization of Object VariablesInteractive Vs Programmed InstantiationProgrammed InstantiationALoanPairgetTotalLoan()Programmer-Defined Add AlgorithmProgrammer-Defined AddReturning AnotherLoan()Combining Object Creation and InitializationAdding Constructor in ALoanConstructor Vs Regular MethodInstantiation Requires ParametersConstructorMulti-Parameter ConstructorDefault ConstructorReal-World AnalogyO-O WordClass MethodsSlide 62External Call of Class MethodnumInstances() Algorithmreturning numLoansIncrementing getNumLoans (edit)Incrementing getNumLoans (edited)Incrementing getNumLoans (soln)Declaring numInstancesSlide 70Slide 71Instance Vs Class MembersScope of Class and Instance MembersLegal & Illegal AccessesInstance Vs Class Named ConstantSlide 76Class Vs Instance ConstantClass Vs Instance MethodsClass Vs Instance MethodClass Vs Instance Constant/MethodPolymorphic MethodsNon Polymorphic MethodsOverloading Vs PolymprphismPrimitive Vs Object TypesStructure Vs Atomic TypesSlide 86Slide 87Slide 88Physical Vs. Logical StructureLoan Pair InterfaceSlide 91Slide 92Programmer-Defined Types•Object Types as Programmer-defined Types•Two-way Dependencies•Representation Errors•Primitive Vs Object Properties•Constructors•Class variables/methods•Top-Down, Bottom-up, Middle-out ProgrammingLoan ObjectProperties Classificationpublic class ABMISpreadsheet {double height;public double getHeight() {return height;}public void setHeight(double newHeight) {height = newHeight;}double weight;public double getWeight() {return weight;}public void setWeight(double newWeight) {weight = newWeight;}public double getBMI() {return weight/(height*height);}}HeightWeightBMIEditableEditableRead-onlyIndependentIndependentDependentRead-OnlyRead-Only Vs Editable, Dependent Vs IndependentEditableDependent1-Way Vs. 2-Way DependenciesBMIHeightWeightPrincipleMonthly InterestYearly InterestTop-Down ProgrammingInterfaceRepresentationAlgorithmClassBottom-up Programming in BMIInterfaceClassLoan ObjectLoan Interfacepublic interface Loan {public int getPrincipal(); public void setPrincipal(int newValue);public int getYearlyInterest(); public void setYearlyInterest(int newVal); public int getMonthlyInterest(); public void setMonthlyInterest(int newVal); }A Loan RepresentationsetYearlyInterest()setMonthlyInterest()getYearlyinterest()setPrincipal() getPrincipal()getMonthlyInterest()writereaddouble principalStored Vs ComputedEditableDependentStoredComputedLoan AlgorithmsetYearlyInterest()setMonthlyInterest()getYearlyinterest()setPrincipal() getPrincipal()getMonthlyInterest()writereadF1-1F2-1F1F2int principalSetting and Getting Stored PropertysetPrincipal() getPrincipal() public void setPrincipal(int newVal) {principal = newVal;}public int getPrincipal(){ return principal; }int principalSetting and Getting Stored PropertysetPrincipal() getPrincipal() public void setPrincipal(int newVal) {principal = newVal;}public int getPrincipal(){ return principal; }int principalGetting and Setting Computed Property (edit)setYearlyInterest()getYearlyinterest()writereadF1-1F1public int getYearlyInterest() { return principal* INTEREST_RATE/100; } public void setYearlyInterest(int newVal) { ????}int principalGetting and Setting Computed Property (edited)setYearlyInterest()getYearlyinterest()writereadF1-1F1public int getYearlyInterest() { return principal* INTEREST_RATE/100; } public void setYearlyInterest(int newVal) { principal = newVal/INTEREST_RATE*100;}int principalGetting and Setting Computed Property(soln)setYearlyInterest()getYearlyinterest()writereadF1-1F1public int getYearlyInterest() { return principal* INTEREST_RATE/100; } public void setYearlyInterest(int newVal) { principal = newVal*100/INTEREST_RATE;}int principalGetting and Setting Computed Property (edit)setMonthlyInterest()getMonthlyInterest()F2-1F2public int getMonthlyInterest() { ??? } public void setMonthlyInterest(int newVal) { ???}int principalGetting and Setting Computed Property (edited)setMonthlyInterest()getMonthlyInterest()F2-1F2public int getMonthlyInterest() { return getYearlyInterest()/12; } public void setMonthlyInterest(int newVal) { setYearlyInterest (newVal*12);}int principalGetting and Setting Computed Property(soln)setMonthlyInterest()getMonthlyInterest()F2-1F2public int getMonthlyInterest() { return getYearlyInterest()/12; } public void setMonthlyInterest(int newVal) { principal = setYearlyInterest(newVal*12);}int principalModified Loan Interfacepublic interface Loan {public final int INTEREST_RATE = 6;public int getPrincipal(); public void setPrincipal(int newValue);public int getYearlyInterest(); public void setYearlyInterest(int newVal); public int getMonthlyInterest(); public void setMonthlyInterest(int newVal); }Middle-Out ProgrammingInterfaceRepresentationAlgorithmClassAnother Loan Representationint yearlyInterestsetYearlyInterest()setMonthlyInterest()getYearlyinterest()setPrincipal() getPrincipal()getMonthlyInterest()writereadConversion Errors with Principal Repn.No Conversion Errors with YearlyInterest Repn.Car LoanHouse LoanTotal LoanPrincipalYearly InterestMonthly InterestLoan PairCar Loan Yearly InterestCar Loan Monthly InterestHouse Loan PrincipalCar Loan Principal...Primitive Vs. Object PropertiesLoan PairCar Loan PrincipalCar Loan Yearly InterestCar Loan Monthly InterestHouse Loan Principal...Loan PairCar LoanHouse LoanTotal LoanPrimitive PropertiesObject PropertiesReusing Loan!Loan Pair Interface (edit)public


View Full Document

UNC-Chapel Hill COMP 14 - Programmer-Defined Types

Download Programmer-Defined Types
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 Programmer-Defined Types 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 Programmer-Defined Types 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?