COP 3330 Notes 4/6.

Slides:



Advertisements
Similar presentations
Unit 9 It's warm 清丰县第一实验小学 唐利娟.
Advertisements

My Favourite Season Let'chant Season s eason The first season is_______. s p r ing.
9-Jun-14 Enum s (and a review of switch statements)
What’s your favorite season?
Magical Mother Nature: The Four Seasons
1-May-15 Java 1.5. Reason for changes “The new language features all have one thing in common: they take some common idiom and provide linguistic support.
Enumerated Types Define a new data type and list all possible values: enum Season {winter, spring, summer, fall} Then the new type can be used to declare.
Value Types and Reference Types Enumerations and Structures.
Fall 2007CS 2251 Enum Types from Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus.
CS 106 Introduction to Computer Science I 11 / 08 / 2006 Instructor: Michael Eckmann.
Seasons of Poems Webquest
Multidimensional Arrays C++ also allows an array to have more than one dimension. For example, a two-dimensional array consists of a certain number of.
Dale Roberts Object Oriented Programming using Java - Enumerations Dale Roberts, Lecturer Computer Science, IUPUI Department.
9. Types Intro Programming in C++ Computer Science Dept Va Tech August, 2002 © Barnette ND & McQuain WD 1 Data Types data type:a collection of.
CompSci 100E 40.1 Java 5 New Features  Generics  Enhanced for loop  Autoboxing/unboxing  Typesafe enums  Other  Varargs  Static Import  Metadata.
Programming in Java (COP 2250) Lecture 8 Chengyong Yang Fall, 2005.
1 Enumerations and Structs Chapter 9. 2 Objectives You will be able to: Write programs that define and use enumeration variables. Write programs that.
Who Wants To Be A Millionaire? Seasons Question 1.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Student Page [Teacher Page]
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
This recitation 1 An interesting point about A3: Using previous methods to avoid work in programming and debugging. How much time did you spend writing.
High Frequency Words favourite My favourite season is spring. HFW – P.2 – Unit Find this on page 54 of your MP book.
Unit2 My favourite season. spring summer fall winter.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 39 – Command Line Args & Recursion Webpage:
CSE 332: C++ pointers, arrays, and references Overview of Pointers and References Often need to refer to another object –Without making a copy of the object.
Introduction to Enumerations CMSC 202. Enumerated Values Enumerated values are used to represent a set of named values. Historically in Java (and other.
Enum. enum – a new type 2 enum is a set of constant int values, that defines a type: enum Season { WINTER,// = 0 by default SPRING,// = WINTER + 1 SUMMER,//
New Java Features Advanced Programming Techniques.
Enumeration Types Managing Ordered Sets. Enumeration types are designed to increase the readability of programs Used to define a set of named constants.
OOP Tirgul 12.
Lecture 7 D&D Chapter 7 & 8 Composite Classes and enums Date.
Java Language Basics.
A season is a time of the year.
Review Multiple Regression Multiple-Category Dummy Variables
Error Correcting Code.
Student Book An Introduction
Visit for more Learning Resources
CNG 140 C Programming (Lecture set 10)
Error Handling Summary of the next few pages: Error Handling Cursors.
Some random things in Java
What are the Common Seasonal Car Repairs?.
Buy book Online -
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
File Handling Programming Guides.
Namespaces, Typedefs & Enums
(and a review of switch statements)
(and a review of switch statements)
SEASONS.
More On Enumeration Types
Impact on Learning: Feedback in On-line Assignments
What Causes Seasons?.
Another method for solving systems of linear equations
Variables In today’s lesson we will look at: what a variable is
To burn-in a print, the print is first given normal exposure.
Chapter 16: Check Digit Systems, Continued
EECE.2160 ECE Application Programming
Decisions, decisions, decisions
5. 3 Coding with Denotations
Java 5 New Features 1-May-19.
Cut and Paste Phases from PDF Datasheets EXAMPLE And insert here Visit
For Loops Pages
Introduction Welcome! I am sure you all know a little something already about the four seasons: Autumn, Winter, Spring, and Summer. You will be working.
For Professional Services
Enum.
Hossain Shahriar CISC 101: Fall 2011 Hossain Shahriar
EECE.2160 ECE Application Programming
Morning Warm- Up. What changes can we observe in nature
For Automotive Services and Repair
Presentation transcript:

COP 3330 Notes 4/6

Today’s Topics Enumerations

enum webpage Since the book has nothing on enums, you can go to this page for reference instead: http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html

Enumerations Sometimes we want to keep track non-standard data that can only take on a few states Examples: Seasons of the year Rock, Paper, Scissors Let's see if you can come up with an example (think assignment 3)

Enumerations One way to keep track of such data is using constants Example public static final int SPRING = 1; public static final int SUMMER = 2; public static final int FALL = 3; public static final int WINTER = 4;

Enumerations A better way can be to use an enum You can create an enumeration in much the same way as a class Example: public enum Season{ SPRING, SUMMER, FALL, WINTER }

Enumerations Problems with using int constants Not typesafe: You can store invalid values (e.g. There's no such thing as season 47) Printed values mean little (e.g. Does 2 mean Rock, Paper, or Scissors?) Adding values is error prone

Enumerations Additional benefits of enum You can use an iterator for loop over the enumerated values by using the values() method to retrieve the set of values The enumerated type can also store extra information that an int can't (constant objects could get around that, though)

Enumerations Example: Use enumerations to print out every card in a deck of cards Example: Use enumerations to print out holidays