Object-Oriented Programming and class Design

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Object-Oriented Programming. Agenda Classes & Objects Attributes Methods Objects in memory Visibility Properties (get & set) Constructors.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
 Setter methods ◦ public methods that set the value of instance variables to a value specified by the call to the argument ◦ Setter methods do not violate.
Liang Chapter 6 Variable scope and the keyword this.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Introduction to Objects A way to create our own types.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
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!
© A+ Computer Science - public Triangle() { setSides(0,0,0); } Constructors are similar to methods. Constructors set the properties.
CSE 1301 Lecture 5 Writing Classes Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Objects and Classes Mostafa Abdallah
CSE 1301 Lecture 6 Writing Classes Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Static. 2 Objectives Introduce static keyword –examine syntax –describe common uses.
Introduction to Objects What is a constructor? Use type to create a variable Use class to create an object int x; Circle mycircle = new Circle ();
Bank Account Example public class BankAccount { private double balance; public static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++;
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
Packages. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L13: Layout Managers Slide 2.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Classes and Objects (contd.) Course Lecture Slides 19 May 2010.
Chapter 7 Objects and Classes. OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object represents an entity.
Class Everything in Java is in a class. The class has a constructor that creates the object. If you do not supply a constructor Java will create a default.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Unified Modeling Language
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Introduction to Programming using Java Day 3 and 4 Java Language Basics Review The “For” loop Subroutines The “String” class.
Chapter 7 Objects and Classes
Lecture 3: Introduction to Object and Classes
Introduction to Programming G50PRO University of Nottingham Unit 9 : Classes and objects Paul Tennent
Interface.
IST311 Advanced Issues in OOP: Inheritance and Polymorphism
IST311 Advanced Issues in OOP: Inheritance and Polymorphism
Lecture 14 Writing Classes part 2 Richard Gesick.
TK1114 Computer Programming
CS 302 Week 10 Jim Williams.
Lecture 13 Writing Classes Richard Gesick.
Classes & Objects: Examples
Chapter 8 Objects and Classes Part 1
Code Animation Examples
Chapter 8 Objects and Classes
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Objects and Classes Creating Objects and Object Reference Variables
Module 2 - Part 1 Variables, Assignment, and Data Types
Module 3 Selection Structures 4/3/2019 CSE 1321 Module 3.
Module 2 Variables, Assignment, and Data Types
Methods and Data Passing
CSE Module 1 A Programming Primer
JAVA An Introduction to Java OOP Basics
Introduction to Objects & Classes
CSE Module 1 A Programming Primer
Module 3 Selection Structures 4/5/2019 CSE 1321 Module 3.
Chapter 6 Objects and Classes
Object-Oriented Programming and class Design
Introduction to Classes and Objects
Chapter 8 Objects and Classes
Object-Oriented Programming
Chapter 9 Objects and Classes Part 01
OO Programming Concepts
Object-Oriented Programming and class Design
Object-Oriented Design AND CLASS PROPERTIES
Object-Oriented Programming and class Design
Object-Oriented Programming and class Design
Object-Oriented Design AND CLASS PROPERTIES
Chapter 7 Objects and Classes
Module 3 Selection Structures 12/7/2019 CSE 1321 Module 3.
Object-Oriented Design AND CLASS PROPERTIES
Presentation transcript:

Object-Oriented Programming and class Design Ps Module 6 Object-Oriented Programming and class Design 4/22/2019 CSE 1321 Module 5

Class Circle Pseudocode BEGIN CREATE Radius ← 1.0 CONSTRUCTOR Circle //called default constructor BEGIN END CONSTRUCTOR CONSTRUCTOR Circle (NewRadius) //called constructor Radius ← NewRadius END CONSTRUCTOR METHOD getArea () //compute and return circle area RETURN (Radius * Radius * 3.14159) END METHOD END CLASS Ps 4/26/2018 CSE 1321 Module 6 5

Class Circle public class Circle { double radius = 1.0; Circle() //default constructor { } Circle(double newRadius) //another constructor { radius = newRadius; } public double getArea() //calculates area { return (radius*radius*3.14159); } } 6 4/26/2018 CSE 1321 Module 6

Ps Driver in Pseudocode CLASS TestCircle BEGIN CREATE circle1, circle2 AS Circle // create two variables circle1 ← NEW circle() // create circle1 object circle2 ← NEW circle(25.0) // create circle2 object PRINT ("Circle 1 area = " + circle1.getArea()) PRINT ("Circle 2 area = " + circle2.getArea()) END TestCircle Outputs: Circle 1 area = 3.14159 Circle 2 area = 1963.4937499999999 Ps 4/26/2018 CSE 1321 Module 6 5

Driver in C# class Test_Circle { public static void Main (string args[]) { Circle c1 = new Circle(); Console.WriteLine("The area of the c1 is " + c1.getArea()); Circle c2 = new Circle(25); Console.WriteLine("The area of c2 is " + c2.getArea()); } } 4/26/2018 CSE 1321 Module 6 6

Example CLASS BMW_Z4 BEGIN CONSTRUCTOR BMW_Z4() // constructor #1 BEGIN ModelYear ← 2004 TopUp ← false LicensePlate ← "DEALER" END CONSTRUCTOR CONSTRUCTOR BMW_Z4(parameter: year) // constructor #2 BEGIN ModelYear ← year TopUp ← false LicensePlate ← "DEALER" END CONSTRUCTOR END CLASS Ps 4/22/2019 CSE 1321 Module 6 6

C# - Constructor Example class BMW_Z4 { int modelYear; string licensePlate; bool topUp; BMW_Z4 () { modelYear = 2004; topUp = false; licensePlate = "DEALER"; } BMW_Z4 (int year) modelYear = year; topUp = false; } 4/22/2019 CSE 1321 Module 6 7

Properties Example Pseudocode CLASS BMW_Z4 BEGIN PRIVATE ModelYear PRIVATE LicensePlate PUBLIC METHOD SetModelYear (Year) BEGIN ModelYear ← Year END PUBLIC METHOD GetModelYear () BEGIN RETURN ModelYear END PUBLIC METHOD SetLicensePlate (value) BEGIN LicensePlate ← value END PUBLIC METHOD GetLicensePlate () BEGIN RETURN LicensePlate END END CLASS Ps 4/26/2018 CSE 1321 Module 6 5

Class BMW_Z4 public class BMW_Z4 { private int modelYear; private string licensePlate; private bool topUp; public int ModelYear { get {return modelYear;} set {modelYear = value; }} public string SetLicensePlate { get {return licensePlate;} set{licensePlate = value;}} public bool TopUp { get {return TopUp;} set{topUp = value; }} } 7 4/26/2018 CSE 1321 Module 6