CS110 Introduction to Programming Lecture 1 January 27, 2004 Ethan Bolker • Philosophy •Bank: user interface, Java, object model • Programming environment • Homework 1 • Start now! Announcements • These slides are available on course web page • Hand in questionnaire on your way out • Discussion sections meet regularly in Purple Lab, upper garage level in Healey library • Purple lab PCs have been configured for CS110 • Other lab computers will be ready soon – I will let you know when • Passwords for homework turnin web site available at next class Lecture 1 2 Learning to program • • • • Lots of fun Practical Hard, time consuming Unusual mixture: – sophisticated intellectual content – picky details that must be right • Exercise in reading, writing, thinking • CS110 is for CS majors, future professionals Lecture 1 3 Teaching/learning style • To learn a language well, live in a land where it’s spoken – anxiety producing, but efficient! • Learn to write by to reading and writing and writing about what you learn • 60% of a lot is more than 100% of a little • Ask questions (to slow me down) Lecture 1 4 Computers and programs • Computer: a machine that can simulate many different machines word processor internet shopping site traffic light controller bank ATM … • Program: the instructions that tell a computer how to act like some particular machine • Example: Bank simulation – user interface (how the program behaves) – object model (the program’s architecture) – Java implementation (the program itself) Lecture 1 5 Bank simulation - user interface a:\> java Bank [Enter, CR] Welcome to Engulf and Devour Account number (1 or 2), 0 to shut down: 1 Transactions: exit, help, deposit, withdraw, balance transaction: balance 200 transaction: deposit amount: 799 transaction: balance 999 transaction: exit Account number (1 or 2), 0 to shut down: 0 Goodbye from Engulf and Devour a:\> Lecture 1 6 Bank simulation - object model program architecture Bank “Engulf and Devour” BankAccount String int int balance: 200 999 bankName: BankAccount account1: BankAccount BankAccount account2: Terminal int balance: 200 200 Terminal atm: Lecture 1 7 Why Java? • Fashionable, modern (for good reasons) • Object oriented: when you have designed the architecture a program almost writes itself • Portable: the same Java code turns any computer (PC, mac, server) into a Bank • Well designed: – – – – consistent user interface easy to learn hard to make serious mistakes prebuilt objects plug into your programs Lecture 1 8 Send object a message Bank.java (lines 101ff) while ( moreTransactions ) { ... String command = atm.readWord( "transaction: " ); ... else if ( command.equals( "deposit" ) ) { int amount = atm.readInt( "amount: " ); account.deposit( amount ); } ... else if ( command.equals( "balance" ) ) { atm.println( account.getBalance() ); } ... } object dot message ( information ) Lecture 1 9 Bank simulation Objects responding to messages Terminal object (the atm) message from Bank: readWord(″transaction: ″) line 107 command customer typed return info to Bank String object (the command) equals(″deposit″) line 114 true or false Lecture 1 return info to Bank 10 Bank simulation Objects responding to messages BankAccount object message from Bank: before deposit(799) bal: 200 after return info to Bank: bal: 999 line 116 getBalance() line 123 bal: 999 bal: 999 Lecture 1 999 11 Software development cycle • • • • • • imagine design edit compile run, test imagine the next release ... • user interface • object model • Java implementation X E m a c s • quality assurance • good programs evolve! Lecture 1 12 emacs • • • • The programmer’s editor (word processor) Learning emacs is as important as learning Java You will live inside emacs in this course XEmacs installed on all lab PCs, available free for home machines • Start using it today – tutorial linked from course home page Lecture 1 13 Homework 1 • Handed out in class, on course web page • Part 1 – get started – – – – – Hard copy due at the next class Send email Explore course web page Understand rules about honesty Write about what you find – use emacs • Part 2 - jump in to Java – – – – Collected electronically Tuesday Feb 3 Play with Bank simulation Improve Bank simulation Write about your coding and testing Lecture 1 14 Start now! • Turn in questionnaire as you leave class • Sections meet in Purple lab (Library upper level) • Today: begin hw1 – send email! (any lab) – explore web page www.cs.umb.edu/cs110 (any lab) – begin using XEmacs (Purple lab) • I will be in my office (S-3-179) today until 4, tomorrow 12-2:30 Lecture 1 15