1 CS2111 is no longer required for affiliation with Computer Science How to install newest Java Royal Flush is better than Full.

Slides:



Advertisements
Similar presentations
Topics Introduction Types of Errors Exceptions Exception Handling
Advertisements

Computer Science 209 Images and GUIs. Working with Java Colors The class java.awt.Color includes constants, such as Color.red, for some commonly used.
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
1 For more info: CS Sep 2008 In 1968, the Defense Department hired Bolt Beranek and Newman (BBN) of Boston to.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
Chapter 10 Introduction to Arrays
1 CS Sept. Customizing a class & testing Quiz 2 on Tuesday 15 Sept Purpose of a constructor (slide 5) Evaluating a new expression (slide 6) Fields;
GUIs Part 4 CS221 – 4/17/09. Professional Assignments Assignment #2 – Download and install Visual Studio 2008 Professional Trial Software –
1 CS100J 1 February Customizing a class & testing Quote for the day: There is no reason anyone would want a computer in their home. - -Ken Olson,
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
1 CS100J 13 March 2006 Arrays. Reading: Secs 8.1, 8.2, 8.3. Listen to the following lectures on loops on your Plive CD. They are only 2-3 minutes long,
CS 177 Recitation Week 8 – Methods. Questions? Announcements  Project 3 milestone due next Thursday 10/22 9pm  Turn in with: turnin –c cs177=xxxx –p.
1 CS100J 14 March 2006 Arrays. Reading: Secs 8.1, 8.2, 8.3. Listen to the following lectures on loops on your Plive CD. They are only 2-3 minutes long,
1 CS100J 25 October 2006 Arrays. Reading: Secs 8.1, 8.2, 8.3. Listen to the following lectures on loops on your Plive CD. They are only 2-3 minutes long,
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Chapter 5 - Making Music: An On-Screen Piano
Io package as Java’s basic I/O system continue’d.
CC1007NI: Further Programming Week 8-9 Dhruba Sen Module Leader (Islington College)
1 Lecture 09 Iterators and Enumerations Reading for these lectures: Weiss, Section Iterator Interface. Much better is: ProgramLive, Section 12.3.
A First Book of ANSI C Fourth Edition
CS1110 lecture 5 14 Sept 2010 Testing; the class Object; toString; static variables & methods Reading for this lecture: Testing with JUnit (Appendix I.2.4.
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!
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
Chapter 7 Arrays. A 12-element array Declaring and Creating Arrays Arrays are objects that occupy memory Created dynamically with keyword new int c[]
CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Final Review Lecture 14.
Chapter 2: Java Fundamentals
Programming With Java ICS201 University Of Hail1 Chapter 13 Interfaces.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
Alice in Action with Java Chapter 14 Events and GUIs.
Concurrent Programming and Threads Threads Blocking a User Interface.
Xiaoying Gao Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, Victoria University of Wellington More Interfaces.
CS1110 lecture 5 8 Feb 2010 Testing; class Object; toString; static variables/methods Reading for this lecture: Testing with JUnit (Appendix I.2.4 & pp.
1 CS1110 lecture 4 9 Sept. Customizing a class & testing Classes: fields; getter & setter methods. Secs (p. 45) & 3.1 (pp. 105–110 only) Constructors.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
1 CS November Testing/Debugging. And Applications Read chapter 14, pp. 385–401 Prelim 2 Max 100 Median 82 Mean 78.3 Min * ***************************
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
Georgia Institute of Technology Creating Classes part 2 Barb Ericson Georgia Institute of Technology June 2006.
Review_6 AWT, Swing, ActionListener, and Graphics.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 27.1 Test-Driving the Drawing Shapes Application.
Arrays.
Java – An Object Oriented Language CS 307 Lecture Notes Lecture Weeks 5-6 Khalid Siddiqui.
Week 10 - Friday.  What did we talk about last time?  References and primitive types  Started review.
1 Royal Flush is better than Full House CS March 31 Testing/Debugging. Also, about A6 Read chapter 14, pp. 385–401 Prelim 2 is Thursday eve, 14.
1 Royal Flush is better than Full House CS March 2009 Testing/Debugging Read chapter 14, pp. 385–401.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Exceptions and Error Handling. Exceptions Errors that occur during program execution We should try to ‘gracefully’ deal with the error Not like this.
Last Revision. Question1 Novice Java programmers often write code similar to, class C { public int x;... }... C[] a = new C[10]; for(int i = 0; i < a.length;
JAVA GENERICS Lecture 16 CS2110 – Spring 2016 Photo credit: Andrew Kennedy.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
1 CS Oct 2008 Arrays. Reading: Secs 8.1, 8.2, 8.3 Listen to the following lectures on loops on your Plive CD. They are only 2-3 minutes long, and.
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
1 CS Sept Customizing a class & testing Quote for the day: There is no reason anyone would want a computer in their home. - -Ken Olson, founder.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
CSE 205 Exam 2 Review By Cheri Thompson and Katherine Kincade.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Chapter 10 – Exception Handling
“Form Ever Follows Function” Louis Henri Sullivan
Testing and Debugging.
Lambdas ---anonymous functions---
Lecture 14: Testing Testing used to verify object behavior through designed test suites Can test Classes – “unit” testing Object interactions – “integration”
Presentation transcript:

1 CS2111 is no longer required for affiliation with Computer Science How to install newest Java Royal Flush is better than Full House CS October 2008 Testing/Debugging Read chapter 14, pp. 385–401

Put several.wav arrays into a single one d1 a1 d2 a2 d3 a3 a1 v0 v1 v2 w0 w1 a2 x0 x1 x2 a3 2.wav file an array of double values: type double[] The file may have other things, talking about frequency or whatever. But when it is read in one gets an array of double values v0 v1 v2 w0 w1 x0 x1 x2 a4 d3 a4

3 Mozart’s WuerfelSpiel WurfelGUI WurfelSpiel StdAudio MNumber WurfelSpielTester Subclass of JFrame. It has all the buttons, panels, etc., that make up the GUI. It has methods that are called when a button is clicked or a measure number is clicked. Contains methods that you will write. toString(), create a waltz, put a bunch of measures into a single file, etc. Methods called from the GUI. Basic methods for reading a.wav file, playing a.wav file, playing a double array of values that make up a tune, etc. A JPanel that can be clicked on. Each instance is for a minuet or trio measure.

4 Connecting a GUI button to a method in WurfelSpiel public class WurfelGUI extends JFrame { JButton button1= new JButton("GO!"); // Create waltz from first row private String[] lastWS; // Last waltz constructed (null if none) private double[] lastWD; // Compression of last waltz (null if none) public static void create0() { lastWS=WurfelSpiel.create0Spiel(); System.out.println( "Waltz created from row 1"); lastWaltzD= null; } public void actionPerformed (ActionEvent e) { Object b= e.getSource(); if (!(b instanceof JButton)) { return; } JButton jb= (JButton) b; if (jb == button1) { create0(); return; } … called when a button is clicked public class WurfelSpiel { /** = array containing names of files in row 0 of minuet, trio */ public static String[] create0Spiel() { … } }

5 Listening to a GUI /** Process a click on of the buttons button1--button 6.*/ public void actionPerformed(ActionEvent e) { Object ob= e.getSource(); if (ob == button1) { { create0(); return; } if (ob == button2) {createRandom(); return; } if (ob == button3) {compress(); return; } if (ob == button4) {printLastWaltz(); return; } if (ob == button5) {playLastWaltz(); return; } if (ob == button6) {saveLastWaltz(); return; }

6 Type of d is int[][] (“int array array”, “an array of int arrays”) To declare variable d: int d[][]. To create a new array and assign it to d: d= new int[3][4]; To reference element at row r column c: d[r][c] number of rows number of cols Two-dimensional arrays b b.length one-dimensional array d rectangular array: 5 rows and 4 columns

7 Testing: Read chapter 14. Bug: Error in a program. Testing: Process of analyzing, running program, looking for bugs. Test case: A set of input values, together with the expected output. Debugging: Process of finding a bug and removing it. Exceptions: When an error occurs, like divide by 0, or s.charAt[I] when I = – 1, Java throws an exception. A lot —generally too much— information is provided.

8 Exceptions: When an error occurs, like divide by 0, or s.charAt[i] when i = – 1, Java throws an exception. 06 /** = String s truncated …. */ 07 public static String truncate5(String s) { 08 int b= 10 / 0; 09 if (s.length() <= 5) 10 return s; 11 return s.substring(0,5); 12 } ArithmeticException: / by zero at A4Methods.truncate5(A4Methods.java:8) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(….java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(….java:25) at java.lang.reflect.Method.invoke(Method.java:585) important part Turn on line numbering in DrJava. Preferences / Display Options call stack

9 Debugging a program Strategy 0: Find a simplest possible test case that exhibits the error. When an error occurs, you have to play detective and find it. That process is called debugging. The place where the bug is may be far removed from the place where an error is revealed. Strategy 1: put print statements, suitably annotated, at judiciously chosen places in the program. Strategy 2: Use the debugging feature of your IDE (Interactive Development Environment —yours is DrJava.

10 Debugging a program public static HSV RGB2HSV(Color rgb) { … /**Figure out MAX and MIN* double MAX= 0; double MIN= 0; if (R>G && R>B) {MAX= R; } if (G>B && G>R) {MAX= G;} if (B>R && B>G) {MAX= B;} if (R<G && R<B) {MIN= R; } if (G<B && G<R) {MIN= G; } if (B<R && B<G) {MIN= B;} When an error occurs, play detective and find it. Called debugging. The place where the bug is may be far removed from the place where an error is revealed. System.out.println("R " + R + ", G " + G + ", B ” + B + ", MAX " + MAX); If you just output the numbers without naming them, you will have trouble.

11 public static HSV RGB2HSV(Color rgb) { … if (R>G && R>B) {MAX= R; } if (G>B && G>R) {MAX= G;} if (B>R && B>G) {MAX= B;} if (R<G && R<B) {MIN= R; } if (G<B && G<R) {MIN= G; } if (B<R && B<G) {MIN= B;} System.out.println("R " + R + ", G " + G + ", B ” + B + ", MAX " + MAX); > A4Methods.RGB2HSV(new java.awt.Color(255,255,128)) R 1.0, G 1.0, B 0.502, MAX 0.0 Look! MAX is 0 and not 1! call and output if conditions should be >=, not >

Other debugging solving tasks What’s wrong with this constructor in A5? It doesn’t compile /** Constructor: a new turtle that has a ball drawn at the turtle's position. The turtle is initially at the center of the panel, the pen is black, the ball's radius is r, and the ball moves with speed (vx, vy). */ public A5J(double vx, double vy, double r){ this(getWidth(), getHeight(),r, Color.black, vx, vy); } Error: cannot reference this before supertype constructor has been called

13 Debugging 1. Problem with drawing square flake 2. Coloring Sierpinski triangles