Spring 2008 Mark Fontenot CSE 1341 - Honors Principles of Computer Science I Note Set 17.

Slides:



Advertisements
Similar presentations
Classes And Objects II. Recall the LightSwitch Class class LightSwitch { boolean on = true; boolean isOn() { return on; } void switch() { on = !on; }
Advertisements

1 Classes and Objects in Java Parameter Passing, Delegation, Visibility Control, and Object Cleanup.
Class Solar System Riddles
Java for C++ Programmers Second Night. Overview First Night –Basics –Classes and Objects Second Night –Enumerations –Exceptions –Input/Output –Templates.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
1 Calling within Static method /* We can call a non static method from a static method but by only through an object of that class. */ class Test1{ public.
1.To investigate the value of g on other planets in our solar system & to practice our graph drawing and other practical skills 2.To recreate some of.
Using Classes to Store Data Computer Science 2 Gerb.
Computer Programming Lab 8.
THE SOLAR SYSTEM By: Natalie Natale LRC 320 Final Project.
By Keith Lehman  Mercury has no moons.  Mercury is 1/3 the size of Earth.  On Mercury, a day is 59 Earth days long.  Mercury is a rock planet.
Mass & Weight D. Crowley, 2008.
Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto Solar System Radius= light years An arrow where the tenth planet is and maybe how small.
Misc Language Features Features that were added relatively recently that are now in common use.
Comparative Diameters of the Planets Title the page with the above title.
THE SOLAR SYSTEM.
Planet Order Create an easy way to remember the names of the planets in order from the Sun. Make up a silly sentence. Each word in the sentence should.
Ms. Mitchell’s 6th Grade Greenbriar West Elementary Matter.
My Solar System Slide Show YOUR NAME.
By: ? & ? Grade 6-1 The Planet’s chart PlanetPeriod of rotation Orbiting the sun Mercury59 days88 days Venus243 days225 days Earth23.9 hours days.
The Solar System. Mercury Mercury is the closest planet to the sun. Mercury is the closest planet to the sun. Mercury is the eighth largest planet. Mercury.
The Solar System.
Planets of the Solar System Our Solar System has nine planets.
Mercury  The closest planet to the sun.  It has no moons.  It has 38% gravity.  It takes 88 days to orbit the sun.
Nacht van Saturnus.
Evaluating Experiments D. Crowley, Evaluating Experiments To be able to evaluate experiments, and know the difference between mass and weight Monday,
The FRAME Routine Key Topic Main idea is about… So What? (What’s important to understand about this?) Essential details Main idea Essential details Main.
+ The sun is hot. The sun can kill you before you get there.
Ms. Mitchell’s 6th Grade Greenbriar West Elementary TEACHER VERSION Matter.
Are Amazing Planets By Samy Abdelsalam Mercury Mercury has no moons. Mercury is the first planet from the sun. Mercury is 36 million kilometers) away.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Warmup: Finish #4 and #5 Planet Orbital Period Orbital Radius (AU) Mercury Venus Earth 11 Moon Mars Jupiter
Space Science Space Science. How many planets are in our Solar System?
The Solar System Journey to Outer Space. Overview  The Solar System includes:  The sun  The eight official planets  At least three draft planets 
Our Solar System By Priya Papandrea. Contents Our Planets The Sun Facts about the sun More facts about the sun The moon Facts about the moon Bibliography.
Welcome to... A Game of X’s and O’s Modified from a game Developed by Presentation © All rights Reserved
Java Programming: Program Design Including Data Structures 1 Vectors The class Vector can be used to implement a list Unlike an array, the size of a Vector.
Planets By Meagan Caine.
How many moons does each planet have?. Saturn has 60 moons l=en&site=imghp&tbm=isch&source=hp&biw= 1366&bih=665&q=planets+in+the+solar+syste.
The Solar System By Devin Fields Fourth grade Mrs. Krause 2009.
Made By Chloe,Imogen,Peter And Teigue
Space and the planets.
Do Now  If you had to define what a “year” is, how would you define it?
© 2006 Pearson Addison-Wesley. All rights reserved char and String char is for storing single characters primitive type constants: a printable character.
What is in Space? Have you ever wondered what’s in space?
Lesson 5: Rotation vs. Revolution.  A planet spinning on its axis.  1 Day  Venus has the solar system’s longest day! PlanetDay Mercury58 Earth days.
Comparing the Planet’s to the Sun
CS 1430: Programming in C++.
Kepler’s Laws of Planetary Motion - 3 Laws -. Elliptical Orbits Planets travel in elliptical orbits with the sun at one focus. Furthest point = Aphelion.
TOURING THE SOLAR SYSTEM Use the Internet to research this project and use the following websites as a place to start:
What makes the Universe?. Questions to Consider What is the Solar System? What is the Solar System? What does the Solar System consists of? What does.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 12.
ESSENTIAL QUESTION HOW CAN I DETERMINE THE PLACE OF A DIGIT IN A NUMBER? KNOW YOUR PLACE IN SPACE.
The formation of the solar system.. The Planets in Our Solar System Planet Distance from the Sun (Astrono mical Units miles km) Period of Revolut ion.
Distance to the Planets (whole class activity) Materials: Long strip of paper, pencil.
Planets Caitlin Price Mercury Venus EarthSaturn Neptune Quiz.
By: Krystal Carpenter. Things to talk about today Planets in order from the Sun Planets in order from the Sun The Sun The Sun The Moon The Moon.
PowerPoint Design by Jim Luther Click The ? Buttons For More Info Scan Type Scan Time in Seconds for Single Switch Scan Scan Setup Slide.
By Charlotte. This power point is about the Solar System. It will include Pluto as well as all the other planets. I will have some fascinating facts about.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
 By the end of today…  SWBAT explain the differences between Terrestrial planets and Jovian planets.
The Planets of Our Solar System Mercury.
CLICK TO CONTINUE CLICK TO CONTINUE. The Sun Inner Solar System Inner Solar System Outer Solar System Outer Solar System.
Seven Lecture Collection 1. 2 Some Legacy Collection Types  ArrayList  Enumeration  Vector  HashTable – self study.
Mass and Weight.
char is for storing single characters
Far and Away.
A Different Kind of Variable
AKA the birth, life, and death of variables.
The Planets of our Solar System The Terrestrial Planets
Presentation transcript:

Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 17

Note Set 17 Overview Back To The … Enums

Before Enums: The enum “pattern” public class StudentType { public static final int FRESHMAN = 1; public static final int SOPHOMORE = 2; public static final int JUNIOR = 3; public static final int SENIOR = 4; public static final int GRADUATE = 5; } Problems?? Yes. 1.Not Typesafe = its just an int 2.Printed values will just be number, not a useful string representation 3.others…

What is it? Enumeration In simplest form: set of declared constants represented by identifiers Actually a special kind of class introduced with keyword enum enum Status {CONTINUE, WON, LOST}; enum Problem {ADDITION, SUBTRACTION, MULTIPLICATION, DIVISION}; enum Class {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR};

StudentType /** * StudentType enum provides a type * where the valid range of values are only * those listed. */ public enum StudentType { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR, GRADUATE; }

Student public class Student { //Student's name private String name; //This variable's type is StudentType. //So it can only hold a value from //the list declared in the StudentType Enum. private StudentType classification; public void setName(String s) { name = s; } public String getName() { return name; } public void setClassification (StudentType t) { classification = t; } public StudentType getClassification() { return classification; }

StudentTypeTest public class StudentTypeTest { public static void main (String[] args) { Student s1 = new Student(); Student s2 = new Student(); s1.setName("Sam"); s1.setClassification(StudentType.FRESHMAN); s2.setName("Bob"); s2.setClassification(StudentType.GRADUATE); print(s1); print(s2); }

StudentTypeTest public static void print(Student s) { System.out.println("Hi, my name is " + s.getName()); //call the accessor of the Student object to get the StudentType //swicth on this value returned switch(s.getClassification()) { //Case labels must be from the datatype that //we are switching on case FRESHMAN: System.out.println(" I'm just starting."); break; case SOPHOMORE: System.out.println(" 1 Down, 2 to go!"); break; case JUNIOR: System.out.println(" Yay, I\"m and upperclassperson"); break; case SENIOR: System.out.println(" I can see the light...Whew"); break; case GRADUATE: System.out.println(" I've been here too long..."); }

Treating as a class Because an enum is a type, it can have data and behavior. Each enumerated value can have data associated with it. public enum Planet { MERCURY (3.303e+23, e6), VENUS (4.869e+24, e6), EARTH (5.976e+24, e6), MARS (6.421e+23, e6), JUPITER (1.9e+27, e7), SATURN (5.688e+26, e7), URANUS (8.686e+25, e7), NEPTUNE (1.024e+26, e7), PLUTO (1.27e+22, 1.137e6); private final double mass; // in kilograms private final double radius; // in meters Planet(double mass, double radius) { this.mass = mass; this.radius = radius; } public double mass() { return mass; } public double radius() { return radius; } // universal gravitational constant (m3 kg-1 s-2) public static final double G = E-11; public double surfaceGravity() { return G * mass / (radius * radius); } public double surfaceWeight(double otherMass) { return otherMass * surfaceGravity(); }