Download presentation
Presentation is loading. Please wait.
Published byWinfred Perkins Modified over 9 years ago
1
COMP 114 Chris VanderKnyff Kimberly Noonan William Luebke
2
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
3
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.
4
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.
5
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
6
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
7
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
8
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
9
Assignment 2 Rubric (Continued) Category / Item Points Either no coversheet or name is not in the upper right corner: Not stapled: -4
10
Enumeration Example Want to be able to enumerate through numbers until there are no more numbers: public interface IntEnumeration { int getNextInt(); boolean hasMoreInts(); }
11
Natural Number Enumeration Implements IntEnumeration to return the natural numbers. (Natural numbers are the positive integers.)
12
Natural Number Enumeration public class NaturalNumberEnumeration implements IntEnumeration { private int _lastNumber=0; public NaturalNumberEnumeration() {} public int getNextInt() { return ++_lastNumber; // (?) } public boolean hasMoreInts() { return true; }}
13
Fibonacci Enumeration Everyone loves Fibbonacci numbers! Remember: 1, 1, 2, 3, 5, 8, 13, …
14
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; }}
15
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, …
16
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...
17
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; }};
18
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…
19
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();}}}
20
Putting it all together…
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.