Lecture 21 CS110 Lecture 2 January 29, 2004 Announcements –hw1 part 1 – due right now –hw1 part 2 – due Tuesday night Questions Agenda –turnin –Object.

Slides:



Advertisements
Similar presentations
Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
Advertisements

Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
The Java Programming Language  Simple – but abstract  Safe  Platform-independent ("write once, run anywhere")  Has a Rich growing library  Designed.
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Lecture 241 CS110 Lecture 25 Tuesday, May 4, 2004 Announcements –final exam Thursday, May 20, 8:00 AM McCormack, Floor 01, Room 0608 (easier than last.
ACM/JETT Workshop - August 4-5, Object-Oriented Basics & Design.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Hello AP Computer Science!. What are some of the things that you have used computers for?
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Computing Science 1P Large Group Tutorial 17 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Java Language and SW Dev’t
CS 106 Introduction to Computer Science I 01 / 25 / 2010 Instructor: Michael Eckmann.
Lecture 61 CS110 Lecture 6 Thursday, February 12, 2004 Announcements –hw2 due today Agenda –questions –testing –modeling text files –declarations (classes,
Introduction to Object-Oriented Programming
1 Agenda Administration Background Our first C program Working environment Exercise Memory and Variables.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
The Java Programming Language
Creating your first C++ program
Programming With C.
Classes CS 21a: Introduction to Computing I First Semester,
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Lecture 131 CS110 Lecture 13 Thursday, March 11, 2004 Announcements –hw5 due tonight –Spring break next week –hw6 due two weeks from tonight Agenda –questions.
Introduction to programming in the Java programming language.
Lecture 71 CS110 Lecture 7 February 17, 2004 Announcements –hw3 due Thursday Agenda –questions –hw3 tips –getters and setters – information hiding –delegation.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
 When you receive a new you will be shown a highlighted in yellow box where your can be found  To open your new just double click.
Introduction to Java Java Translation Program Structure
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Chapter 4 Introduction to Classes, Objects, Methods and strings
Creating Programs on UNIX This term you can create programs on UNIX or you can create programs using a C++ compiler on your PC. This set of slides steps.
1 A simple C++ program // ======================================================= // File:helloworld.cpp // Author:Vana Doufexi // Date:1/4/2006 // Description:Displays.
Lecture 121 CS110 Lecture 12 Tuesday, March 9, 2004 Announcements –hw5 due Thursday –Spring break next week Agenda –questions –ArrayList –TreeMap.
CMSC 104, Lecture 111 Introduction to C Topics l Compilation l Using the gcc Compiler l The Anatomy of a C Program l 104 C Programming Standards and Indentation.
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
CMSC 1041 Introduction to C Creating your first C program.
Lecture 71 CS110 Lecture 8 February 19, 2004 Announcements –hw3 due tonight –hw4 available, due Thursday February 26 –exam Tuesday March 2 Agenda –questions.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Getting Started with Java: Object declaration and creation Primitive.
Introduction Chapter 1 1/22/16. Check zyBooks Completion Click on the boxes for each section.
Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.
CS110 Introduction to Programming Lecture 1 January 27, 2004 Ethan Bolker Philosophy Bank: user interface, Java, object model Programming environment Homework.
CS100Lecture 21 Announcements For homework due Thursday, work alone -- do not work in pairs New class location: Olin 155 Office hour oops! Lyn: MW, 11:15-12:15.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Chapter 3 Implementing Classes
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Linux CSE 1222 CSE1222: Lecture 1BThe Ohio State University1.
Introduction to C Topics Compilation Using the gcc Compiler
Lecture 3 John Woodward.
ANNOUNCEMENT The missed lecture will be made up this Monday evening in the Tech PC classroom (MG51). A tentative time interval is 6:30-8:00. The exact.
CSC201: Computer Programming
Lecture 1 Introduction Richard Gesick.
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Introduction to C Topics Compilation Using the gcc Compiler
Creating Programs on UNIX
Introduction to C Topics Compilation Using the gcc Compiler
Chapter Three - Implementing Classes
Chapter 1: Computer Systems
Creating your first C program
Anatomy of a Java Program
Classes CS 21a: Introduction to Computing I
Introduction to Object-Oriented Programming
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

Lecture 21 CS110 Lecture 2 January 29, 2004 Announcements –hw1 part 1 – due right now –hw1 part 2 – due Tuesday night Questions Agenda –turnin –Object oriented programming (bank simulation) –XEmacs

Lecture 22 Questions Do ask in class when you –have come with a question –are a little confused –think I have made a mistake –think others might learn from your question/insight Don’t ask –just to show off –if you are completely lost (come see me instead) –if you haven’t read the book and hw and your –what happened in a class you missed –after class about something in the class

Lecture 23 etiquette (please) Ask (in ) –after you have tried to solve your problem, but before you’ve wasted 8 hours stuck in one place –with enough detail so that I can help Don’t expect immediate feedback I may cc question and answer to class Do correspond with your friends No junk mail

Lecture 24 Electronic hw submission turnin system: (available by Monday, perhaps sooner) Instructions: follow link on course web page Your user name (all lower case) –up to 6 characters from last name –balance to 8 characters from first name John Kennedy  kennedjo Clark Kent  kentclar Wei Liu  liuwei Password: passwd (change it!)

Lecture 25 Object oriented programming The (software) world consists of objects Each object is an instance of a class An object has –fields that describe what it looks like (its state) –methods that describe how it behaves One object sends a message to another asking it to use one of its methods to do some work Add italicized words to your vocabulary Illustrate these abstractions with bank example in Java

Lecture 26 OOP in Java File BankAccount.java describes BankAccount objects (instances of class BankAccount) BankAccount.java has two audiences –people (programmers like us) –the Java compiler Java files always start with comments –a convention good programs honor –not a rule in the Java language, but a rule for us Comments are for people to read: Java doesn’t care // text up to end of line is a comment /** special javadoc comment – more later */ /* old style comment– rare */

Lecture 27 1 // joi/1/bank/BankAccount.java 2 // 3 // 4 // Copyright 2003 Bill Campbell and Ethan Bolker 5 6 /** 7 * A BankAccount object has a private field for 8 * this account's current balance, and public 9 * methods to return and change the balance. 10 * 11 Bank */ public class BankAccount 16 { 62 } BankAccount.java File name, date, authors in // comments at top of file Brief description of class instances in javadoc comment block /** … */ Java code between these braces describes fields and methods of BankAccount objects Official Java declaring the class

Lecture 28 Each field has a type, a name and a value BankAccount object picture Code in BankAccount.java tells type (int, for integer) and name (balance – good choice by programmer) Value (999) may change from time to time balance:999 int fields : what an object looks like BankAccount 17: private int balance; // work in whole dollars type of object field name:value type of field

Lecture 29 Bank object’s fields (picture) “Engulf and Devour” int 200 int 200 BankAccount balance: BankAccount balance: Terminal String bankName: Bank BankAccount account1: BankAccount account2: Terminal atm: int name of field type of field value when value is another object, use an arrow type of object

Lecture 210 Bank object’s fields (code) From Bank.java, showing types and names of four fields type name 22 private String bankName; // Bank’s name private Terminal atm; // talks to customer private BankAccount account1; 27 private BankAccount account2; Conventions: –Class names always begin with an upper case letter –Field names always begins with a lower case letter If type is a class then value is that kind of object

Lecture 211 Messages Ask an object to work for you: send it a message Bank.java (line 116) account.deposit(amount) this Bank object sends a deposit message to object account of type BankAccount Java syntax: object.message(info) syntax: what the program looks like on the page deposit method in BankAccount.java does the work

Lecture 212 methods : how an object behaves BankAccount has several methods: deposit (int amount) // line 47 –add amount to current balance, changing value of balance field getBalance( ) // line 58 –tell whoever sent the message how much money is in this account (value of balance field) –balance does not change –the empty parentheses tell us this method needs no information from the sender to do its job

Lecture 213 Messages (reprise) Ask an object to work for you: send it a message Bank.java (line 126) atm.println(“sorry,... ”) this Bank object sends a println message to object atm of type Terminal asking it to print a String on the screen Java syntax: object.message(info) println(String something) method in Terminal.java does the work Trust Terminal.java to do the right thing

Lecture 214 Bank.java line 107 somewhere in Terminal.java Message invoking a method String command = atm.readWord(“transaction: ”); readWord (String prompt ) { print prompt on screen get first word user types return thatWord } prompt = “transaction: ” command = thatWord execution flow: line 107 in Bank.java sends a readWord message to a Terminal. Code for readWord method in Terminal.java runs, then work resumes at line 104 in Bank.java

Lecture 215 Homework 1 Part 1 (hard copy due right now) –Play with Bank simulation Part 2 (collected electronically Tuesday night) –Play with Bank simulation –Improve the Bank simulation –Write about your coding and testing

Lecture 216 emacs is a programmer’s editor prettyprint tab, java  indent compilectrl-x ctrl-m tools  compile  compile loop through compiler errors ctrl-x ` (backquote) tools  compile  next error run programsctrl-x ctrl-r tools  shell  shell learn from XEmacs/Java tutorial