U.S. States/Capitals Political Map States/Capitals 12345678910.
6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style...
Transcript of 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style...
![Page 1: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/1.jpg)
6.092: Introduction to Java 6: Design, Debugging,
Interfaces
![Page 2: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/2.jpg)
Assignment 5: main()
Programs start at a main() method, butmany classes can have main()
public class SimpleDraw { /* ... stuff ... */ public static void main(String args[]) { SimpleDraw content = new SimpleDraw(new DrawGraphics()); /* ... more stuff ... */
} }
![Page 3: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/3.jpg)
Assignment 5: main()
Programs start at a main() method, butmany classes can have main()
public class SimpleDraw { /* ... stuff ... */ public static void main(String args[]) { SimpleDraw content = new SimpleDraw(new DrawGraphics()); /* ... more stuff ... */
} }
![Page 4: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/4.jpg)
public class DrawGraphics { BouncingBox box;
public DrawGraphics() { box = new BouncingBox(200, 50, Color.RED);
}
public void draw(Graphics surface) { surface.drawLine(50, 50, 250, 250); box.draw(surface);
} }
![Page 5: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/5.jpg)
public class DrawGraphics { BouncingBox box; // a field or member variable
public DrawGraphics() { box = new BouncingBox(200, 50, Color.RED);
}
public void draw(Graphics surface) { surface.drawLine(50, 50, 250, 250); box.draw(surface);
} }
![Page 6: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/6.jpg)
public class DrawGraphics { BouncingBox box;
public DrawGraphics() { // constructor box = new BouncingBox(200, 50, Color.RED);
}
public void draw(Graphics surface) { surface.drawLine(50, 50, 250, 250); box.draw(surface);
} }
![Page 7: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/7.jpg)
public class DrawGraphics { public void draw(Graphics surface) {
surface.drawLine(50, 50, 250, 250); box.draw(surface); surface.fillRect (150, 100, 25, 40); surface.fillOval (40, 40, 25, 10); surface.setColor (Color.YELLOW); surface.drawString ("Mr. And Mrs. Smith", 200, 10);
} }
![Page 8: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/8.jpg)
public class DrawGraphics { ArrayList<BouncingBox> boxes = new ArrayList<BouncingBox>();
public DrawGraphics() { boxes.add(new BouncingBox(200, 50, Color.RED)); boxes.add(new BouncingBox(10, 10, Color.BLUE)); boxes.add(new BouncingBox(100, 100, Color.GREEN)); boxes.get(0).setMovementVector(1, 0); boxes.get(1).setMovementVector(-3, -2); boxes.get(2).setMovementVector(1, 1);
}
public void draw(Graphics surface) { for (BouncingBox box : boxes) {
box.draw(surface); }
} }
![Page 9: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/9.jpg)
Outline
Good program design
Debugging
Interfaces
![Page 10: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/10.jpg)
What is a good program?
Correct / no errors
Easy to understand
Easy to modify / extend
Good performance (speed)
![Page 11: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/11.jpg)
Consistency
Writing code in a consistent way makes iteasier to write and understand
Programming “style” guides: define rulesabout how to do things
Java has some widely accepted“standard” style guidelines
![Page 12: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/12.jpg)
Naming Variables: Nouns, lowercase first letter, capitals
separating words x, shape, highScore, fileName
Methods: Verbs, lowercase first letter getSize(), draw(), drawWithColor()
Classes: Nouns, uppercase first letter Shape, WebPage, EmailAddress
![Page 13: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/13.jpg)
Good Class Design Good classes: easy to understand and use
• Make fields and methods private by default • Only make methods public if you need to • If you need access to a field, create a
method:
public int getBar() { return bar; }
![Page 14: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/14.jpg)
Debugging
The process of finding and correcting anerror in a program
A fundamental skill in programming
![Page 15: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/15.jpg)
Step 1: Donʼt Make Mistakes
Donʼt introduce errors in the first place
![Page 16: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/16.jpg)
Step 1: Donʼt Make Mistakes
Donʼt introduce errors in the first place
• Reuse: find existing code that doeswhat you want
• Design: think before you code • Best Practices: Recommended
procedures/techniques to avoidcommon problems
![Page 17: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/17.jpg)
Design: Pseudocode
A high-level, understandable descriptionof what a program is supposed to do
Donʼt worry about the details, worry aboutthe structure
![Page 18: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/18.jpg)
Pseudocode: Interval Testing
Example: Is a number within the interval [x, y)?
If number < x return false If number > y return false Return true
![Page 19: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/19.jpg)
Design
Visual design for objects, or how aprogram works
Donʼt worry about specific notation, justdo something that makes sense for you
Scrap paper is useful
![Page 20: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/20.jpg)
SimpleDraw
DrawGraphics
ArrayList
BouncingBox BouncingBox BouncingBox
![Page 21: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/21.jpg)
Step 2: Find Mistakes Early
Easier to fix errors the earlier you findthem
• Test your design • Tools: detect potential errors • Test your implementation • Check your work: assertions
![Page 22: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/22.jpg)
Testing: Important Inputs
Want to check all “paths” through the program.
Think about one example for each “path”
Example: Is a number within the interval [x, y)?
![Page 23: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/23.jpg)
Intervals: Important Cases
Below the lower bound Equal to the lower bound Within the interval Equal to the upper bound Above the upper bound
![Page 24: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/24.jpg)
Intervals: Important Cases
What if lower bound > upper bound?
What if lower bound == upper bound?
(hard to get right!)
![Page 25: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/25.jpg)
Pseudocode: Interval Testing
Is a number within the interval [x, y)?
If number < x return false If number > y return false Return true
![Page 26: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/26.jpg)
Pseudocode: Interval Testing
Is a number within the interval [x, y)?
Is 5 in the interval [3, 5)?
If number < x return false If number > y return false Return true
![Page 27: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/27.jpg)
Pseudocode: Interval Testing
Is a number within the interval [x, y)?
Is 5 in the interval [3, 5)?
If number < x return false If number >= y return false Return true
![Page 28: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/28.jpg)
Tools: Eclipse Warnings
Warnings: may not be a mistake, but itlikely is.
Suggestion: always fix all warnings
Extra checks: FindBugs and related tools Unit testing: JUnit makes testing easier
![Page 29: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/29.jpg)
Assertions
Verify that code does what you expect
If true: nothing happens If false: program crashes with error Disabled by default (enable with ‐ea)
assert difference >= 0;
![Page 30: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/30.jpg)
void printDifferenceFromFastest(int[] marathonTimes) { int fastestTime = findMinimum(marathonTimes);
for (int time : marathonTimes) { int difference = time - fastestTime; assert difference >= 0; System.out.println("Difference: " + difference);
} }
![Page 31: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/31.jpg)
Step 3: Reproduce the Error
• Figure out how to repeat the error • Create a minimal test case
Go back to a working version, andintroduce changes one at a time untilthe error comes back
Eliminate extra stuff that isnʼt used
![Page 32: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/32.jpg)
Step 4: Generate Hypothesis
What is going wrong? What might be causing the error?
Question your assumptions: “x canʼt be possible:” What if it is, due to somethingelse?
![Page 33: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/33.jpg)
Step 5: Collect Information
If x is the problem, how can you verify?Need information about what is going on inside the program
System.out.println() is very powerful
Eclipse debugger can help
![Page 34: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/34.jpg)
Step 6: Examine Data
Examine your data
Is your hypothesis correct?
Fix the error, or generate a newhypothesis
![Page 35: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/35.jpg)
Why Use Methods?
Write and test code once, use it multipletimes: avoid duplication
Eg. Library.addBook()
![Page 36: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/36.jpg)
Why Use Methods?
Use it without understanding how it works: encapsulation / information hiding
Eg. How does System.out.println() work?
![Page 37: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/37.jpg)
Why Use Objects?
Objects combine a related set of variablesand methods
Provide a simple interface
(encapsulation again)
![Page 38: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/38.jpg)
Implementation / Interface
Library
Book[] books; int numBooks; String address;
void addBook(Book b) { books[numBooks] = b; numBooks++; }
Library
void addBook(Book b);
![Page 39: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/39.jpg)
Java Interfaces
Manipulate objects, without knowing howthey work
Useful when you have similar but notidentical objects
Useful when you want to use code writtenby others
![Page 40: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/40.jpg)
Interface Example: Drawing public class BouncingBox {
public void draw(Graphics surface) { // … code to draw the box …
} }
// … draw boxes … for (BouncingBox box : boxes) {
box.draw(surface); }
![Page 41: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/41.jpg)
Interface Example: Drawing public class Flower {
public void draw(Graphics surface) { // … code to draw a flower …
} }
// … draw flowers … for (Flower flower : flowers) {
flower.draw(surface); }
![Page 42: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/42.jpg)
public class DrawGraphics { ArrayList<BouncingBox> boxes = new ArrayList<BouncingBox>(); ArrayList<Flower> flowers = new ArrayList<Flower>(); ArrayList<Car> cars = new ArrayList<Car>();
public void draw(Graphics surface) { for (BouncingBox box : boxes) {
box.draw(surface); } for (Flower flower : flowers) {
flower.draw(surface); } for (Car car : cars) {
car.draw(surface); }
} }
![Page 43: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/43.jpg)
public class DrawGraphics { ArrayList<Drawable> shapes = new ArrayList<Drawable>(); ArrayList<Flower> flowers = new ArrayList<Flower>(); ArrayList<Car> cars = new ArrayList<Car>();
public void draw(Graphics surface) { for (Drawable shape : shapes) {
shape.draw(surface); } for (Flower flower : flowers) {
flower.draw(surface); } for (Car car : cars) {
car.draw(surface); }
} }
![Page 44: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/44.jpg)
Interfaces
Set of classes that share methods
Declare an interface with the common methods
Can use the interface, without knowing anobjectʼs specific type
![Page 45: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/45.jpg)
Interfaces: Drawable import java.awt.Graphics;
interface Drawable { void draw(Graphics surface);
void setColor(Color color); }
![Page 46: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/46.jpg)
Implementing Interfaces
Implementations provide completemethods:
import java.awt.Graphics; class Flower implements Drawable {
// ... other stuff ... public void draw(Graphics surface) {
// ... code to draw a flower here ... }
}
![Page 47: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/47.jpg)
Interface Notes
Only have methods (mostly true)
Do not provide code, only the definition(called signatures)
A class can implement any number ofinterface
![Page 48: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/48.jpg)
Using Interfaces
Can only access stuff in the interface.
Drawable d = new BouncingBox(…); d.setMovementVector(1, 1);
The method setMovementVector(int, int) is undefined for the type Drawable
![Page 49: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/49.jpg)
Casting
If you know that a variable holds aspecific type, you can use a cast:
Drawable d = new BouncingBox(…); BouncingBox box = (BouncingBox) d; box.setMovementVector(1, 1);
![Page 50: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/50.jpg)
Assignment: More graphics
Start a new project: code has changed.
![Page 51: 6.092 Lecture 6: Design, Debugging, Interfaces...Java has some widely accepted “standard” style guidelines. Naming Variables: Nouns, lowercase first letter, capitals separating](https://reader030.fdocuments.net/reader030/viewer/2022040901/5e70be70c4da2947bf143926/html5/thumbnails/51.jpg)
MIT OpenCourseWarehttp://ocw.mit.edu
6.092 Introduction to Programming in Java January (IAP) 2010
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.