Enumeration Types Managing Ordered Sets. Enumeration types are designed to increase the readability of programs Used to define a set of named constants.

Slides:



Advertisements
Similar presentations
1 CSE 331 Enumerated types ( enum ) slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Advertisements

Modules Program is built out of components. Each component defines a set of logically related entities (strong internal coupling) A component has a public.
Enumeration Data Type enum Day {SUN, MON, TUE, WED, THU, FRI, SAT}; Day today; today = WED; if (today == FRI) cout
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
Programming in Java (COP 2250) Lecture 8 Chengyong Yang Fall, 2005.
Enumeration.
CONTENTS Wrapper Class Enumeration Garbage Collection Import static.
CS 1430: Programming in C++.
Outline Creating Objects The String Class Packages Formatting Output Enumerated Types Wrapper Classes Components and Containers Images.
Enumerated Types Mr. Dave Clausen La Cañada High School.
1 Enums (Chapter 4) To enumerate is: to name things one after another in a list Java has a type, called an enum, where a programmer specifies a finite.
COMP102 Lab 111 COMP 102 Programming Fundamentals I Presented by : Timture Choi.
1 dimensional static Array Int[] a = new int[4]; A[0]A[1]A[2]A[3] Int[] b= new int[1]; B[0] Array is a list of variables having same name and same data.
Chapter 6. Character String Types It is one in which the values consists of sequences of characters. How to Define a variable contain a string? In a programming.
5 Day Forecast Mon Tues Wed Thu Fri.
More About Objects and Methods
LESSON 06.
Outline Creating Objects The String Class Packages Formatting Output
Enumerated Data Types Data type created by programmer
OBJECT ORIENTED PROGRAMMING II LECTURE 2_1 GEORGE KOUTSOGIANNAKIS
Enumeration Types and typedef
GANTT CHARTS Example Example Example Example text Tasks Example 1
Enumerated DATA Types Enum Types Enumerated Data Types
Instructor: Ioannis A. Vetsikas
typedef typedef int Index; typedef char Letter; Index i; i = 17;
Mon – 2Tue – 3Wed – 4Thu - 5Fri - 6Sat - 7Sun - 8 Mon – 9Tue – 10Wed – 11Thu - 12Fri – 13Sat – 14Sun -15 Mon – 16Tue – 17Wed – 18Thu - 19Fri – 20Sat –
C Arrays Systems Programming.
به نام خداوند خورشید و ماه
October 2011 October 2011 Name: __________________________

MON TUE WED THU
GANTT CHARTS Example Text Text Here Text Here Text Here Text Here
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
January MON TUE WED THU FRI SAT SUN
January MON TUE WED THU FRI SAT SUN
A Different Kind of Variable
There Was Virtually No Difference In TV’s Social Popularity Between May And The Post Memorial Day Time Period TV-related topics dominated social conversations.
Preschool Times and Rates 2 year 3 year 4 year

Topics 4.1 Relational Operators 4.2 The if Statement
January Sun Mon Tue Wed Thu Fri Sat
January MON TUE WED THU FRI SAT SUN
January MON TUE WED THU FRI SAT SUN
More About Objects and Methods

2008 Calendar.
Enumerated DATA Types Enum Types Enumerated Data Types
OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS
CMSC 202 Interfaces.
January MON TUE WED THU FRI SAT SUN
Sun Mon Tue Wed Thu Fri Sat
CS 240 – Lecture 7 Boolean Operations, Increment and Decrement Operators, Constant Types, enum Types, Precedence.
January MON TUE WED THU FRI SAT SUN
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
January MON TUE WED THU FRI SAT SUN
Sun Mon Tue Wed Thu Fri Sat
Name: ______________________________
Chapter 13 Abstract Classes and Interfaces Part 01
1/○~1/○ weekly schedule MON TUE WED THU FRI SAT SUN MEMO
January MON TUE WED THU FRI SAT SUN
S M T W F S M T W F
2016 | 10 OCT SUN MON TUE WED THU FRI SAT
Sun Mon Tue Wed Thu Fri Sat

1 January 2018 Sun Mon Tue Wed Thu Fri Sat
Structures Chapter 4.
2008 Calendar.
Presentation transcript:

Enumeration Types Managing Ordered Sets

Enumeration types are designed to increase the readability of programs Used to define a set of named constants that can be used instead of numbers in a program Such as days of week, months, suits in a deck of cards Months are often set as 1-12 To input or use these values often requires the conversion back and forth between the numeric value and the string value. Enums allow us to refer to a set of objects by name instead of using numbers

Declaring enums Part of the Java.lang package so nothing to import Syntax – enum EnumName { obj1,obj2,obj3}; where these are the names of the constant objects enum Weekday { Sun, Mon, Tues, Weds, Thurs, Fri, Sat }; When executed, an object is instantiated for each name in the list, of the type “Weekday”

Using enum Enums are constant objects – they cannot be changed. References are by the dot syntax Weekday.Sun Weekday w; w = Weekday.Thurs;

Methods Int compareTo( Enum obj) Compares two enum objects and returns Negative value if this object is less than the argument Positive value if this object is more than the argument Zero if the two objects are the same

Boolean equals ( Enum obj) Returns true if this object is equal to the argument Int ordinal() Returns the numeric value of the enum object String toString() Returns the name of the enum constant Enum valueOf ( String enumName) Static method that returns the enum object whose name is the same as the String argument