Lec 13 Writing an Instantiable Class II. Agenda Adding to our Balloon Class demo: – default Constructor method – inflate method that takes a parameter.

Slides:



Advertisements
Similar presentations
Section 6.1 CS 106, Fall The Big Q What do we get by being able to define a class?! Or Do we really need this?!
Advertisements

Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Objects, Variables & Methods Java encapsulates data and action modules that access the data in one container, called an object. Object members that.
OOP: Inheritance By: Lamiaa Said.
Lec 12 Writing an Instantiable Class. Agenda Review objects and classes Making our own class to create objects – Our first "Instantiable" class – with.
CS-1030 Dr. Mark L. Hornick 1 Constructors Copy Constructors.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
C++ data types. Structs vs. Classes C++ Classes.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of.
CS 106 Introduction to Computer Science I 03 / 17 / 2008 Instructor: Michael Eckmann.
Writing a Class (defining a data-type). Create a new project : Project (uncheck the “Create Main Class”)
UML Basics & Access Modifier
Chapter 3 Vector Class. Agenda Design and Implementation of Vector class – add, get, set remove, copy, equals, ensureCapacity Hangman using Vector class.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
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!
ECE122 Feb. 22, Any question on Vehicle sample code?
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
Lec 14 Writing an Instantiable Class III. Agenda Review of Instantiable Classes Scope of variables Using this to override scope issues Lab: Creating a.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 27 I Love this Class.
CS 139 Objects Based on a lecture by Dr. Farzana Rahman Assistant Professor Department of Computer Science.
Objects with Functions and Arrays. Objects can be Passed Class defines type – Can use as type of function or parameter.
Powerpoint slides from A+ Computer Science Modified by Mr. Smith for his course.
Constructors, Copy Constructors, constructor overloading, function overloading Lecture 04.
1 COMS 261 Computer Science I Title: Classes Date: November 4, 2005 Lecture Number: 27.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
An Introduction to Programming with C++ Fifth Edition Chapter 14 Classes and Objects.
Powerpoint slides from A+ Computer Science Modified by Mr. Smith for his course.
Lab 2. Prepare: 1.Create a folder named lab2 inside the workspace. 2.Download RecordDB.java and Record.java from the lab document. 3.Change the file name.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
OOP Details Constructors, copies, access. Initialize Fields are not initialized by default:
SCIENCE FAIR REQUIREMENTS To create a display for Science Board use this KEYNOTE template. NO COLOR IS ALLOWED here in this file (your fonts should.
More About Objects and Methods
Examples of Classes & Objects
Chapter 7- Inheritance.
Haidong Xue Summer 2011, at GSU
More About Objects and Methods
Road Map Introduction to object oriented programming. Classes
הצטרפות לקבוצת DeDemoc
This pointer, Dynamic memory allocation, Constructors and Destructor
Objects First with Java
CS Week 13 Jim Williams, PhD.
CS 302 Week 10 Jim Williams.
أهداف المحاضرة مراجعة المفاهيم والعلاقات الأساسية لتحليل العلاقة بين التكاليف والحجم والربح. بناء نموذج لتحليل التعادل في حالة وجود منتج وحيد. بناء نموذج.
Class Constructor Recall: we can give default values to instance variables of a class The “numberOfPlayers” variable from the “PlayerData” class before.
Comparing Objects Phil Tayco San Jose City College Slide version 1.1
CSC 113: Computer programming II
CS 200 More Classes Jim Williams, PhD.
Classes & Objects: Examples
ITunes Lab Copyright © 2012 Pearson Education, Inc.
Exam 1 Material Study Guide
CS 302 Week 9 Jim Williams.
Objects with Functions and Arrays
More About Objects and Methods
COMS 261 Computer Science I
Lec 13 Writing an Instantiable Class II
Which best describes the relationship between classes and objects?
JAVA CLASSES.
Java Programming with BlueJ Objectives
Chapter 11 Inheritance and Polymorphism
Classes CSC 265 (Blum).
Anatomy of a class Part II
Class: Special Topics Overloading (methods) Copy Constructors
Agenda About Homework for BPJ lesson 15 Overloading constructor
Classes and Objects CGS3416 Spring 2019.
Copy Constructor CSCE 121.
C++ data types.
Lec 10 Using Objects II.
Presentation transcript:

Lec 13 Writing an Instantiable Class II

Agenda Adding to our Balloon Class demo: – default Constructor method – inflate method that takes a parameter (amount) – pop method – volume method

Recall Structure of an Instantiable Class class Balloon size color Balloon inflate getSize getColor setColor pop Class Name Instance Varbls Methods Constructor method same name as class

Method Overloading We can add methods to Balloon with same names – as long as have different parameters – the Constructor we made in our Balloon class – A second "Default" constructor with no parameters

Which one is used? Balloon myBal = new Balloon(10,Color.RED); Balloon yrBal = new Balloon(); default constructor automatically – sets size to 0 – sets color to Color.WHITE

Now we'll begin BalloonDemo2 start with BalloonDemo from last time add default constructor add inflate method that takes an amount add pop method – modify both inflate methods add volume method – should return 0 if balloon has been popped

More Dairy.java make Lab13DairyFarm folder Copy, Dairy.java file from Lab12 folder, then add – default Constructor – addCow takes a number – calcMllkProfit takes a price/gallon – calcButterProfit takes a price/pound Create a new class Farm.java that – tests your new Dairy class by constructing a dairy farm, adding cows and printing the number of cows – And printing profit from selling milk or butter