Practice problem on defining and using Class types. Part 4.
|
|
- Loreen Blake
- 6 years ago
- Views:
Transcription
1 CS180 Programming Fundamentals Practice problem on defining and using Class types. Part 4. Implementing object associations: Applications typically consist of collections of objects of different related classes, working together. Given class Employee and BankAccount, implement direct deposit as a form of payment to their employees. (The account owner may not be the same person as the employee) CLASS Employee String name double payrate double unpaidhours getname() getpayrate() giveraise(double percent) setpayrate(double newrate) getunpaidhours() incrementhoursby(int hrs) DirectDeposit to CLASS BankAccount String owner String id double balance static int numaccounts getid() getbalance() deposit(double amt ) withdrawal(double amt ) We already have the separate class definitions for class Employee and BankAccount To implement direct deposit feature, perform the following using the Employee and Bank Account class specifications: a) Add a field of type BankAccount to each Employee object. b) Add a new constructor to allow for specification of direct deposit account as well as the name and pay rate of an employee. c) Add accessor and mutator methods for the direct deposit instance variable. d) Add instance method pay to Employee class, which should work as follows: Calculate the amount due to employee for unpaidhours. In case employee does not have the direct deposit account specified on record (i.e. the value of the appropriate instance var is null), print a check for the specified amount. Otherwise, if direct deposit account field is not null, deposit the amount due to the employee on their direct deposit account (Hint: use instance method deposit of the BankAccount class). Reset the number of unpaidhours to 0. e) *** update Employee class to keep track the percentage of all Employee objects that have direct deposit accounts. f) *** update Employee class so that no employee rate is below the minimum pay rate.
2
3 /** Class that represents an employee with name, hourly pay rate, unpaid hours */ public class Employee { // instance variables private String name; private double payrate; private int unpaidhours; private static DecimalFormat MONEY = new DecimalFormat("#,##0.00"); // Constructor public Employee (String name, double hourlyrate){ this.setname(name); this.payrate = hourlyrate; public void setunpaidhours(int unpaidhours) { this.unpaidhours = unpaidhours; public String tostring() { String result = this.getname() + " is paid " + MONEY.format(this.getRate()) + " per hour. " + " Unpaid hours: " + this.getunpaidhours(); return result; public String getname (){ return this.name; public double getrate (){ return this.payrate; public int getunpaidhours() {return this.unpaidhours; // mutators /** setname - method that sets value of instance var name * to a String that is passed in as a parameter */ public void setname (String name){ this.name = name; /** Mutator that increments the number of hours worked * Returns the updated value of unpaidhours */ public int incrementhoursby( int addidionalhours){ this.unpaidhours += addidionalhours; return this.unpaidhours; /** Mutator that assigns the pay rate to rate * passed as parameter */ public void setpayrate ( double rate){ if (rate < 0){ System.out.println("Pay rate cannot be below $" + 0); else this.payrate = rate;
4 /** public void giveraise (double percent){ * increases the pay rate by specified percent value */ public void giveraise (double percent){ double newrate = 0; // this is a local variable newrate = this.payrate *(percent +1); // set the calling object's rate to newrate this.payrate = newrate;
5 /** Class developed for the in-class practice from Handout 9 */ public class BankAccount { private String owner; private double balance; private String id; private static int countaccounts = 0; // how many accounts were created so far public static final DecimalFormat ACC_FORMAT = new DecimalFormat("00000"); public BankAccount (String accountholder){ this(accountholder, 0); // call the 2-arg constructor // to set the balance to 0 // this() refers to a constructor // Constructor which creates an account with the specified (b) initial deposit public BankAccount (String accountholder, double b){ this.owner = accountholder; this.balance = b; countaccounts++; this.id = ACC_FORMAT.format( countaccounts); // method tostring() public String tostring(){ return "id = " + this.id + " owner "+ this.owner + " has $" +this.balance; public String getowner() { return this.owner; public double getbalance() {return this.balance; /** Method deposit(double adeposit) * adds adeposit to the calling object's balance as long as adeposit is nonnegative. Otherwise leaves balance unchanged. Returns the updated balance.*/ public double deposit (double adeposit){ if (adeposit >=0) this.balance = this.balance + adeposit; return this.balance; /** Method withdrawal(double amt) * If amt is positive and if the calling object's balance is sufficient * to cover the amt, reduce the balance of calling * object by amt. Return true. Otherwise, return false. */ public boolean withdrawal (double amt) { boolean check= true; // will store return value if (amt < this.balance && amt > 0) this.balance = this.balance - amt; else check = false; return check;
Handout 8 Classes and Objects Continued: Static Variables and Constants.
Handout 8 CS603 Object-Oriented Programming Fall 16 Page 1 of 8 Handout 8 Classes and Objects Continued: Static Variables and Constants. 1. Static variable Declared with keyword static One per class (instead
More informationpublic class Account { private int id; private static int nextaccountid = 0; private String name; private double balance;
public class Account { private int id; private static int nextaccountid = 0; private String name; private double balance; public double deposit(double amount) { public double withdraw(double amount) {
More informationCSE115 Introduction to Computer Science I Coding Exercise #7 Retrospective Fall 2017
This week the main activity was a quiz activity, with a structure similar to our Friday lecture activities. The retrospective for the quiz is in Quiz-07- retrospective.pdf This retrospective explores the
More informationEncapsulation. Mason Vail Boise State University Computer Science
Encapsulation Mason Vail Boise State University Computer Science Pillars of Object-Oriented Programming Encapsulation Inheritance Polymorphism Abstraction (sometimes) Object Identity Data (variables) make
More informationBankAccount account1 = new BankAccount(...);,this
1 6 ',, : (.new ) BankAccount account1 = new BankAccount(...); פ, פ,this,, ) \ פ\( פ פ פ 2 ) ( " פ : :? public class BankAccount {... private double balance;... 3 :),, ( 3 )queries, accessors( ), ( :)observers(
More informationLecture 07: Object Encapsulation & References AITI Nigeria Summer 2012 University of Lagos.
Accelerating Information Technology Innovation http://aiti.mit.edu Lecture 07: Object Encapsulation & References AITI Nigeria Summer 2012 University of Lagos. Data Field Encapsulation Sometimes we want
More informationCS 209 Sec. 52 Spring, 2006 Lab 5: Classes Instructor: J.G. Neal
CS 209 Sec. 52 Spring, 2006 Lab 5: Classes Instructor: J.G. Neal Objectives. To gain experience with: 1. The definition and use of a class to represent a real-world type of entity (an employee). 2. Adding
More informationReview of Object-Oriented Concepts in JAVA
Review of Object-Oriented Concepts in JAVA Object-Oriented Concepts supported by JAVA. Advantages of Object-Orientation. Inheritance. Abstract Classes. Interfaces. Review Questions. Object-Oriented Concepts
More informationpublic void creditaccount(string accountnumber, float amount) { this.accounts.get(accountnumber).credit(amount); }
package bank; //... public class Bank { private Map accounts; public Bank() { this.accounts = new HashMap(); public void addaccount(bankaccount account) { this.accounts.put(account.getnumber(),
More informationNotes on Chapter Three
Notes on Chapter Three Methods 1. A Method is a named block of code that can be executed by using the method name. When the code in the method has completed it will return to the place it was called in
More informationBuilding Java Programs
Building Java Programs Chapter 15 Lecture 15-1: Implementing ArrayIntList reading: 15.1-15.3 Recall: classes and objects class: A program entity that represents: A complete program or module, or A template
More informationSWC test question #01. Using objects part I
SWC test question #01 Using objects part I Using objects part I Give a presentation of the concept objects, and how you use objects You could describe Types Variables Variable definitions The assignment
More informationGetter and Setter Methods
Example 1 namespace ConsoleApplication14 public class Student public int ID; public string Name; public int Passmark = 50; class Program static void Main(string[] args) Student c1 = new Student(); Console.WriteLine("please..enter
More information$ % $ % BankAccount. public class BankAccount {... private??? balance; } "commands, transformers, mutators! "abstract state! "queries, accessors!
"! public class { private??? balance; "! # "! "commands, transformers, mutators! "abstract state! "queries, accessors! "constructors! & "! public class { private double balance; "! void "this! x.command1();
More informationENGR 2710U Midterm Exam UOIT SOLUTION SHEET
SOLUTION SHEET ENGR 2710U: Object Oriented Programming & Design Midterm Exam October 19, 2012, Duration: 80 Minutes (9 Pages, 14 questions, 100 Marks) Instructor: Dr. Kamran Sartipi Name: Student Number:
More informationCOMP-202 Unit 8: Defining Your Own Classes. CONTENTS: Class Definitions Attributes Methods and Constructors Access Modifiers and Encapsulation
COMP-202 Unit 8: Defining Your Own Classes CONTENTS: Class Definitions Attributes Methods and Constructors Access Modifiers and Encapsulation Defining Our Own Classes (1) So far, we have been creating
More informationObject-oriented basics. Object Class vs object Inheritance Overloading Interface
Object-oriented basics Object Class vs object Inheritance Overloading Interface 1 The object concept Object Encapsulation abstraction Entity with state and behaviour state -> variables behaviour -> methods
More informationQuarter 1 Practice Exam
University of Chicago Laboratory Schools Advanced Placement Computer Science Quarter 1 Practice Exam Baker Franke 2005 APCS - 12/10/08 :: 1 of 8 1.) (10 percent) Write a segment of code that will produce
More informationFall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.
Grading Page 1 / 4 Page3 / 20 Page 4 / 13 Page 5 / 10 Page 6 / 26 Page 7 / 17 Page 8 / 10 Total / 100 1. (4 points) What is your course section? CS 101 CS 101E Pledged Page 1 of 8 Pledged The following
More informationCS 1302 Chapter 9 (Review) Object & Classes
CS 1302 Chapter 9 (Review) Object & Classes Reference Sections 9.2-9.5, 9.7-9.14 9.2 Defining Classes for Objects 1. A class is a blueprint (or template) for creating objects. A class defines the state
More informationProblem Grade Total
CS 101, Prof. Loftin: Final Exam, May 11, 2009 Name: All your work should be done on the pages provided. Scratch paper is available, but you should present everything which is to be graded on the pages
More informationRunning the program (the model) simulates what would
CSE 143 Programming as Modeling Reading: Ch. 1-6 Building Virtual Worlds Much of programming can be viewed as building a model of a real or imaginary world in the computer a banking program models real
More informationHandout 9 OO Inheritance.
Handout 9 CS603 Object-Oriented Programming Fall 2016 Page 1 of 11 Handout 9 OO Inheritance. All classes in Java form a hierarchy. The top of the hierarchy is class Object Example: classicalarchives.com
More informationCSE 413 Winter 2001 Midterm Exam
Name ID # Score 1 2 3 4 5 6 7 8 There are 8 questions worth a total of 75 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. You may refer to
More informationName: Checked: Objectives: Practice creating classes and methods, and using them in your programs.
Lab 8 Name: Checked: Objectives: Practice creating classes and methods, and using them in your programs. Preparation A: Exercise using the Die class Create a subfolder Dice for your files in this exercise.
More informationLecture 7 Objects and Classes
Lecture 7 Objects and Classes An Introduction to Data Abstraction MIT AITI June 13th, 2005 1 What do we know so far? Primitives: int, double, boolean, String* Variables: Stores values of one type. Arrays:
More informationFile: D:\My Documents\Classes\Computer Science\Class Notes\Fall New\Polymorphism\Employee.java 7/20/1999, 10:53:52 AM
File: D:\My Documents\Classes\Computer Science\Class Notes\Fall New\Polymorphism\Employee.java 7/20/1999, 10:53:52 AM Employee.java Author: Lewis and Loftus Represents a general paid employee. class Employee
More informationName: Checked: Objectives: Practice creating classes and methods, and using them in your programs.
Lab 8 Name: Checked: Objectives: Practice creating classes and methods, and using them in your programs. Preparation: Exercise using the Account class We will be modifying the code of the Transactions
More informationEduardo M. Breijo Baullosa May 2, Assignment 17. Report
Eduardo M. Breijo Baullosa May 2, 2012 Cesar I. Cruz ICOM4015 Assignment 17 Report The Automated teller machine is a computer that allows the interaction between bank account information and its respective
More informationName: Checked: Objectives: Practice creating classes and methods, and using them in your programs.
Lab 8 Name: Checked: Objectives: Practice creating classes and methods, and using them in your programs. Preparation, Part A: Exercise using the Die class For this exercise we will be modifying an example
More informationCS 617 Object Oriented Systems Lecture 5 Classes, Classless World:Prototypes, Instance Variables, Class Variables, This/Self 3:30-5:00 pm Thu, Jan 17
Objects, Interfaces and CS 617 Object Oriented Systems Lecture 5, Classless World:Prototypes, Instance Variables, Class Variables, This/Self 3:30-5:00 pm Thu, Jan 17 Rushikesh K Joshi Department of Computer
More informationWrite code to represent
Arrays: Day 3 Objectives Understand how to use the for-each loop Understand when it is appropriate to use a for loop as opposed to a for-each loop. Practice with arrays Understand the difference between
More informationLecture 20: Implementation () / 33
Lecture 20: Implementation 15.07.2013 () 15.07.2013 1 / 33 Contents Implementation Implementation Principles Example: Eight Queens by Refinement () 15.07.2013 2 / 33 Implementation Input: software architecture,
More informationIntro to Computer Science 2. Inheritance
Intro to Computer Science 2 Inheritance Admin Questions? Quizzes Midterm Exam Announcement Inheritance Inheritance Specializing a class Inheritance Just as In science we have inheritance and specialization
More informationObjects and Classes. Lecture 10 of TDA 540 (Objektorienterad Programmering) Chalmers University of Technology Gothenburg University Fall 2017
Objects and Classes Lecture 10 of TDA 540 (Objektorienterad Programmering) Carlo A. Furia Alex Gerdes Chalmers University of Technology Gothenburg University Fall 2017 All labs have been published Descriptions
More informationCMSC 202. Exceptions
CMSC 202 Exceptions Error Handling In the ideal world, all errors would occur when your code is compiled. That won t happen. Errors which occur when your code is running must be handled by some mechanism
More informationEXAM Computer Science 1 Part 1
Maastricht University Faculty of Humanities and Science Department of Knowledge Engineering EXAM Computer Science 1 Part 1 Block 1.1: Computer Science 1 Code: KEN1120 Examiner: Kurt Driessens Date: Januari
More informationObject oriented programming
Exercises 7 Version 1.0, 11 April, 2017 Table of Contents 1. Inheritance.................................................................. 1 1.1. Tennis Player...........................................................
More informationClasses and Methods: Classes
Class declaration Syntax: [] Classes and Methods: Classes [] class [] [] [] When
More informationGROUP - A <10 questions x 4 points each = 40 points >
GROUP - A For each question, write in the box the output of the shown fragment. If you believe the fragment will not produce output due to errors, write the
More informationProblem 1 Short Answers Why use the reserved words new or delete? Why use dynamic memory allocation?
Problem 1 Short Answers Why use the reserved words new or delete? Why use dynamic memory allocation? What is a pointer? What is a reference variable? When would you use pointers over reference variables?
More informationProgramming a Bank Database. We ll store the information in two tables: INTEGER DECIMAL(10, 2)
WE1 W o r k e d E x a m p l e 2 2.1 Programming a Bank Database In this Worked Example, we will develop a complete database program. We will reimplement the ATM simulation of Chapter 12, storing the customer
More informationCS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:
CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : In mathematics,
More informationImplementation. (Mapping to Java) Jörg Kienzle & Alfred Strohmeier. COMP-533 Implementation
Implementation (Mapping to Java) Jörg Kienzle & Alfred Strohmeier COMP-533 Implementation Datatype Enumeration Class Attribute Association Inheritance Method Visibility Collections Overview 2 Data Type
More informationDomain-Driven Design Activity
Domain-Driven Design Activity SWEN-261 Introduction to Software Engineering Department of Software Engineering Rochester Institute of Technology Entities and Value Objects are special types of objects
More informationLecture 06: Classes and Objects
Accelerating Information Technology Innovation http://aiti.mit.edu Lecture 06: Classes and Objects AITI Nigeria Summer 2012 University of Lagos. What do we know so far? Primitives: int, float, double,
More informationPASS4TEST IT 인증시험덤프전문사이트
PASS4TEST IT 인증시험덤프전문사이트 http://www.pass4test.net 일년동안무료업데이트 Exam : 1z0-809 Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z0-809 Exam's Question and Answers 1 from
More informationIntroduction to Inheritance
Introduction to Inheritance James Brucker These slides cover only the basics of inheritance. What is Inheritance? One class incorporates all the attributes and behavior from another class -- it inherits
More informationIT 313 Advanced Application Development
Page 1 of 7 IT 313 Advanced Application Development Practice Midterm Exam Part A. Multiple Choice Questions. Answer all questions. Optional: supply a reason or show work for partial credit in case you
More informationName. CPTR246 Spring '17 (100 total points) Exam 2
Name CPTR246 Spring '17 (100 total points) Exam 2 1. Pointer parameters (the old C way) In the following program, make all of the changes to convert the call-by-reference parameters in the function computeoptions
More informationOBJECTS AND CLASSES CHAPTER. Final Draft 10/30/2011. Slides by Donald W. Smith TechNeTrain.com
CHAPTER 8 OBJECTS AND CLASSES Slides by Donald W. Smith TechNeTrain.com Final Draft 10/30/2011 Chapter Goals To understand the concepts of classes, objects and encapsulation To implement instance variables,
More informationCSIS 10A Practice Final Exam Name:
CSIS 10A Practice Final Exam Name: Multiple Choice: Each question is worth 2 points. Circle the letter of the best answer for the following questions. 1. For the following declarations: int area; String
More informationChapter 4 Defining Classes I
Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the
More informationMutating Object State and Implementing Equality
Mutating Object State and Implementing Equality 6.1 Mutating Object State Goals Today we touch the void... (sounds creepy right... see the movie, or read the book, to understand how scary the void can
More informationCSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University
Last Class CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in this
More informationChapter 5: Arrays. Chapter 5. Arrays. Java Programming FROM THE BEGINNING. Copyright 2000 W. W. Norton & Company. All rights reserved.
Chapter 5 Arrays 1 5.1 Creating and Using Arrays A collection of data items stored under a single name is known as a data structure. An object is one kind of data structure, because it can store multiple
More informationCSC 175 Intermediate Programming
CSC 175 Intermediate Programming Lecture 6 Inheritance Inheritance and Derived Classes Inheritance is the process by which a new class is created from another class. The new class is called the derived
More informationThis exam is open book. Each question is worth 3 points.
This exam is open book. Each question is worth 3 points. Page 1 / 15 Page 2 / 15 Page 3 / 12 Page 4 / 18 Page 5 / 15 Page 6 / 9 Page 7 / 12 Page 8 / 6 Total / 100 (maximum is 102) 1. Are you in CS101 or
More informationAP CS Unit 4: Classes and Objects Programs
AP CS Unit 4: Classes and Objects Programs 1. Copy the Bucket class. Make sure it compiles (but you won t be able to run it because it does not have a main method). public class Bucket { private double
More informationClass 09 Slides: Polymorphism Preconditions. Table of Contents. Postconditions
Class 09 Slides: Polymorphism Preconditions Students are familiar with inheritance and arrays. Students have worked with a poorly written program in A08 that could benefit from polymorphism. Students have
More informationWhat This Course Is About Design-by-Contract (DbC)
What This Course Is About Design-by-Contract (DbC) Readings: OOSC2 Chapter 11 EECS3311 A: Software Design Fall 2018 CHEN-WEI WANG Focus is design Architecture: (many) inter-related modules Specification:
More informationStoring Data in Objects
Storing Data in Objects Rob Miles Department of Computer Science 28d 08120 Programming 2 Objects and Items I have said for some time that you use objects to represent things in your problem Objects equate
More informationChapter 7. Inheritance
Chapter 7 Inheritance Introduction to Inheritance Inheritance is one of the main techniques of objectoriented programming (OOP) Using this technique, a very general form of a class is first defined and
More informationCatching Defects: Design or Implementation Phase? Design-by-Contract (Dbc) Test-Driven Development (TDD) Motivation of this Course
Design-by-Contract (Dbc) Test-Driven Development (TDD) Readings: OOSC2 Chapter 11 Catching Defects: Design or Implementation Phase? To minimize development costs, minimize software defects. The cost of
More informationInheritance Advanced Programming ICOM 4015 Lecture 11 Reading: Java Concepts Chapter 13
Inheritance Advanced Programming ICOM 4015 Lecture 11 Reading: Java Concepts Chapter 13 Fall 2006 Adapted from Java Concepts Companion Slides 1 Chapter Goals To learn about inheritance To understand how
More informationIntroduction to Objects. James Brucker
Introduction to Objects James Brucker What is an Object? An object is a program element that encapsulates both data and behavior. An object contains both data and methods that operate on the data. Objects
More informationName: CS 159 Practice Final Fall 2015
Name: CS 159 Practice Final Fall 2015 CS 159, Fall 2015 Final Exam Section 02 Page 2 of 17 1. Choose the best answer for each of the following multiple choice questions. (a) (2 points) What will happen
More informationCS112 Lecture: Defining Instantiable Classes
CS112 Lecture: Defining Instantiable Classes Last revised 2/3/05 Objectives: 1. To describe the process of defining an instantiable class 2. To discuss public and private visibility modifiers. Materials:
More informationCS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:
CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : In mathematics,
More informationSoftware Design and Analysis for Engineers
Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:
More informationImplementing Classes
Implementing Classes Advanced Programming ICOM 4015 Lecture 3 Reading: Java Concepts Chapter 3 Fall 2006 Slides adapted from Java Concepts companion slides 1 Chapter Goals To become familiar with the process
More informationGoals for Today. CSE1030 Introduction to Computer Science II. CSE1030 Lecture #9. Review is-a versus has-a. Lecture #9 Inheritance I
CSE1030 Introduction to Computer Science II Lecture #9 Inheritance I Goals for Today Today we start discussing Inheritance (continued next lecture too) This is an important fundamental feature of Object
More informationInstance Method Development Demo
Instance Method Development Demo Write a class Person with a constructor that accepts a name and an age as its argument. These values should be stored in the private attributes name and age. Then, write
More informationName: CS 159 Practice Final Fall 2015
Name: CS 159 Practice Final Fall 2015 CS 159, Fall 2015 Final Exam Section 02 Page 2 of 16 1. Choose the best answer for each of the following multiple choice questions. (a) (2 points) What will happen
More informationCSEN401 Computer Programming Lab. Topics: Introduction and Motivation Recap: Objects and Classes
CSEN401 Computer Programming Lab Topics: Introduction and Motivation Recap: Objects and Classes Prof. Dr. Slim Abdennadher 16.2.2014 c S. Abdennadher 1 Course Structure Lectures Presentation of topics
More informationCS 302: Introduction to Programming in Java. Lecture 15
CS 302: Introduction to Programming in Java Lecture 15 Class Instances of the class (objects) only valid at runtime Private Instance Methods Instance methods usually public why? If we have an internal
More informationImplementing Classes (P1 2006/2007)
Implementing Classes (P1 2006/2007) Fernando Brito e Abreu (fba@di.fct.unl.pt) Universidade Nova de Lisboa (http://www.unl.pt) QUASAR Research Group (http://ctp.di.fct.unl.pt/quasar) Chapter Goals To become
More informationOutline CSE 142. Specification vs Implementation - Review. CSE142 Wi03 F-1. Instance Variables
Outline CSE 142 Class Implementation in Java Implementing classes in Java Instance variables properties Value-returning methods for queries Void methods for commands Return statement Assignment statement
More information& Object-Oriented Programming (POOP) Modified from CS61A Summer 2012 Lecture at UC Berkeley
& Object-Oriented Programming (POOP) Modified from CS61A Summer 2012 Lecture at UC Berkeley Where We Were: Functional Programming Style of programming One of many programming paradigms where functions
More informationSTUDENT LESSON A5 Designing and Using Classes
STUDENT LESSON A5 Designing and Using Classes 1 STUDENT LESSON A5 Designing and Using Classes INTRODUCTION: This lesson discusses how to design your own classes. This can be the most challenging part of
More informationPractice Midterm Examination
Steve Cooper Handout #28 CS106A May 1, 2013 Practice Midterm Examination Midterm Time: Tuesday, May 7, 7:00P.M. 9:00P.M. Portions of this handout by Eric Roberts and Patrick Young This handout is intended
More informationObjec,ves. Review: Object-Oriented Programming. Object-oriented programming in Java. What is OO programming? Benefits?
Objec,ves Object-oriented programming in Java Ø Encapsula,on Ø Access modifiers Ø Using others classes Ø Defining own classes Sept 16, 2016 Sprenkle - CSCI209 1 Review: Object-Oriented Programming What
More informationSoftware and Programming I. Classes and Arrays. Roman Kontchakov / Carsten Fuhs. Birkbeck, University of London
Software and Programming I Classes and Arrays Roman Kontchakov / Carsten Fuhs Birkbeck, University of London Outline Class Object Interfaces Arrays Sections 9.5 9.6 Common Array Algorithms Sections 6.1
More informationUNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED
UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED EXERCISE 11.1 1. static public final int DEFAULT_NUM_SCORES = 3; 2. Java allocates a separate set of memory cells in each instance
More informationCS 101 Fall 2006 Midterm 3 Name: ID:
You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure
More informationUnderstanding class definitions
Objects First With Java A Practical Introduction Using BlueJ Understanding class definitions Looking inside classes 2.1 Looking inside classes basic elements of class definitions fields constructors methods
More informationDesign-by-Contract (Dbc) Test-Driven Development (TDD)
Design-by-Contract (Dbc) Test-Driven Development (TDD) Readings: OOSC2 Chapter 11 EECS3311: Software Design Fall 2017 CHEN-WEI WANG Terminology: Contract, Client, Supplier A supplier implements/provides
More informationBinghamton University. CS-140 Fall Problem Solving. Creating a class from scratch
Problem Solving Creating a class from scratch 1 Recipe for Writing a Class 1. Write the class boilerplate stuff 2. Declare Fields 3. Write Creator(s) 4. Write accessor methods 5. Write mutator methods
More informationREVIEW EXERCISES. Draw an inheritance diagram that shows the relationships between these classes.
Review Exercises 367 11. A derived-class pointer can be converted to a base-class pointer. 12. When a virtual function is called, the version belonging to the actual type of the implicit parameter is invoked.
More informationChapter 2a Class Relationships
Data Structures for Java William H. Ford William R. Topp Chapter 2a Class Relationships Bret Ford 2005, Prentice Hall Wrapper Classes Convert a value of primitive type to an object. Supply methods to access
More informationToday s Agenda. Quick Review
Today s Agenda TA Information Homework 1, Due on 6/17 Quick Review Finish Objects and Classes Understanding class definitions 1 Quick Review What is OOP? How is OOP different from procedural programming?
More informationCS 302 Week 9. Jim Williams
CS 302 Week 9 Jim Williams This Week P2 Milestone 3 Lab: Instantiating Classes Lecture: Wrapper Classes More Objects (Instances) and Classes Next Week: Spring Break Will this work? Double d = new Double(10);
More informationImperative Languages!
Imperative Languages! Java is an imperative object-oriented language. What is the difference in the organisation of a program in a procedural and an objectoriented language? 30 class BankAccount { private
More informationTHE UNIVERSITY OF WESTERN AUSTRALIA. School of Computer Science & Software Engineering CITS1001 OBJECT-ORIENTED PROGRAMMING AND SOFTWARE ENGINEERING
THE UNIVERSITY OF WESTERN AUSTRALIA School of Computer Science & Software Engineering CITS1001 OBJECT-ORIENTED PROGRAMMING AND SOFTWARE ENGINEERING SAMPLE TEST APRIL 2012 This Paper Contains: 12 Pages
More informationInheritance (P1 2006/2007)
Inheritance (P1 2006/2007) Fernando Brito e Abreu (fba@di.fct.unl.pt) Universidade Nova de Lisboa (http://www.unl.pt) QUASAR Research Group (http://ctp.di.fct.unl.pt/quasar) Chapter Goals To learn about
More informationCMSC 341 Lecture 7 Lists
CMSC 341 Lecture 7 Lists Today s Topics Linked Lists vs Arrays Nodes Using Linked Lists Supporting Actors (member variables) Overview Creation Traversal Deletion UMBC CMSC 341 Lists 2 Linked Lists vs Arrays
More informationModule Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1
UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2015-16 PROGRAMMING 1 CMP-4008Y Time allowed: 2 hours Section A (Attempt all questions: 80 marks) Section B (Attempt one
More informationCS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class
CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount
More informationCS 101 Exam 2 Spring Id Name
CS 101 Exam 2 Spring 2005 Email Id Name This exam is open text book and closed notes. Different questions have different points associated with them. Because your goal is to maximize your number of points,
More informationCreating and Using Objects
Creating and Using Objects 1 Fill in the blanks Object behaviour is described by, and object state is described by. Fill in the blanks Object behaviour is described by methods, and object state is described
More information