COMP 114 Chris VanderKnyff Kimberly Noonan William Luebke.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

More methods and classes, 4 of 4 Math 130 Introduction to Programming Lecture # 18 Monday, October 8, 2007.
Lecture 27 Exceptions COMP1681 / SE15 Introduction to Programming.
Repetition Chapter 4: Control structures. Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 2 Loop Statements After reading and studying this Section,
CS 106 Introduction to Computer Science I 02 / 18 / 2008 Instructor: Michael Eckmann.
COMP 114 Chris VanderKnyff Kimberly Noonan William Luebke.
10-Jun-15 Fibonacci Numbers A simple example of program design.
Fibonacci Numbers A simple example of program design.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
Additional control structures. The if-else statement The if-else statement chooses which of two statements to execute The if-else statement has the form:
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University.
COMP 114 Kimberly Noonan (040) Chris Vanderknyff (040) William Luebke (039)
COMP 114 Recitation Kimberly Noonan Chris VanderKnyff William Luebke.
COMP 114 Kimberly Noonan Chris VanderKnyff William Luebke.
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
CS2110 Recitation 07. Interfaces Iterator and Iterable. Nested, Inner, and static classes We work often with a class C (say) that implements a bag: unordered.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Style It's still hard to give rules, but we can give some examples. Remember: this is to some extent a matter of taste.
Conditional If Week 3. Lecture outcomes Boolean operators – == (equal ) – OR (||) – AND (&&) If statements User input vs command line arguments.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
The Java Programming Language
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Chapter 2: Java Fundamentals
A First Look at Java Chapter 2 1/29 & 2/2 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
COMP 110 switch statements and while loops Luv Kohli September 10, 2008 MWF 2-2:50 pm Sitterson
Java Arrays and Methods MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh.
Writing Static Methods Up until now, we have been USING (calling) static methods that other people have written. Now, we will start CREATING our own static.
1 Building Java Programs Chapter 3: Introduction to Parameters and Objects These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Style guide in JAVA From a lecture by Dr. Rahman.
Introduction to Methods Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com April 1, 2013.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
The for loop.
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
CSCI S-1 Section 4. Deadlines for Homework 2 Problems 1-8 in Parts C and D – Friday, July 3, 17:00 EST Parts E and F – Tuesday, July 7, 17:00 EST.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Programs with Choice Booleans,
REPETITION MTS3033 OBJECT ORIENTED PROGRAMMING 1.
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 2: Primitive Data and Definite Loops.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Information and Computer Sciences University of Hawaii, Manoa
Introduction to Computer Science / Procedural – 67130
CS305J Introduction to Computing
Chapter 5: Control Structures II
Decision statements. - They can use logic to arrive at desired results
Chapter 12 Recursion (methods calling themselves)
Chapter 6 More Conditionals and Loops
A simple example of program design
March 29th Odds & Ends CS 239.
Introduction to Java Programming
Review for Final Exam.
Chapter 1: Computer Systems
Review for Final Exam.
Building Java Programs
Drawing complex figures
Review of Previous Lesson
Building Java Programs
CSS161: Fundamentals of Computing
Presentation transcript:

COMP 114 Chris VanderKnyff Kimberly Noonan William Luebke

What we’re going to do today… Questions from Monday’s and Wednesday’s Lecture Hand back Assignment 1 Rules for Submitting Future Assignments Grading Rubric for Assignment 2 Enumeration Example

Rules for Submitting Future Assignments Code should be printed in a fixed width font. “Courier New” is a common fixed width font. “Courier New” is a common fixed width font. If there are lines longer than 80 characters, print out the code in “landscape” mode so the code doesn’t wrap or get chopped off. If there are lines longer than 80 characters, print out the code in “landscape” mode so the code doesn’t wrap or get chopped off. Ensure that your name is on upper right corner of the first page, or use a coversheet.

Rules for Submitting Future Assignments (Continued) Staple all pages together. No paper clips. No paper clips. No folded papers. No folded papers. Lateness will be strictly enforced. This means that assignments will be returned sooner. This means that assignments will be returned sooner.

Assignment 2 Rubric Category / Item Points Part 1 (while or for loop conditional termination): Solution uses while or for loop conditional termination: 10 Appropriate Test Cases (Screenshots): 0-10 Part 2 (break termination): Solution uses break for loop termination: 10 Appropriate Test Cases (Screenshots): 0-10

Assignment 2 Rubric (Continued) Category / Item Points Part 4 Solution: Style and Structural Guidelines: 0-20 Appropriate Test Cases (Screenshots): 0-20 Cleverness / Elegance 0-10 Write ups: Write up comparing while/for conditional and break termination: 0-10 Write up discussing decoupling: 0-10

Assignment 2 Rubric (Continued) Category / Item Points Lateness: One class period -25 Two class periods -50 Comments: No inner comments (inside methods): -10 No method comments (about each method): -10 No class comments (about each class): -10

Assignment 2 Rubric (Continued) Category / Item Points Not implemented: User input instead of command line: -20 Not implemented: Program loops until a lone period is encountered: -10 Illegal Java library usage: -30 Monolithic main: -10 Meaningless methods: -5 Using “magic numbers” instead of constants: -10

Assignment 2 Rubric (Continued) Category / Item Points Either no coversheet or name is not in the upper right corner: Not stapled: -4

Enumeration Example Want to be able to enumerate through numbers until there are no more numbers: public interface IntEnumeration { int getNextInt(); boolean hasMoreInts(); }

Natural Number Enumeration Implements IntEnumeration to return the natural numbers. (Natural numbers are the positive integers.)

Natural Number Enumeration public class NaturalNumberEnumeration implements IntEnumeration { private int _lastNumber=0; public NaturalNumberEnumeration() {} public int getNextInt() { return ++_lastNumber; // (?) } public boolean hasMoreInts() { return true; }}

Fibonacci Enumeration Everyone loves Fibbonacci numbers! Remember: 1, 1, 2, 3, 5, 8, 13, …

Fibbonacci Enumeration public class FibonacciEnumeration implements IntEnumeration { private int _lastIntReturned=0; private int _secondToLastIntReturned=0; public FibonacciEnumeration() {} public int getNextInt() { int next=_lastIntReturned==0 ? 1 : // (?) _lastIntReturned+_secondToLastIntReturned; _secondToLastIntReturned=_lastIntReturned; return _lastIntReturned=next; } public boolean hasMoreInts() { return true; }}

Every Nth Int Enumeration Provide an IntEnumeration e and ints n and s, and it returns every nth int in e after s. Example: new EveryNthIntEnumeration(5,0,new NaturalNumberEnumeration()) = 1, 6, 11, 16, 21, 26, … new EveryNthIntEnumeration(5,0,new NaturalNumberEnumeration()) = 1, 6, 11, 16, 21, 26, … new EveryNthIntEnumeration(5,2,new NaturalNumberEnumeration()) = 3, 8, 13, 18, 23, 28, … new EveryNthIntEnumeration(5,2,new NaturalNumberEnumeration()) = 3, 8, 13, 18, 23, 28, …

Every Nth Int Enumeration public class EveryNthIntEnumeration implements IntEnumeration { private int _n; private IntEnumeration _enumeration; private int _next; private boolean _hasMore; public EveryNthIntEnumeration(int n,int initialSkip, IntEnumeration enumeration) {_n=n;_enumeration=enumeration; for (int i=0;i<initialSkip;i++) {_enumeration.getNextInt();}_hasMore=_enumeration.hasMoreInts(); if (_hasMore) {_next=_enumeration.getNextInt();}} // More on next slide...

Every Nth Int Enumeration public int getNextInt() { int r=_next; for (int i=0;i<_n-1;i++) {_enumeration.getNextInt();}_next=_enumeration.getNextInt();_hasMore=_enumeration.hasMoreInts(); return r; } public boolean hasMoreInts() { return _hasMore; }};

Putting it all together… public class EnumerationDemo { public static String convertToString( IntEnumeration enumeration,int maxToPrint) { String s=""; for (int i=0; enumeration.hasMoreInts() && i<maxToPrint;i++){ s+=enumeration.getNextInt()+" "; } return s; } // More on next slide…

Putting it all together… public static void main(String args[]) { String descriptions[]= { "natural numbers", "odd numbers", "even numbers", "Fibonacci numbers" }; IntEnumeration enumerations[]= // (?) { new NaturalNumberEnumeration(), new EveryNthIntEnumeration(2,0,new NaturalNumberEnumeration()), new EveryNthIntEnumeration(2,1,new NaturalNumberEnumeration()), new FibonacciEnumeration() }; for (int i=0;i<enumerations.length;i++) { final int FEW=15; System.out.println("The first "+FEW+" "+descriptions[i]+ ": "+convertToString(enumerations[i],FEW)); System.out.println();}}}

Putting it all together…