For Wednesday No new reading Complete WebCT quiz.

Slides:



Advertisements
Similar presentations
Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view class.
Advertisements

1 User-Defined Classes The String class is a pre-defined class that is provided by the Java Designer. Sometimes programmers would like to create their.
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
***** SWTJC STEM ***** Chapter 4-1 cg 42 Object Oriented Program Terms Up until now we have focused on application programs written in procedural oriented.
1 Classes, Encapsulation, Methods and Constructors (Continued) Class definitions Instance data Encapsulation and Java modifiers Method declaration and.
Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 Association relationship We’ve seen one implementation of “knows a”: public class Dog.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Reminder Check the course web site on a regular basis:
CS 106 Introduction to Computer Science I 03 / 21 / 2008 Instructor: Michael Eckmann.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Four: Defining Your Own Classes *Instantiable.
Object Oriented Programming.  OOP Basic Principles  C++ Classes  September 2004  John Edgar 22.
ECE122 L6: Problem Definition and Implementation February 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Classes with multiple methods Part 1. Review of classes & objects Early on, we learned that objects are the basic working units in object-oriented programs.
29-Jun-15 Using Objects. 2 Classes and objects The type of an object is the class that describes that object If we say int count, the type of count is.
Object-Oriented Application Development Using VB.NET 1 Chapter 7 Adding Responsibilities to Problem Domain Classes.
CS 106 Introduction to Computer Science I 03 / 17 / 2008 Instructor: Michael Eckmann.
More C++ Bryce Boe 2013/07/18 CS24, Summer 2013 C.
Object Oriented Software Development
Java Chapter 2 Creating Classes. Class Defines structure of an object or set of objects; Includes variables (data) and methods (actions) which determine.
Writing Classes (Chapter 4)
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
CSC 212 – Data Structures Lecture 12: Java Review.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
1 Introduction Modules  Most computer programs solve much larger problem than the examples in last sessions.  The problem is more manageable and easy.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 3: Developing Class Methods Object-Oriented Program Development Using Java: A Class-Centered Approach.
Creating Classes and Objects Chapter Microsoft Visual Basic.NET: Reloaded 1.
Chapter 4 -2 part Writing Classes 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All.
Chapter Eleven Classes and Objects Programming with Microsoft Visual Basic th Edition.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
1 Chapter Four Creating and Using Classes. 2 Objectives Learn about class concepts How to create a class from which objects can be instantiated Learn.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
02/14/2005 Introduction to Programming with Java, for Beginners Midterm 1 Review.
2 Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Chapter 3: Developing Class Methods Object-Oriented Program Development Using Java: A Class-Centered Approach.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 27 I Love this Class.
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
Week 12 - Monday.  What did we talk about last time?  Defining classes  Class practice  Lab 11.
CS 106 Introduction to Computer Science I 03 / 22 / 2010 Instructor: Michael Eckmann.
Non-Static Classes What is the Object of this lecture?
For Wednesday No reading No homework. Exam 1 Wednesday night STV pm Sign up if you need to take a make-up (after clearing it with me)
Dale Roberts Object Oriented Programming using Java - Getters and Setters Dale Roberts, Lecturer Computer Science, IUPUI
For Friday Read No quiz Program 6 due. Program 6 Any questions?
Outline Anatomy of a Class Encapsulation Anatomy of a Method Copyright © 2014 Pearson Education, Inc.
Ch 4-3 Piecewise and Stepwise Functions C.N.Colon ALGEBRA-HP SBHS.
Class Definitions and Writing Methods Chapter 3 3/31/16 & 4/4/16.
Class Definitions and Writing Methods Chapter 3 10/12/15 & 10/13/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education.
Class Definitions: The Fundamentals Chapter 6 3/30/15 & 4/2/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 26, 2009.
9.1 CLASS (STATIC) VARIABLES AND METHODS Defining classes is only one aspect of object-oriented programming. The real power of object-oriented programming.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Java Programming: Guided Learning with Early Objects
More About Objects and Methods
Creating Your OwnClasses
Agenda Warmup Lesson 2.5 (Ascii, Method Overloading)
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Chapter 4: Writing classes
Unit-1 Introduction to Java
Classes, Encapsulation, Methods and Constructors (Continued)
More on Classes and Objects
Which best describes the relationship between classes and objects?
PreAP Computer Science Quiz Key
Classes and Objects CGS3416 Spring 2019.
Presentation transcript:

For Wednesday No new reading Complete WebCT quiz

Program 4 Any questions?

Write a method to compute the sum of all integers between first and second (including first and second), where first and second are integers and first <= second. The method should return the sum. You may not change the value of either first or second.

Write a method to find the smaller of two integers. The method will accept two integers and return the smaller of the two. If they are the same, then the method returns either one of them.

Telephone company rules to calculate the cost of a long distance call are as follows. –If the cost of the call is over 60 minutes, the cost is 7 cents per minute. –If the call is over 20 minutes long, the cost is 10 cents per minute. –If the call is 20 minutes or less, the cost is 13 cents per minute. Write a method that takes the length of a call in minutes and returns the per minute rate for that call.

A carpenter computes the price of a desk as follows: –The charge for all desks is a minimum of $200 –If the surface (length * width) is over 750 square inches, add $50 –If the wood code is 1 (mahogany), add $100. If the wood code is 2, add $75. If the wood code is 3 (pine), there is no extra charge. Write a method that takes the surface of a desk and the wood code and returns the cost of the desk.

A company gives bonuses based on production as follows: –1000 units or fewer, the bonus is $25 –1001 to 3000 units, the bonus is $50 –3001 to 6000 units, the bonus is $100 –6001 units and up, the bonus is $200 Write a method that accepts the number of units produced and determines the bonus for the employee. Return the bonus.

Write a method to determine the purchaser’s discount based on a code. –If the code is 7, the discount is 10%. –If the code is 3, the discount is 15%. –If the code is 12, the discount is 4%. –If the code is 1, there is no discount. –If the code is 8, the discount is 30%. The method should return the discount. Use a switch statement.

Instance Variables Used to keep track of the information about an object Defined in the class Each object has its own instance variables The instance variables are accessible in all of the class’s methods The instance variables’ lifetimes are the same as the object’s lifetime

Example: Simplified Robot SimpleBots can be displayed in a SimpleCity. Attributes describe information about the robot. Methods use those attributes.

Declaring Instance Variable Three major pieces –An access modifier (almost ALWAYS private) –A type specifying the kind of data –A descriptive name May also provide an initial value for the instance variable here – often done in the constructor

Using Instance Variables Somewhat similar to temporary variables. In this case, the paint method would use the street and avenue to figure out where to paint the robot.

Handling Direction Named constants

Accessor Methods Also called getters. Used to find out the value of a particular instance variable (attribute) Often, but not always, desirable

Mutator Methods Also called setters Used to directly modify the value of an instance variable. Sometimes appropriate, but sometimes not. Only provide appropriate setters.

Managing Data in Java Instance variables Temporary variables Parameters Constants

A Harvester That Counts