1 Review for exam 2 CS 101 Spring 2005 Aaron Bloomfield.

Slides:



Advertisements
Similar presentations
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Advertisements

The Line Class Suppose you are involved in the development of a large mathematical application, and this application needs an object to represent a Line.
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, toString reading: self-checks: #13-18,
Written by: Dr. JJ Shepherd
Collections & Loops Chapter 5 Copyright © 2012 Pearson Education, Inc.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CS 106 Introduction to Computer Science I 03 / 24 / 2008 Instructor: Michael Eckmann.
CS180 Chapter 4 2/1/08. Announcements Project 3 is out –2 weeks due to the exam Exam –Thursday, February 7, 8:30 – 9:30 pm, WTHR 104 –Covers chapters.
Understanding class definitions Looking inside classes.
Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Writing Classes (Chapter 4)
Classes and Objects. Topics The Class Definition Declaring Instance Member Variables Writing Instance Member Methods Creating Objects Sending Messages.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
CS 106 Introduction to Computer Science I 03 / 19 / 2007 Instructor: Michael Eckmann.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
CS 101E – Exam 2 Review Spring 2007 Michele Co. Announcements Review Session Tonight, 7/7:30 p.m., OLS 009 Will be announced via In-class Exam Wednesday.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
C# Programming Fundamentals Control Flow Jim Warren, COMPSCI 280 S Enterprise Software Development.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
1 The Stack Class Final Review Fall 2005 CS 101 Aaron Bloomfield.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Defining Classes II. Today’s topics  Static methods  Static variables  Wrapper classes  References  Class parameters  Copy constructor.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Understanding class definitions
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Programming with methods and classes. Methods  Instance method Operates on a object (i.e., and instance of the class) String s = new String("Help every.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Methods OR HOW TO MAKE A BIG PROGRAM SEEM SMALLER.
Programming with methods and classes Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Written by: Dr. JJ Shepherd
1 Static Variable and Method Lecture 9 by Dr. Norazah Yusof.
Announcements Final Exam: TBD. Static Variables and Methods static means “in class” methods and variables static variable: one per class (not one per.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
1 Review for Midterm 2 Aaron Bloomfield CS 101-E.
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade Know: loops, switch/case Files Input failure (e.g. scan.hasNextInt())
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Staples are our staple Building upon our solution.
Section 2.2 The StringLog ADT Specification. 2.2 The StringLog ADT Specification The primary responsibility of the StringLog ADT is to remember all the.
Classes and Objects.
Creating Your OwnClasses
An Introduction to Java – Part I
CS 302 Week 11 Jim Williams, PhD.
Programming with methods and classes
Initializing Arrays char [] cArray3 = {'a', 'b', 'c'};
Lecture 8-3: Encapsulation, this
Classes Variables That Are Not of a Built-in Type Are Objects
Building Java Programs
Building Java Programs
ITunes Lab Copyright © 2012 Pearson Education, Inc.
Building Java Programs
CS 302 Week 9 Jim Williams.
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade
Today’s topics UML Diagramming review of terms
CS139 October 11, 2004.
Building Java Programs
Outline Anatomy of a Class Encapsulation Anatomy of a Method
Instance Method – CSC142 Computer Science II
CIS 199 Final Review.
Introduction to Object-Oriented Programming
Building Java Programs
Building Java Programs
Objects with ArrayLists as Attributes
What to expect this week
Review for Midterm 3.
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Announcements Lab 5 due Wednesday at noon.
Day 11 The Last Week!.
Presentation transcript:

1 Review for exam 2 CS 101 Spring 2005 Aaron Bloomfield

2 What’s on the exam Creating class (chapter 4) Examples we’ve seen Examples we’ve seenColoredRectangleCarRationalCircle Decisions (chapter 5) If, if-else, if-else-if If, if-else, if-else-if Switch Switch Iteration (chapter 6) You just have to be able to analyze while loops You just have to be able to analyze while loops

3 The Tune class Used to represent a song from a CD collection Properties: artist artist title title album album length length These will be implemented as instance variables private String artist private String artist private String title private String title private String album private String album private int length private int length

4 Tune behaviors Creating a new Tune object AccessorsMutators Checking if two tunes have the same artist or are on the same album

5 Exercise 1: Default constructor The default constructor initializes the Tune to “Mary Had a Little Lamb” That’s the first audio track ever recorded That’s the first audio track ever recorded public Tune () { setArtist (“Thomas Edison”); setTitle (“Mary Had a Little Lamb”); setAlbum (“Mary Had a Little Lamb”); setLength (15); } Note we haven’t declared the mutators yet! But we assume they are there and that they exist But we assume they are there and that they exist

6 Exercise 1: Method sameArtist() This method will compare two objects to see if they have the same artist The two objects are: The two objects are: The current object that the method is executing from The object passed in as a parameter public boolean sameArtist (Tune that) { String thisArtist = getArtist(); String thatArtist = that.getArtist(); if ( thisArtist.equals(thatArtist) ) { return true; } else { return false; }} Again, we are assuming that the accessors exist

7 Exercise 1: Method sameArtist() This method will compare two objects to see if they have the same artist The two objects are: The two objects are: The current object that the method is executing from The object passed in as a parameter public boolean sameArtist (Tune that) { String thisArtist = getArtist(); String thatArtist = that.getArtist(); return thisArtist.equals(thatArtist); } Again, we are assuming that the accessors exist

8 Give a memory diagram for the following: Tune t1 = new Tune(); Tune t2 new Tune( "Neil Young", "I Am the Ocean". "Mirror Ball", 428); Exercise 2: Memory diagram t1 - artist = - title = - album = - length = Tune + Tune() + Tune (String, String, String, String) + boolean sameArtist (Tune that) + … “Thomas Edison” “Mary had a little lamb” 15 “Thomas Edison” “Mary had a little lamb” t2 - artist = - title = - album = - length = Tune + Tune() + Tune (String, String, String, String) + boolean sameArtist (Tune that) + … “Neil Young” “I Am the Ocean” “Mirror Ball” 15 “Neil Young” “I Am the Ocean” “Mirror Ball”

9 Exercise 3: Memory diagram Update your memory diagram from the second exercise so that it also include the initial activation record depiction of sameArtist() for the following invocation t1.sameArtist(t2) We’ll not be going over this question As we haven’t studied activation records As we haven’t studied activation records

10 About the Tune class We will be using that class on the exam…

11 // Representation of a musical track public class Tune { // instance variables for attributes private String artist; // Performer of the piece private String title; // Name of the track private int year; // Release year // default constructor public Tune() { setArtist("Thomas Alva Edison"); setTitle("Mary had a little lamb"); setYear(1877);} // mutators public void setArtist(String performer) { artist = performer; } public void setTitle(String track) { title = track; } public void setYear(int date) { year = date; }

12 // stringifier public String toString() { String performer = getArtist(); String track = getTitle(); int date = getYear(); String result = "Tune( " + performer + ", " + track + ", " + date + " )"; return result; } // demo public static void main(String[] args) { Tune tune1 = new Tune(); Tune tune2 = new Tune(); tune2.setArtist("Paul McCartney"); tune2.setYear(1972); System.out.println( "tune1 = " + tune1 ); System.out.println( "tune2 = " + tune2 ); System.out.println( "artists match: " + tune1.sameArtist(tune2) ); System.out.println( "titles match: " + tune1.sameTitle(tune2) ); }//...}

13 Quick survey I feel I understand the Tune class… I feel I understand the Tune class… a) Very well b) With some review, I’ll be good c) Not really d) Not at all

14 Quick survey How comfortable and prepared do you feel for the exam? How comfortable and prepared do you feel for the exam? a) I’m gonna get a 100! b) More or less comfortable c) Uncomfortable d) Exam? What exam?!?!?

15 Today’s demotivators