{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# lecture9 - Administrative Issues Introduction to Classes...

This preview shows pages 1–4. Sign up to view the full content.

Introduction to Classes Lecture 9 Administrative Issues Homework 2 assigned today – Due Thursday, June 5 Program 2 ongoing – Due Wednesday June 4 Midterm scheduled for Friday! Homework #1 Review (1/4) Problem 2.6, parts 4 and 5 int iResult, num1=25, num2=40, num3=17, num4=5; double fResult, val1=17.0, val2=12.78; fResult = num3 / num4; = 17 / 5; = 3; (by integer division) = 3.0; (by assignment conversion) fResult = val1 / num4; = 17.0 / 5; = 17.0 / 5.0; (by arithmetic promotion) = 3.4; Homework #1 Review (2/4) Problem 2.6, parts 9 and 10 int iResult, num1=25, num2=40, num3=17, num4=5; double fResult, val1=17.0, val2=12.78; fResult = ( double ) num1 / num2; = 25.0 / 40; (by casting) = 25.0 / 40.0; (by arithmetic promotion) = 0.625; fResult = num1 / ( double ) num2; = 25 / 40.0; (by casting) = 25.0 / 40.0; (by arithmetic promotion) = 0.625; fResult = ( double ) (num1 / num2); = 25 / 40; = 0; (by integer division) = 0.0; (by casting) Recall that an if / else statement is a single statement! Homework #1 Review (3/4) Problem 3.3 if (total == MAX) if (total < sum) System.out.println(“total == MAX and is < sum.”); else System.out.println(“total is not equal to MAX”); if (total == MAX) { if (total < sum) System.out.println(“total == MAX and is < sum.”); } else System.out.println(“total is not equal to MAX”); Homework #1 Review (4/4) Problem 3.4 if (length = MIN_LENGTH) System.out.println(“The length is minimal.”); (length = MIN_LENGTH) is not a boolean expresssion. The equality operator ( == ) should be used instead of the assignment operator ( = ).

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Objects We’ve created and/or used lots of objects String objects Random objects These objects belong to a class String Random So far, all have been part of the Standard Java Library Standard Classes Until today, we’ve used standard classes We are ignorant of how they work Abstraction Just trust that they work Writing Our Own Classes Today’s topic: Writing our own classes But first… – An in-depth look at the concept of objects The World As Objects Objects exist in the world around us – Desks – Books – Students – Buildings – Trees – Roads – Cars Object Attributes How would you describe an object? Example: Car Car has many characteristics – Model Year – Color – Number of Doors – Weight There are a Car’s attributes Object Behaviors A car can do many things – Open a door – Start the ignition – Play a CD – Lock the doors – Accelerate These define a car’s behavior
Objects All objects are defined by – Attributes (or state ) – Behaviors An object’s variables define it’s attributes (or state) Methods define behaviors A Driving Simulator Consider a driving video game

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}