COMP 110 Worksheet review, debugger Luv Kohli September 29, 2008 MWF 2-2:50 pm Sitterson 014.

Slides:



Advertisements
Similar presentations
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Advertisements

1 Chapter 4 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference l Parameter passing Classes, Objects, and Methods.
Defining classes and methods Recitation – 09/(25,26)/2008 CS 180 Department of Computer Science, Purdue University.
COMP 110 Loops Tabitha Peck M.S. February 11, 2008 MWF 3-3:50 pm Philips
Classes, Objects, and Methods
The Type boolean. Boolean Expressions and Boolean Variables  The type boolean is a primitive type  Variables of type boolean and Boolean expressions.
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
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
COMP Classes Yi Hong May 22, Announcement  Lab 2 & 3 due today.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson
Catie Welsh January 12, 2011 MWF 1-1:50 pm Sitterson
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
CSC 212 – Data Structures Lecture 12: Java Review.
The Java Programming Language
COMP 110: Introduction to Programming Tyler Johnson Feb 2, 2009 MWF 11:00AM-12:15PM Sitterson 014.
Chapter 3 Edited by JJ Shepherd
Lecture 2: Classes and Objects, using Scanner and String.
Bryce Canyon, Utah CSE 114 – Computer Science I Objects and Reference.
COMP Mid-Term Review Yi Hong May 27, 2015.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
COMP 110 Constructors Luv Kohli October 13, 2008 MWF 2-2:50 pm Sitterson 014.
Boolean expressions, part 2: Logical operators. Previously discussed Recall that there are 2 types of operators that return a boolean result (true or.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
Chapter 4Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 4 l Class and Method Definitions l Information Hiding and Encapsulation.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Day 5. Task: Implement your vending machine code into the program with JOptionPane I/O (modify it) it to me.
COMP 110 switch statements and while loops Luv Kohli September 10, 2008 MWF 2-2:50 pm Sitterson
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Data Types and Operations On Data Objective To understand what data types are The need to study data types To differentiate between primitive types and.
COMP Flow of Control: Branching 1 Yi Hong May 19, 2015.
COMP 150: Introduction to Object-Oriented Programming Lecturer: Dr. AJ Bieszczad 4-1 Chapter 4 l Class and Method Definitions l Information Hiding and.
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
COMP 110 Objects and references Luv Kohli October 8, 2008 MWF 2-2:50 pm Sitterson 014.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
COMP 110 Classes Luv Kohli October 1, 2008 MWF 2-2:50 pm Sitterson 014.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
COMP 110: Introduction to Programming Tyler Johnson Feb 16, 2009 MWF 11:00AM-12:15PM Sitterson 014.
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
COMP 110 More loops Luv Kohli September 15, 2008 MWF 2-2:50 pm Sitterson
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
COMP 110 Branching Statements and Boolean Expressions Luv Kohli September 8, 2008 MWF 2-2:50 pm Sitterson
COMP 110 Designing and overloading methods Luv Kohli November 3, 2008 MWF 2-2:50 pm Sitterson 014.
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
A High Flying Overview CS139 – Fall 2006 How far we have come.
COMP 110 Some notes on inheritance, review Luv Kohli December 1, 2008 MWF 2-2:50 pm Sitterson 014.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
Catie Welsh March 4,  Midterm on Monday, March 14th ◦ Closed books, no notes, no computer  No office hours during Spring Break ◦ However, I will.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
© 2004 Pearson Addison-Wesley. All rights reserved January 23, 2006 Creating Objects & String Class ComS 207: Programming I (in Java) Iowa State University,
COMP 110 Augustus Gloop, Augustus Gloop… Luv Kohli September 24, 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.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
CompSci 230 S Programming Techniques
Michele Weigle - COMP 14 - Spr 04 Catie Welsh February 21, 2011
COMP 110 Review for midterm exam
Loop Structures.
Building Java Programs Chapter 2
Building Java Programs
February , 2009 CSE 113 B.
Announcements Assignment 2 and Lab 4 due Wednesday.
Unit 3: Variables in Java
Announcements Lab 3 was due today Assignment 2 due next Wednesday
Presentation transcript:

COMP 110 Worksheet review, debugger Luv Kohli September 29, 2008 MWF 2-2:50 pm Sitterson 014

Announcements Lab 4 due Wednesday, 2pm ◦ Remember to also print out your code and hand it in Extra office hours before Wednesday’s class? 2

Questions? Any further questions on Lab 3? How is Lab 4 going? 3

Today in COMP 110 Some comments about the type boolean and boolean expressions Go over in-class worksheet Debugger Revisiting classes 4

boolean type Can be either true or false Choose variable names that sound true when the value is true boolean isAlive = true; boolean isPositive = false; boolean systemsAreOK = true; if (isAlive)... if (isPositive)... if (systemsAreOK)... 5

boolean type Can give boolean variable the value of a boolean expression by using an assignment statement int number = -5; boolean isPositive = (number > 0); 6

boolean type Once boolean variable has a value, you can use it just like any other boolean expression int number = -5; boolean isPositive = (number > 0); if (isPositive) System.out.println(“The number is positive”); else System.out.println(“The number is not positive”); 7

boolean type Can use more complicated expressions also boolean systemsAreOK = (temperature <= 100) && (thrust >= 12000) && (cabinPressure > 30); 8

Review in-class worksheet 9

&& vs. &, || vs. | In the if statement below, is the boolean expression true or false? int temperature = 100; int rainFall = 40; int humidity = 70; if ((temperature > 95) || (rainFall > 20) || (humidity >= 60)) 10

&&, ||: short-circuit evaluation Evaluate the first subexpression ◦ If that is enough information, do not evaluate subsequent subexpressions if ((temperature > 95) || (rainFall > 20) || (humidity >= 60)) if ((assignmentsDone > 0) && ((totalScore / assignmentsDone) > 60)) 11

&, |: complete evaluation Evaluate all subexpressions, always What is wrong with this if statement? if ((assignmentsDone > 0) & ((totalScore / assignmentsDone) > 60)) Possible divide by 0 error! ◦ assignmentsDone could be 0 Usually do not want or need to use complete evaluation 12

&, |: bitwise operators &, | are not valid as boolean logical operators in many C-based languages Usually, they are bitwise operators ◦ In Java, can be used as boolean logical operators or bitwise operators More advanced, will not discuss bitwise operators now 13

Finding errors Trace your variables ◦ Put output statements in your code to see what values are stored in your variables  System.out.println(variable);  Check whether the values are correct and what you expect ◦ Remove these extra output statements after the program runs correctly ◦ Read example in the book, p. 188 (4 th edition), p. 218 (5 th edition) Use a debugger 14

Debugger in jGRASP Read sections 2.10, of jGRASP tutorial (linked off of course schedule) Try using debugger on your programs It will not help if your program does not compile! 15

Classes and Objects Java programs (and programs in other object-oriented programming languages) consist of objects of various class types Objects can represent objects in the real world ◦ Automobiles, houses, employee records Or abstract concepts ◦ Colors, shapes, words 16

Class A class is the definition of a kind of object ◦ A blueprint for constructing specific objects 17 Class Name: Automobile Data: amount of fuel speed license plate Methods (actions): accelerate: How: Press on gas pedal. decelerate: How: Press on brake pedal.

Objects, Instantiation 18 Object Name: patsCar amount of fuel: 10 gallons speed: 55 miles per hour license plate: “135 XJK” Object Name: suesCar amount of fuel: 14 gallons speed: 0 miles per hour license plate: “SUES CAR” Object Name: ronsCar amount of fuel: 2 gallons speed: 75 miles per hour license plate: “351 WLF” Instantiations, or instances, of the class Automobile

UML (Universal Modeling Language) 19 Automobile - fuel: double - speed: double - license: String + accelerate(double pedalPressure): void + decelerate(double pedalPressure): void Class name Data Methods (actions)

Something we’ve seen before Automobile suesCar = new Automobile(); Scanner keyboard = new Scanner(System.in); 20 Create an object Return memory address of object Assign memory address of object to variable

Wednesday Lab 4 due, 2pm Go over program 2 21