The Vic Class. a1 b e g end. a d2 end. a3 b e g3 h3 end. a d4 e4 end. GarthB LyleL stack
|
|
- Timothy Hoover
- 5 years ago
- Views:
Transcription
1 Conditionals
2 The Vic Class a1 b e g end a d2 end a3 b e g3 h3 end GarthB LyleL stack a d4 e4 end
3 The Vic Class 1. The Vic class simulates a CD changer. 2. You can have 1 to 4 rows of CDs. 3. Each row can have 1 to eight slots for storing CDs. 4. CDs can be stored on a stack when they are not in a slot. 5. Each row has a current slot indicated by a stick figure. 6. The stick figure can move one place past the last slot in a row.
4 The Vic Class public static void main( String[]args ) Vic jane = new Vic(); Vic sally = new Vic(); jane sally a1 b e g end a d2 end a
5 The Vic Class Vic jane = new Vic(); Vic sally = new Vic(); jane.moveon(); jane sally a1 b e g end a d2 end a
6 The Vic Class... jane.moveon(); sally.moveon(); sally.moveon(); jane sally a1 b e g end a d2 end a
7 The Vic Class... sally.moveon(); jane.takecd(); jane sally b1 a e g end a d2 end to stack a b1 3 GarthB LyleL stack
8 The Vic Class... jane.takecd(); sally.putcd(): jane a e g end sally a b1 d2 end from stack a GarthB Lyle stack
9 The Vic Class public static void main( String[]args ) Vic.reset( args ); > java VicProgram a1 b e g end a d2 end a Use the java command to create a predictable number of rows and slots.
10 The Vic Class public static void main( String[]args ) Vic.reset( args ); > java VicProgram # a1 b e g end a d2 end Calexico a GarthB ---- LyleL 3 stack Use the java command to create a predictable stack configuration.
11 The Move On Method The moveon method takes no arguments. It advances the simulator "arm." moveon() This method tells the Vic simulator to advance an arm to the next position. If the arm is at the last slot it is advanced to the end position. You must not try to advance the arm past the end position.
12 The Back Up Method The backup method takes no arguments. It reverses the simulator "arm." backup() This method tells the Vic simulator to move an arm to the previous position. You must not try to move the arm before the first position.
13 The Take CD Method The takecd method takes no arguments. It moves a CD from a slot to the stack. takecd() This method tells the Vic simulator to take the CD from the current slot and add it to the stack. If there is no CD in the current slot no action is taken.
14 The Put CD Method The putcd method takes no arguments. It moves a CD from the stack to a slot. putcd() This method tells the Vic simulator to remove the CD at the top of the stack and put it in the current slot. If the stack is empty no action is taken.
15 The Say Method The say class method takes one argument; it tells the Vic simulator to print a message. Vic.say( message ) This method causes the Vic simulator to print a message in the white bar at the top of the simulator window. The previous message, if any, is erased. Message goes here a e end
16 The Reset Method The reset class method takes one argument; it tells the Vic simulator how to configure the rows, slots and stack. Vic.reset( strings[] ) This method tells the Vic simulator how many rows to make, how many slots to put in each row, and, optionally, how many items to put on the stack. (See previous slides for examples.)
17 Exercises 1. Write a program that uses the reset method to create a Vic simulator with three rows; the first should have 5 slots, alternating empty and occupied; the second should have 3 slots, all occupied; the third should have 6 empty slots. 2. Write a program to create a Vic simulator with 2 rows of 6 slots each, and 7 items on the stack. 3. In the following exercises ignore the instructions that make assumptions about the configuration of a row or the stack; instead, use reset( args ) to ensure that the rows and/or stack are properly created. Textbook, Chapter 2, page 2 6: Exercises
18 The SmartVic Class public class SmartVic extends Vic public void movetake() moveon(); takecd(); public void backput() backup(); putcd(); movetake is an instance method (not static) Commands apply to the default executor SmartVic is a sublcass of Vic
19 Testing the SmartVic Class public class Test public static void main (String[] args) Vic.reset( args ); SmartVic tim = new SmartVic(); tim.movetake(); tim.movetake(); tim.backput(); tim.backput();
20 Review subclass SmartVic is a subclass of Vic. extends SmartVic extends Vic. inherit SmartVic inherits from Vic. superclass Vic is a superclass of SmartVic. class method Vic.reset is a class method. instance method movetake is an instance method.
21 Exercises 1. Write and compile SmartVic.java. 2. Write a program to test the SmartVic class. 3. Textbook, Chapter 2, page page 2 9: Exercises
22 Boolean Values A Boolean value can be either true or false. In java, a Boolean value is represented by one of the keywords true or false. Examples: It is true that a cow is a mammal. It is true that a SmartVic is a Vic. It is false that all Turtles are SmartTurtles.
23 Boolean Types A variable or expression that can only be true or false is type boolean: boolean firstone = true; A method can be boolean, which means that it returns true or false: public class TurtlePlus extends Turtle public boolean areyouarabbit() return false; public boolean areyouaturtle() return true;
24 The If Statement The if statement can be used to test a boolean value: public class TestIf public static void main( String[] args ) TurtlePlus timmy = new TurtlePlus(); if ( timmy.areyouaturtle() ) timmy.say( "I knew it!" );
25 The If Statement The if statement has two forms: 1. if condition statement If condition is true execute statement, otherwise skip to the first line following statement. public class TestIf public static void main( String[] args ) TurtlePlus timmy = new TurtlePlus(); if ( timmy.areyouarabbit() ) timmy.say( "I knew it!" ); timmy.say( "next line starts here" );
26 The If Statement (continued) 2. if condition statements If condition is true execute all the statements inside the braces, otherwise skip to the next line following the right brace: public class TestIf static public void main( String[] args ) TurtlePlus timmy = new TurtlePlus(); if ( timmy.areyouaturtle() ) timmy.say( "I knew it!" ); timmy.paint( 90, 128 ); timmy.paint( -90, 64 );
27 Nested If Statements An if statement can be nested within another if statement: if ( conda ) if ( condb ) if ( condc ) do something do something // if condc is false, skip to here // if condb is false, skip to here // if conda is false, skip to here Note: Indenting nested if statements is not required but it makes your code far more readable.
28 The Sees Slot Method The seesslot method takes no arguments. It returns true if the given Vic is at a valid slot. if ( seesslot() ) moveon(); Question: when will the seesslot method return false?
29 The Sees CD Method The seescd method takes no arguments. It returns true if the given Vic has a CD in its current slot. if ( seescd() ) takecd(); Question: what will happen if you use this method while your Vic is at the end position of a row?
30 The Shifter Subclass public class Shifter extends Vic // If possible, shift the CD in slot 3 to slot 5. public void shiftthreetofive() if ( seesslot() ) // at position one moveon(); // move to position two if ( seesslot() ) moveon(); // move to position three if ( seesslot() ) if ( seescd() ) takecd(); moveon(); // move to position four if ( seesslot() ) moveon(); // move to position five if ( seesslot() ) putcd();
31 Exercises 1. Create and test the Shifter subclass. 2. Textbook, Chapter 2, page 2 12: Exercises
32 Review: Class vs. Instance Methods In the Vic class a method such as moveon refers to any one of up to four different "arms." To specify which arm is to be affected, invoke the method on a specific instance of a Vic. That makes moveon an instance method. The method stackhascd returns true if the simulator's stack contains at least one CD. The stack is independent of any single arm, so stackhascd is a class method. public class Test Class methods are invoked via public static void main (String[ ] args) the class name. Vic tim = new Vic(); if ( Vic.stackHasCD() ) Vic.say( "stack contains at least one CD." );
33 1. Textbook, Chapter 2, page page 2 15: Exercises Exercises
34 Block Statements A block statement, also called a compound statement,consists of one or more additional statements enclosed in braces: if ( tim.seesslot() ) Vic.say( "moving on" ); tim.moveon(); A block statement is considered a single statement, so we can say that if the condition in an if statement is true the next statement is executed; if the condition is false the next statement is skipped.
35 The Else Statement An else statement is always paired with an if statement: if ( condition ) is-true statement else is-false statement If condition is true, the is true statement is executed; if condition is false the is false statement is executed. Remember that you can always use a block statement to encapsulate multiple commands.
36 The Else Statement Example 1 public static void main( String[] args ) Vic.reset( args ); Vic tim = new Vic(); if ( tim.seesslot() ) Vic.say( "tim sees a slot" ); else Vic.say( "tim doesn't sees a slot" );
37 The Else Statement Example 2 public static void main( String[] args ) Vic.reset( args ); Vic tim = new Vic(); if ( tim.seesslot() ) Vic.say( "tim sees a slot" ); tim.moveon(); else Vic.say( "tim doesn't sees a slot" ); Vic.say( tim can t move on );
38 If Else Ladders When making a simple choice from several alternatives you can use an if else ladder, sometimes called a selection block or a case construction (your textbook calls it a multiway selection). if ( tim is an egg ) tim.scramble(); else if ( tim is a potato ) tim.boil(); else if ( tim is a fish ) tim.poach(); else if ( tim is a steak ) tim.grill(); else System.out.println( How should I cook tim?" );
39 Exercises 1. Write a program that: moves an arm to the third slot of a sequence if it can; if the third slot doesn't exist, say "third slot doesn't exist"... if the slot exists and contains a CD put the CD on the stack... if the slot exists and is empty, and if there is a CD on the stack, fill the slot... if the slot exists and is empty, and the stack is empty, say "I have been thwarted. 2. Textbook, Chapter 2, page 2 31: Exercise 2.42.
40 The Not Operator The not operator (!) is used to negate the value of a condition. If an "arm" labeled "tim" is currently at a slot: tim.seeslot(); will be true and!tim.seeslot(); will befalse.
41 Not Operator Example public static void main (String[ ] args) Vic tim = new Vic(); Vic fred = new Vic(); if ( tim.seesslot() ) Vic.say( "tim sees a slot" ); else Vic.say( "tim doesn't see a slot" ); if (!fred.seesslot() ) Vic.say( "fred doesn't see a slot" ); else Vic.say( "fred sees a slot" );
42 Review: Boolean Methods public class VicPlus extends Vic public boolean cantakecd() if ( seesslot() ) if ( seescd() ) return true; else return false; else return false; A return statement causes a method to terminate and return to the caller
43 Review: Boolean Methods, Example public class Test public static void main( String[] args ) VicPlus tim = new VicPlus(); if ( tim.cantakecd() ) Vic.say( "can take CD" ); else Vic.say( "cannot take CD" );
44 Boolean Methods You can use variables to simplify return logic. public class VicPlus extends Vic public boolean cantakecd() boolean rval = false; if ( seesslot() ) if ( seescd() ) rval = true; return rval;
45 1. Textbook, Chapter 2, page 2 21: Exercise , 2.28, Exercises
46 Boolean Operators: And The and operator (&&) evaluates the truth value of two conditions: conda && condb The above expression is true only if conda is true and condb is true. if ( tim.seesslot() && tim.seescd() ) tim.takecd();
47 Boolean Operators: Or The or operator ( ) evaluates the truth value of two conditions: conda condb The above expression is true if conda is true or condb is true. if ( tim.seescd()!vic.stackhascd() ) Vic.say( "can't put CD" );
48 Expressions An expression is any valid string of operators and operands, for example: / / 2!stackHasCD()!seesSlot() seescd() 1 rval = true rval = seesslot() &&!seescd() Java has some operators you won t be familiar with from math class, such as., =, (), []
49 Expression Evaluation Like arithmetic, operators have precedence and expressions are evaluated accordingly: / 2 5 is divided by two, then the result is added to 3 conda && condb condc conda is and'ed with condb, then the result is or'ed with condc Order of evaluation can be changed by introducing parentheses: (3 + 5) / 2 5 added to 3, then the result is divided by 2 conda && (condb condc) condb is or'ed with condc, then the result is and'ed with conda
50 Short Circuits In an expression involving and and or, the value of the first part of the expression will prevent the evaluation of the second part. This is called a short circuit. conda && condb if conda is false condb will not be evaluated. conda condb if conda is true condb will not be evaluated. if ( tim.seesslot() && tim.seescd() ) tim.takecd(); If tim can t see a slot he won t check for a CD.
51 1. Textbook, Chapter 2, page 2 25: Exercise Exercises
The While Statement. If boolean expression is true execute statement; continue to execute statement so long as boolean expression is true.
Variables and Loops The While Statement while ( boolean-expression ) statement If boolean expression is true execute statement; continue to execute statement so long as boolean expression is true. While
More informationZhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson
Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program
More informationDECISION STRUCTURES: USING IF STATEMENTS IN JAVA
DECISION STRUCTURES: USING IF STATEMENTS IN JAVA S o far all the programs we have created run straight through from start to finish, without making any decisions along the way. Many times, however, you
More informationPackages. 1. Every Java object resides in a package. 2. An object s package is explicitly declared on the first line of code in a.
Packages Packages 1. Every Java object resides in a package. 2. An object s package is explicitly declared on the first line of code in a.java file: package edu.pcwe.uw.javaintro.misc; public class HelloWorld
More informationLecture Set 4: More About Methods and More About Operators
Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static
More informationMEHMET YAYAN - İSMAİL HAKKI ÖZTÜRK CS101/SEC.-2 CLASS NOTES 1. March 28-30, 2007
MEHMET YAYAN - İSMAİL HAKKI ÖZTÜRK CS101/SEC.-2 CLASS NOTES 1 March 28-30, 2007 if Single-Selection Statement The conditional statement in Java has the form if (condition) statement The condition must
More informationLecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan
Lecture 08-1 Programming in C++ PART 1 By Assistant Professor Dr. Ali Kattan 1 The Conditional Operator The conditional operator is similar to the if..else statement but has a shorter format. This is useful
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationSlide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto
CS 170 Java Programming 1 The Switch Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Menu-Style Code With ladder-style if-else else-if, you might sometimes find yourself writing menu-style
More informationChapter 4 Defining Classes I
Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the
More informationLecture Set 4: More About Methods and More About Operators
Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static
More informationFlow of Control. Flow of control The order in which statements are executed. Transfer of control
1 Programming in C Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control
More informationV2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed
Programming in C 1 Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control
More informationJava Primer 1: Types, Classes and Operators
Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,
More informationIntroduction to C Programming
1 2 Introduction to C Programming 2.6 Decision Making: Equality and Relational Operators 2 Executable statements Perform actions (calculations, input/output of data) Perform decisions - May want to print
More informationReview Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013
Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections 2.1 2.5 Instructor:
More informationIn Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.
CS101, Mock Boolean Conditions, If-Then Boolean Expressions and Conditions The physical order of a program is the order in which the statements are listed. The logical order of a program is the order in
More informationAssoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine
More informationReview of the C Programming Language for Principles of Operating Systems
Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights
More informationCOMP-202: Foundations of Programming. Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015 Announcements Slides will be posted before the class. There might be few
More information12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.
Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started
More informationCS 112 Introduction to Programming
CS 112 Introduction to Programming Java Primitive Data Types; Arithmetic Expressions Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu
More informationAdmin. CS 112 Introduction to Programming. Recap: Java Static Methods. Recap: Decomposition Example. Recap: Static Method Example
Admin CS 112 Introduction to Programming q Programming assignment 2 to be posted tonight Java Primitive Data Types; Arithmetic Expressions Yang (Richard) Yang Computer Science Department Yale University
More informationText Input and Conditionals
Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()
More informationSchool of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15
Table of Contents 1 INTRODUCTION... 1 2 IF... 1 2.1 BOOLEAN EXPRESSIONS... 3 2.2 BLOCKS... 3 2.3 IF-ELSE... 4 2.4 NESTING... 5 3 SWITCH (SOMETIMES KNOWN AS CASE )... 6 3.1 A BIT ABOUT BREAK... 7 4 CONDITIONAL
More informationWEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS
WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS OPERATORS Review: Data values can appear as literals or be stored in variables/constants Data values can be returned by method calls Operators: special symbols
More informationConditional Statements
Conditional Statements CSC 1051 Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some
More information5. Control Statements
5. Control Statements This section of the course will introduce you to the major control statements in C++. These control statements are used to specify the branching in an algorithm/recipe. Control statements
More informationMotivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018
Motivating Examples (1.1) Selections EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG 1 import java.util.scanner; 2 public class ComputeArea { 3 public static void main(string[] args)
More informationSequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;
Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The
More informationSTUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode
STUDENT OUTLINE Lesson 8: Structured Programming, Control Structures, if- Statements, Pseudocode INTRODUCTION: This lesson is the first of four covering the standard control structures of a high-level
More informationComputational Expression
Computational Expression Conditionals Janyl Jumadinova 10 October, 2018 Janyl Jumadinova Computational Expression 10 October, 2018 1 / 16 Computational Thinking: a problem solving process Decomposition
More informationSelections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG
Selections EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG Learning Outcomes The Boolean Data Type if Statement Compound vs. Primitive Statement Common Errors
More informationAPCS Semester #1 Final Exam Practice Problems
Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester
More informationObject oriented programming. Instructor: Masoud Asghari Web page: Ch: 3
Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning
More informationA Foundation for Programming
2.1 Functions A Foundation for Programming any program you might want to write objects functions and modules build bigger programs and reuse code graphics, sound, and image I/O arrays conditionals and
More informationCOMP 202 Java in one week
COMP 202 Java in one week... Continued CONTENTS: Return to material from previous lecture At-home programming exercises Please Do Ask Questions It's perfectly normal not to understand everything Most of
More informationAlgorithms and Conditionals
Algorithms and Conditionals CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/
More informationIEEE Floating-Point Representation 1
IEEE Floating-Point Representation 1 x = ( 1) s M 2 E The sign s determines whether the number is negative (s = 1) or positive (s = 0). The significand M is a fractional binary number that ranges either
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationJava Programming Fundamentals - Day Instructor: Jason Yoon Website:
Java Programming Fundamentals - Day 1 07.09.2016 Instructor: Jason Yoon Website: http://mryoon.weebly.com Quick Advice Before We Get Started Java is not the same as javascript! Don t get them confused
More informationChapter 3. Selections
Chapter 3 Selections 1 Outline 1. Flow of Control 2. Conditional Statements 3. The if Statement 4. The if-else Statement 5. The Conditional operator 6. The Switch Statement 7. Useful Hints 2 1. Flow of
More informationChapter 6 Introduction to Defining Classes
Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of
More informationReview of the C Programming Language
Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the
More informationA PROGRAM IS A SEQUENCE of instructions that a computer can execute to
A PROGRAM IS A SEQUENCE of instructions that a computer can execute to perform some task. A simple enough idea, but for the computer to make any use of the instructions, they must be written in a form
More informationFlow Control. So Far: Writing simple statements that get executed one after another.
Flow Control So Far: Writing simple statements that get executed one after another. Flow Control So Far: Writing simple statements that get executed one after another. Flow control allows the programmer
More informationCS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 06 / 04 / 2015 Instructor: Michael Eckmann Today s Topics Questions / comments? Calling methods (noting parameter(s) and their types, as well as the return type)
More informationFlow of Control. Chapter 3 Part 3 The Switch Statement
Flow of Control Chapter 3 Part 3 The Switch Statement Agenda Hw 03 comments Review of Ch03 - Parts 1 & 2 Conditional operator I/O of boolean values The switch statement Random numbers Methods with arguments
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a
More informationProgramming overview
Programming overview Basic Java A Java program consists of: One or more classes A class contains one or more methods A method contains program statements Each class in a separate file MyClass defined in
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationLecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166
Lecture 20 Java Exceptional Event Handling Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Topics What is an Exception? Exception Handler Catch or Specify Requirement Three Kinds of Exceptions
More informationControl Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003
Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an
More informationCT 229 Java Syntax Continued
CT 229 Java Syntax Continued 29/09/2006 CT229 Lab Assignments One Week Extension for Lab Assignment 1. Due Date: Oct 8 th Before submission make sure that the name of each.java file matches the name given
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationCOP 3330 Final Exam Review
COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time
More informationIntel x86 Jump Instructions. Part 5. JMP address. Operations: Program Flow Control. Operations: Program Flow Control.
Part 5 Intel x86 Jump Instructions Control Logic Fly over code Operations: Program Flow Control Operations: Program Flow Control Unlike high-level languages, processors don't have fancy expressions or
More informationSelec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal
Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program
More informationExpressions and Data Types CSC 121 Fall 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and
More informationCS 1316 Exam 1 Summer 2009
1 / 8 Your Name: I commit to uphold the ideals of honor and integrity by refusing to betray the trust bestowed upon me as a member of the Georgia Tech community. CS 1316 Exam 1 Summer 2009 Section/Problem
More informationCS11 Java. Fall Lecture 1
CS11 Java Fall 2006-2007 Lecture 1 Welcome! 8 Lectures Slides posted on CS11 website http://www.cs.caltech.edu/courses/cs11 7-8 Lab Assignments Made available on Mondays Due one week later Monday, 12 noon
More informationIntel x86 Jump Instructions. Part 5. JMP address. Operations: Program Flow Control. Operations: Program Flow Control.
Part 5 Intel x86 Jump Instructions Control Logic Fly over code Operations: Program Flow Control Operations: Program Flow Control Unlike high-level languages, processors don't have fancy expressions or
More informationFunctions. x y z. f (x, y, z) Take in input arguments (zero or more) Perform some computation - May have side-effects (such as drawing)
2.1 Functions Functions Take in input arguments (zero or more) Perform some computation - May have side-effects (such as drawing) Return one output value Input Arguments x y z f Return Value f (x, y, z)
More informationSoftware and Programming 1
Software and Programming 1 Lab 1: Introduction, HelloWorld Program and use of the Debugger 17 January 2019 SP1-Lab1-2018-19.pptx Tobi Brodie (tobi@dcs.bbk.ac.uk) 1 Module Information Lectures: Afternoon
More informationCS260 Intro to Java & Android 03.Java Language Basics
03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance
More informationbitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=
Operators in java Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc. There are many types of operators in java which are given below: Unary Operator, Arithmetic
More informationSTATIC, ABSTRACT, AND INTERFACE
STATIC, ABSTRACT, AND INTERFACE Thirapon Wongsaardsakul STATIC When variable is a static type, java allocates memory for it at loading time. Class loader Byte code verifier Static variable has been loaded
More informationComputer Components. Software{ User Programs. Operating System. Hardware
Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point
More informationSelec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal
Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program
More informationModule 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1
Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1 Motivation In the programs we have written thus far, statements are executed one after the other, in the order in which they appear. Programs often
More informationThe Java language has a wide variety of modifiers, including the following:
PART 5 5. Modifier Types The Java language has a wide variety of modifiers, including the following: Java Access Modifiers Non Access Modifiers 5.1 Access Control Modifiers Java provides a number of access
More informationCOMP-202: Foundations of Programming. Lecture 6: Conditionals Jackie Cheung, Winter 2016
COMP-202: Foundations of Programming Lecture 6: Conditionals Jackie Cheung, Winter 2016 This Lecture Finish data types and order of operations Conditionals 2 Review Questions What is the difference between
More informationReviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013
Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 2 Things to Review Review the Class Slides: Key Things to Take Away Do you understand
More informationIntroduction to Java Applications
2 Introduction to Java Applications OBJECTIVES In this chapter you will learn: To write simple Java applications. To use input and output statements. Java s primitive types. Basic memory concepts. To use
More informationChapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,
Chapter 11 Inheritance and Polymorphism 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design
More informationProgramming Fundamentals - A Modular Structured Approach using C++ By: Kenneth Leroy Busbee
1 0 1 0 Foundation Topics 1 0 Chapter 1 - Introduction to Programming 1 1 Systems Development Life Cycle N/A N/A N/A N/A N/A N/A 1-8 12-13 1 2 Bloodshed Dev-C++ 5 Compiler/IDE N/A N/A N/A N/A N/A N/A N/A
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection) Control Structures A computer can proceed: In sequence Selectively (branch) - making
More informationQUIZ: What value is stored in a after this
QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer
More informationOperators. Java operators are classified into three categories:
Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.
More information4 Programming Fundamentals. Introduction to Programming 1 1
4 Programming Fundamentals Introduction to Programming 1 1 Objectives At the end of the lesson, the student should be able to: Identify the basic parts of a Java program Differentiate among Java literals,
More informationCS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find
CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS
More informationCSE 142 Su 04 Computer Programming 1 - Java. Objects
Objects Objects have state and behavior. State is maintained in instance variables which live as long as the object does. Behavior is implemented in methods, which can be called by other objects to request
More informationThe first program: Little Crab
Chapter 2 The first program: Little Crab topics: concepts: writing code: movement, turning, reacting to the screen edges source code, method call, parameter, sequence, if-statement In the previous chapter,
More information1 Shyam sir JAVA Notes
1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write
More informationCourse Outline. Introduction to java
Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.
More informationDaMPL. Language Reference Manual. Henrique Grando
DaMPL Language Reference Manual Bernardo Abreu Felipe Rocha Henrique Grando Hugo Sousa bd2440 flt2107 hp2409 ha2398 Contents 1. Getting Started... 4 2. Syntax Notations... 4 3. Lexical Conventions... 4
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationSimple Java Programming Constructs 4
Simple Java Programming Constructs 4 Course Map In this module you will learn the basic Java programming constructs, the if and while statements. Introduction Computer Principles and Components Software
More informationChapter 3. Flow of Control. Branching Loops exit(n) method Boolean data type and expressions
Chapter 3 Flow of Control Branching Loops exit(n) method Boolean data type and expressions Chapter 3 Java: an Introduction to Computer Science & Programming - Walter Savitch 1 What is Flow of Control?
More informationDecisions, Decisions. Testing, testing C H A P T E R 7
C H A P T E R 7 In the first few chapters, we saw some of the basic building blocks of a program. We can now make a program with input, processing, and output. We can even make our input and output a little
More informationInheritance and Polymorphism
Inheritance and Polymorphism Dr. M. G. Abbas Malik Assistant Professor Faculty of Computing and IT (North Jeddah Branch) King Abdulaziz University, Jeddah, KSA mgmalik@kau.edu.sa www.sanlp.org/malik/cpit305/ap.html
More informationConditionals, Loops, and Style
Conditionals, Loops, and Style yes x > y? no max = x; max = y; http://xkcd.com/292/ Fundamentals of Computer Science Keith Vertanen Copyright 2013 Control flow thus far public class ArgsExample public
More informationChapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the
More informationJava Bytecode (binary file)
Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.
More informationObject oriented programming. Instructor: Masoud Asghari Web page: Ch: 7
Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 7 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Essential
More informationCS 251 Intermediate Programming Methods and Classes
CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationCS 251 Intermediate Programming Methods and More
CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationJava I/O and Control Structures
Java I/O and Control Structures CSC 2014 Java Bootcamp Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Some slides in this presentation are adapted from the slides accompanying
More informationJava How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 9/e Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved. Copyright 1992-2012 by Pearson Copyright 1992-2012 by Pearson Before writing a program to solve a problem, have
More information