Dale Roberts Object Oriented Programming using Java - Enumerations Dale Roberts, Lecturer Computer Science, IUPUI Department.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 3 More Syntax; Working with Objects.
Advertisements

Local Variables and Scope Benjamin Fein. Variable Scope A variable’s scope consists of all code blocks in which it is visible. A variable is considered.
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Type Checking Compiler Design Lecture (02/25/98) Computer Science Rensselaer Polytechnic.
Dale Roberts Object Oriented Programming using Java - Inheritance Overview Dale Roberts, Lecturer Computer Science, IUPUI
Dale Roberts Object Oriented Programming using Java - Inheritance Constructors Dale Roberts, Lecturer Computer Science, IUPUI
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
 2005 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look.
 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look - modified by Eileen Kraemer.
CSC 111 Course orientation
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Dale Roberts Object Oriented Programming using Java - Class Constructors Dale Roberts, Lecturer Computer Science, IUPUI Department.
Object Oriented Programming using Java - Polymorphism
Dale Roberts Procedural Programming using Java Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Dale Roberts Object Oriented Programming using Java - Packages Dale Roberts, Lecturer Computer Science, IUPUI Department.
Dale Roberts Introduction to Java - Access Specifiers Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Dale Roberts Program Control using Java - Boolean Expressions Dale Roberts, Lecturer Computer Science, IUPUI Department of.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 2.
 2005 Pearson Education, Inc. All rights reserved. 1 Methods Called functions or procedures in other languages Modularize programs by separating its tasks.
 2005 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look.
Dale Roberts 1 Classes Constructors & Destructors Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer.
 2005 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Dale Roberts GUI Programming using Java - Event Handling Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Dale Roberts GUI Programming using Java - Introduction Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Dale Roberts Program Control using Java - Selection Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
Dale Roberts GUI Programming using Java - GUI Components Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Dale Roberts Object Oriented Programming using Java - OOD to OOP: ATM Case Study Dale Roberts, Lecturer Computer Science, IUPUI
Dale Roberts Program Control using Java - Repetition Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look.
Dale Roberts Object Oriented Programming using Java - Final and Static Keywords Dale Roberts, Lecturer Computer Science, IUPUI
 2005 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look.
 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look.
1 Chapter 5: Defining Classes. 2 Basics of Classes An object is a member of a class type What is a class? Fields & Methods Types of variables: –Instance:
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
Methods.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Dale Roberts Introduction to Java - Input, Program Control and Instantiation Dale Roberts, Lecturer Computer Science, IUPUI
 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look.
Jozef Goetz Credits: Copyright  Pearson Education, Inc. All rights reserved. expanded by J. Goetz, 2016.
Part III © Copyright by Pearson Education, Inc. All Rights Reserved.
Dale Roberts Object Oriented Programming using Java - Getters and Setters Dale Roberts, Lecturer Computer Science, IUPUI
Dale Roberts Operator Overloading Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science,
Dale Roberts 1 Operator Overloading Member Functions Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Pointers Call-by-Reference.
Dale Roberts GUI Programming using Java - Windowing Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
GUI Programming using Java - Event Handling
Object Oriented Programming using Java - Composition
More About Objects and Methods
GUI Programming using Java - Key Events
More About Objects and Methods
Object Oriented Programming using Java - Class Instance Variables
Variable Declarations, Data types, Expressions
Variable Declarations, Data types, Expressions
Using local variable without initialization is an error.
Object Based Programming
More On Enumeration Types
Pointers Call-by-Reference CSCI 230
More About Objects and Methods
Dale Roberts, Lecturer IUPUI
Classes Class Data Members & Initializers
Programming II Vocabulary Review Loops & functions
Classes Member Qualifiers
Presentation transcript:

Dale Roberts Object Oriented Programming using Java - Enumerations Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School of Science, IUPUI

Dale Roberts 2 Enumerations enum types Declared with an enum declaration A comma-separated list of enum constants Declares an enum class with the following restrictions: enum types are implicitly final enum constants are implicitly static Attempting to create an object of an enum type with new is a compilation error enum constants can be used anywhere constants can enum constructor Like class constructors, can specify parameters and be overloaded

Dale Roberts 3Outline Book.java (1 of 2) Declare six enum constants Arguments to pass to the enum constructor Declare enum constructor Book Declare instance variables

Dale Roberts 4Outline Book.java (2 of 2)

Dale Roberts 5 Enumerations (Cont.) static method values Generated by the compiler for every enum Returns an array of the enum ’s constants in the order in which they were declared static method range of class EnumSet Takes two parameters, the first and last enum constants in the desired range Returns an EnumSet containing the constants in that range, inclusive An enhanced for statement can iterate over an EnumSet as it can over an array

Dale Roberts 6Outline EnumTest.ja va (1 of 2) Enhanced for loop iterates for each enum constant in the array returned by method value Enhanced for loop iterates for each enum constant in the EnumSet returned by method range

Dale Roberts 7Outline EnumTe st.java (2 of 2)

Dale Roberts 8 Common Programming Error 8.6 In an enum declaration, it is a syntax error to declare enum constants after the enum type’s constructors, fields and methods in the enum declaration.

Dale Roberts Acknowledgements Deitel, Java How to Program