COMP 110 Classes Tabitha Peck M.S. March 3, 2008 MWF 3-3:50 pm Philips 367 1.

Slides:



Advertisements
Similar presentations
COMP 110: Introduction to Programming Tyler Johnson Feb 25, 2009 MWF 11:00AM-12:15PM Sitterson 014.
Advertisements

COMP 110: Introduction to Programming Tyler Johnson Mar 23, 2009 MWF 11:00AM-12:15PM Sitterson 014.
IMPLEMENTING CLASSES Chapter 3. Black Box  Something that magically does its thing!  You know what it does but not how.  You really don’t care how.
Catie Welsh March 2,  Program 3 due tonight by 11:59pm  Lab 5 due Friday by 1pm  Sample Midterm is posted on course website ◦ Solutions will.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
1 COMP 110 Inheritance Tabitha Peck M.S. April 16, 2008 MWF 3-3:50 pm Philips 367.
1 COMP 110 Static Methods and Variables Tabitha Peck M.S. March 24, 2008 MWF 3-3:50 pm Philips 367.
COMP 110 Loops Tabitha Peck M.S. February 11, 2008 MWF 3-3:50 pm Philips
COMP 110 More Loops and Strings Tabitha Peck M.S. February 18, 2008 MWF 3-3:50 pm Philips
1 COMP 110 Arrays Tabitha Peck M.S. March 31, 2008 MWF 3-3:50 pm Philips 367.
COMP 110 Objects and References Tabitha Peck M.S. February 27, 2008 MWF 3-3:50 pm Philips
1 COMP 110 More Arrays Tabitha Peck M.S. April 2, 2008 MWF 3-3:50 pm Philips 367.
COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips
1 COMP 110 Designing and Overloading Methods Tabitha Peck M.S. March 26, 2008 MWF 3-3:50 pm Philips 367.
COMP 110 Designing Programs Tabitha Peck M.S. January 16, 2008 MWF 3-3:50 pm Philips
COMP 110 Primitive Types, Strings, and Console I/O Tabitha Peck M.S. January 23, 2008 MWF 3-3:50 pm Philips
COMP 110 If / Else and Case Statements Tabitha Peck M.S. February 4, 2008 MWF 3-3:50 pm Philips
COMP 110 Errors, Strings, and Review Tabitha Peck M.S. January 28, 2008 MWF 3-3:50 pm Philips
COMP 110 Branching Statements and Boolean Expressions Tabitha Peck M.S. January 28, 2008 MWF 3-3:50 pm Philips
1 COMP 110 Inheritance Tabitha Peck M.S. April 14, 2008 MWF 3-3:50 pm Philips 367.
COMP 110 Information Hiding and Encapsulation Tabitha Peck M.S. February 25, 2008 MWF 3-3:50 pm Philips
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Writing Classes (Chapter 4)
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
ACO 101: Introduction to Computer Science Anatomy Part 2: Methods.
CS61B L03 Building Objects (1)Garcia / Yelick Fall 2003 © UCB  Dan Garcia ( Kathy Yelick  (
CSCI S-1 Section 6. Coming Soon Homework Part A – Friday, July 10, 17:00 EST Homework Part B – Tuesday, July 14, 17:00 EST Mid-Term Quiz Review – Friday,
COMP 110 Constructors Luv Kohli October 13, 2008 MWF 2-2:50 pm Sitterson 014.
1 Operators and Expressions Instructor: Mainak Chaudhuri
COMP 110 switch statements and while loops Luv Kohli September 10, 2008 MWF 2-2:50 pm Sitterson
Mixing integer and floating point numbers in an arithmetic operation.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
ACM/JETT Workshop - August 4-5, : Defining Classes in Java.
Classes and Objects CS177 Rec 10. Announcements Project 4 is posted ◦ Milestone due on Nov. 12. ◦ Final submission due on Nov. 19. Exam 2 on Nov. 4 ◦
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
1 More data types Character and String –Non-numeric variables –Examples: char orange; String something; –orange and something are variable names –Note.
Bank Account Example public class BankAccount { private double balance; public static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++;
COMP 110 Static variables and methods Luv Kohli October 29, 2008 MWF 2-2:50 pm Sitterson 014.
Chapter One Lesson Three DATA TYPES ©
COMP 110 Branching Statements and Boolean Expressions Luv Kohli September 8, 2008 MWF 2-2:50 pm Sitterson
Announcements Final Exam: TBD. Static Variables and Methods static means “in class” methods and variables static variable: one per class (not one per.
Object-Oriented Programming Fundamentals. Comp 241, Fall Example Colored points on the screen What data goes into making one? Coordinates Color.
Classes CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Java Scanner Class Keyboard Class. User Interaction So far when we created a program there was no human interaction Our programs just simply showed one.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
COMP 110 Augustus Gloop, Augustus Gloop… Luv Kohli September 24, 2008 MWF 2-2:50 pm Sitterson 014.
COMP 110 More about classes Luv Kohli October 3, 2008 MWF 2-2:50 pm Sitterson 014.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
An Introduction to Java – Part I, language basics
د.سناء الصايغ الفصل الأول البرمجة الشيئية
More on Classes and Objects
Assignment 7 User Defined Classes Part 2
Announcements Program 2 is due tomorrow by noon Lab 4 was due today
Arrays of Objects // The following does NOT create memory for
Recursive GCD Demo public class Euclid {
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
CS100J Lecture 7 Previous Lecture This Lecture Java Constructs
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Programs and Classes A program is made up from classes
Local variables and how to recognize them
Announcements Lab 5 due Wednesday at noon.
Previous Lecture: Today’s Lecture: Reading (JV):
Presentation transcript:

COMP 110 Classes Tabitha Peck M.S. March 3, 2008 MWF 3-3:50 pm Philips 367 1

Announcements Program 3 due tomorrow by midnight Wednesday - come with review questions Wednesday office hours? Friday - midterm 2

Questions? 3

Today in COMP 110 Write a bank account class for Harry Potter A.K.A. more with classes 4

Example run Would you like to make a transaction? y/n y Would you like to make a deposit (d), withdrawal (w), or inquire (i)? d How many galleons, sickles, and knuts would you like to deposit? Galleons: 5 Sickles: 6 Knuts: 4 Would you like to make a transaction? y/n y Would you like to make a deposit (d), withdrawal (w), or inquire (i)? w How many galleons, sickles, and knuts would you like to withdrawal? Galleons: 4 Sickles: 0 Knuts: 0 Would you like to make a transaction? y/n y Would you like to make a deposit (d), withdrawal (w), or inquire (i)? i You now have: 1 galleons 6 sickles 4 knuts 5

Private Instance Variables What are instance variables? Why private? What are the instance variables for our bank account program? What do we need to keep track of? 6

Beginning of Account class public class Account { private int galleons = 0; private int sickles = 0; private int knuts = 0; 7

Accessor and Mutator Methods getGalleons: int getSickles: int getKnuts: int setGalleons(int) setSickles(int) setKnuts(int) 8

Deposit public static void main(String[] args) { Account potter = new Account();. potter.deposit(5, 7, 9); public void deposit(int g, int s, int k) { galleons+=g; sickles+=s; knuts+=k; } 9

Withdrawal public void withdrawal(int g, int s, int k) { if((g > galleons) || (s > sickles) || (k > knuts)) { System.out.println("You do not have enough money"); } else { galleons -= g; sickles -= s; knuts -= k; } } public static void main(String[] args) { Account potter = new Account();. potter.withdrawal(5, 7, 9); 10

Inquire public void inquire() { System.out.println("You now have: " + galleons + " galleons " + sickles + " sickles " + knuts + " knuts"); } public static void main(String[] args) { Account potter = new Account();. potter.inquire(); 11

Type Casting (int)var (float)var (double)var 12

Type Casting var56.234…0.321 (int)var560 (double)var …0.321 (float)var …0.321 (short)var560 13

byteshortintlongfloatdouble byte short int long float double Type = ? 14

Type Case I want to put an int into a double? What do I do? Double myDouble = (double)myInt; 15

Wednesday Exam review Come with questions 16