CS62 - Spring 2010 - Lecture 1
introduction to students
- name
- major, year, college
- CS background
- Why are you taking this course?
- What do you hope to get out of the course?
goals of the class
- Prereqs: 51 or AP CS. Should be familiar with Java specifically:
- classes
- arrays
- control structures
- recursion
- advanced programming: more practice and more tools
- data structures
- basic performance analysis and design decisions
- C++
- After this class, you'll be ready to take upper division CS courses
Bursti (
http://saras.cs.pomona.edu/bursti/)
from cs160 in the Fall
administrative
- show class web page
- rough schedule
- labs
- two labs on Wed. and are required (no lab this week)
- must come to one, but feel free to come to both
- labs will lead generally be a lead in to assignment
- computer accounts
- I'll post everything online on the class web page
- I will post my notes
- Grading
- Academic honesty (the code you write must be your own)
What makes a good computer program?
- correct
- efficient
- readable/understandable/well-documented
- reusable/easy to modify
- data encapsulation/information hiding/abstraction
- You write your code, how does your program actually end up running and showing up on the computer?
- Let's ask some more directed questions
- what is a string?
- an ordered list of characters
- what functionality do we have?
- how is it implemented?
- Could be many different ways, but most of the time, we don't care as long as the functionality is preserved. This is data abstraction.
- The functionality, is called the interface
- How this is done internally, is called the implementation
Object oriented programming: The key to an object oriented programming language is managing complexity
- classes
- private, internal data
- methods to access and manipulate the data
- the only thing you need to know about a class is it's interface, i.e. it's public methods, not the details of how it's implemented
Why is OO programming useful/good?
Design a card dealer class
- represent some number of decks of cards
- What operations/functionality do we want (this is the interface)?
- deal/get next card
- are there cards left?
- shuffle
- What should the constructor consist of?
- number of decks
- Implementation details:
- What data do we need to store?
- somehow the state of the cards
- How are we going to store that data?
- Fill in the details of the methods
show
CardDealer code
- comment code!
- coding style: I provide a style guideline online, but as you get better at programming you can experiment with what style works best for you. Just make sure you're consistent and it makes sense
- constants: should always be caps and start with "private static final"
- what do all of those words mean?
- the book suggests using "protected" instead of "private". I'm going to use "private" and will talk about the difference soon.
- What is "public static void main(String[] args)" and what do each of the parts mean?
- Notice that all of our data is private (i.e. not accessible to outside classes), but we provide methods that allow interaction
- What is the functionality of the Random class? What methods does it have?
- We can look it up in the API
- "import" allows us to bring in additional outside resources in to our class
- How else could we implement the CardDealer methods?
show
CardDealerBoolean code
- just keep track of which cards have been dealt and then randomly pick a card from those remaining
- same interface as CardDealer class, but different implementation
- notice the use of private methods (setAllTrue)
- which approach is better?
- CardDealer seems more intuititive
- CardDealer is more efficient (particularly as we have fewer undealt cards)
- CardDealerBoolean uses less memory
- how many bits do we need to store a boolean variable?
- int's use 32 bits to represent the numbers... how many numbers can we represent?
Design a stopwatch class
- What functionality should we have?
- start
- stop
- reset
- getTime
- Be specific about the functionality:
- What happens if we call start twice in ?
- What happens if we call stop twice in a row? or without having called start?
- What happens if we call start then call reset (without calling stop)?
- What data do we need to store?
- start time
- stop time (or accumulated time)
- whether it's running or not (what happens if we just hit stop twice without using a running variable?)
show
StopWatch code