150 likes | 284 Views
CS110 Introduction to Programming. Lecture 1 January 27, 2004 Ethan Bolker Philosophy Bank: user interface, Java, object model Programming environment Homework 1 Start now! www.cs.umb.edu/cs110. Announcements. These slides are available on course web page
E N D
CS110Introduction to Programming Lecture 1 January 27, 2004 Ethan Bolker Philosophy Bank: user interface, Java, object model Programming environment Homework 1 Start now! www.cs.umb.edu/cs110
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
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
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
Computers and programs • Computer: a machine that can simulate many different machines word processor traffic light controller internet shopping site 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
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
Bank simulation - object model program architecture Bank “Engulf and Devour” BankAccount String int bankName: int balance: 999 200 BankAccount account1: BankAccount int BankAccount int account2: balance: 200 200 Terminal Terminal atm: Lecture 1
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
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
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 return info to Bank Lecture 1
Bank simulation Objects responding to messages BankAccount object return info to Bank: message from Bank: before after deposit(799) bal: 200 bal: 999 line 116 999 getBalance() bal: 999 bal: 999 line 123 Lecture 1
Software development cycle • imagine • design • edit • compile • run, test • imagine the next release ... • user interface • object model • Java implementation • quality assurance • good programs evolve! X E m a c s Lecture 1
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
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
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