Lecture 12. Instructor: Craig Duckett

Size: px
Start display at page:

Download "Lecture 12. Instructor: Craig Duckett"

Transcription

1 Lecture 12 Instructor: Craig Duckett

2 Assignment 2 Revision DUE TONIGHT! Uploaded to StudentTracker by midnight YOUR LAST CHANCE TO EARN POINTS! Assignment 3 Maze DUE Lecture 13 Uploaded to StudentTracker by midnight

3 Assignment Dates (By Due Date) Assignment 1 (LECTURE 5) GRADED! Section 1: Monday, January 22 nd Assignment 2 (LECTURE 8) GRADED! Section 1: Wednesday, January 31 st Assignment 1 Revision (LECTURE 10) GRADED! Section 1: Wednesday, February 7 th Assignment 2 Revision (LECTURE 12) Section 1: Wednesday, February 14 th The Fickle Finger of Fate Assignment 3 (LECTURE 13) Section 1: Wednesday, February 21 st Assignment 3 Revision (LECTURE 16) Section 1: Monday, March 5 th Assignment 4 (LECTURE 18) NO REVISION AVAILABLE! Section 1: Monday, March 12 th 3

4 By-Passing/Jumping BIT116 BIT142 BIT 115 (Intro to Programming) BIT 116 (JavaScript) BIT 142 (Intermediate Programming C#) BIT 143 (Data Structures) SKIP BIT 116? Solid performance in this class: On pace to earn a 3.8 GPA or higher. Very comfortable and confident with this material Feel like you can handle more at a faster right. Required to transfer to UW Contact Mike Panitz the Instructor of BIT142 via ( mpanitz@cascadia.edu ) and CC me ( cduckett@cascadia.edu ) to make a request to jump into BIT142 from BIT115 (explaining why you think you are a good candidate to do this). Once I receive your , I will Mike Panitz in private giving him my yea or nay as to whether I think you are a good candidate to make the jump. Once Mike hears from me he will then contact you with instructions how to take a PLACEMENT QUIZ to be sent out on TBA (1 to 4 Java or JavaScript exercises) which you will have to pass before you can register for BIT142 (you will have to print out the you receive from Mike and register inperson at Kodiak. You cannot do this on-line, since it requires special permission).

5 Assignment 3 ( The Maze ) First, how many are working with a partner or partners? Show of hands Some Additional Comments Please read the Directions carefully (Word doc), especially the comments in red. Look at the Rubric for a sense of grading In the Maze.java file, pay special attention to the comments; they are there to help you! If you don't like the comments, simply delete them. If you need a bit of help, are stuck, or have an error you are unable to debug, feel free to me but make sure to attach your Maze.java file so I can check your code and offer the pertinent comments. Remember: Assignment 3 is due LECTURE 13, uploaded to Student Tracker by midnight.

6 Today s Topics Overriding Inherited Methods Using super. Debugging Using System.out Random Numbers Multiple Files

7 But First The Warm-Up Quiz

8 Some Quick Refreshers!

9 Variables: Quick Refresher Declaring a variable creates a named storage location in memory large enough to hold a value of a particular type. For instance, if you declare a variable int num, then you are saying you need a storage location in memory named num that will be large enough to hold an integer (any number in the range of -2,147,483,648 and 2,147,483,647 that takes up a total of 32-bits of storage space). int num; num Initializing the variable simply means that you are putting an initial value in that named storage location: int num = 0; int num = 0; 0 num Now, using code in your program you can access the value that is stored in that named storage location, or add to it, or subtract from it, or alter it in some other way, since it is a variable (meaning that it can be changed and it doesn t have to remain the same, i.e., it isn t constant). System.out.print("The storage container called num contains a " + num);

10 Counter: Quick Refresher Setting up a counter creates a named storage location in memory large enough to hold a value of a particular type. Counters are useful when working with loops. int counter = 0; 0 counter while(counter < 3) move(); System.out.println("Counter is " + counter); counter = counter + 1; // Or counter++; 1 counter 2 counter 3 counter

11 Instance Variables: Refresher An instance variable is a variable that is declared and initialized inside a class, but outside of the methods. A variable declared inside a method is a local or temporary variable and can only be used by that method, but a global or instance variable declared outside of a method can be used by any of the methods or objects of that class. Local or Temporary Variables Only Local Variables AND Instance Variable

12 Overriding Inherited Methods

13 Inheritance: Quick Refresher import becker.robots.*; public class MrRoboto extends Robot // Construct a new MrRoboto public MrRoboto(City thecity, int street, int avenue, Direction adirection) super(thecity, street, avenue, adirection); public void turnaround() this.turnleft(); this.turnleft(); public void move3() this.move(); this.move(); this.move(); public void turnright() this.turnaround(); this.turnleft();

14 Overriding Inherited Methods Java allows us to override methods inherited from the superclass using the super. ( super dot ) keyword in the method. Both the original method and the overriding method must: have the same name declare the same data type accept same number of parameters return the same data type (we ll be going over return in the next lecture) See: ICE_10_Demo_1.java

15 // DEMO 1: Overriding the turnleft() method /////////////////////////////////////////////////////////////////// import becker.robots.*; class SpinningRobot extends Robot SpinningRobot ( City c, int st, int ave, Direction dir, int num) super(c, st, ave, dir, num); public void turnleft() super.turnleft(); // super here tells compiler to use turnleft() super.turnleft(); // from the super class Robot and not from its super.turnleft(); // own class SpinningRobot. If we would have super.turnleft(); // used a this here instead of super then super.turnleft(); // we would find ourselves in an infinite loop public class ICE_10_Demo_1 extends Object public static void main(string[] args) City Dizzyland = new City(10, 10); SpinningRobot mary = new SpinningRobot(Dizzyland, 4, 4, Direction.EAST, 0); mary.turnleft(); // mary turns left 5 times

16 Class Sub-Class Sub-Sub-Class Sub-Sub-Sub-Class class MrRoboto extends Robot MrRoboto( City c, int st, int ave, Direction dir, int num) super(c, st, ave, dir, num); <<methods here>> class NeuvoRoboto extends MrRoboto NeuvoRoboto( City c, int st, int ave, Direction dir, int num) super(c, st, ave, dir, num); <<methods here>> See: ICE_10_Demo_2.java

17 Overloading Same method name Different parameter Overriding Same method name Same parameter Robot class: move( ); RobotSE class: move(int howfar); Robot class: turnleft( ); MrRoboto class: turnleft( );

18 ICE: Overriding Inherited Methods As always, we ll wait until the end of the LECTURE to do all the ICEs together

19 Debugging Programmatically

20 Debugging: A Brief Look Using System.out for debugging In a method: System.out.println(this); With an object (for example, a Robot object named rigby): System.out.println(rigby); [street=1, avenue=4, direction=east, isbroken=false, numthingsinbackpack=3] With an object (for example, a Thing object named t1): System.out.printlin(t1); [street=1, avenue=4] DebugExample.java

21 Random Numbers

22 Random Numbers Depending on your program, sometimes it useful to be able to generate a random number (or numbers) that can be used to interact with your code to accomplish various tasks: Simple Gaming (spin the wheel, roulette, craps, etc) Advanced Gaming (from what coordinate locations the zombies will attack, where the artillery strike will hit, how much schrapnel will fly, the direction and amount of smoke in the wind, etc) Statistical Sampling (political affiliation, voter turnout, employment / unemployment numbers, etc) Computer Simulation (predicting earthquakes, paths of hurricanes, tide flows, etc) Cryptography (codes and encryption) Completely Randomized Design (nuissance variables, response variables) Text

23 Random Numbers Java has a rich toolkit for generating random numbers, in a class named Random. Random can generate many kinds of random numbers, but we ll won t going into these in this introduction. For more information, see Random is defined in the "java.util" library package, so any Java source file that uses Random must begin with a line of the form: import java.util.random; or import java.util.*; The easiest way to initialize a random number generator is to use the parameterless constructor, for example: Random generator = new Random(); Random as it stands is NOT truly random. An instance of the Random class is used to generate a stream of pseudo random numbers using a 48-bit seed, which is modified using a linear congruential formula: x i+1 = (0x5DEECE66DL * x i + 11) mod If two instances of Random are created with the same seed, and the same sequence of method calls is made for each, they will generate and return identical sequences of numbers. Java implementations for Random have been developed this way for the sake of absolute portability of Java code. However, subclasses of Random are permitted to use other algorithms, so long as they adhere to the general contracts for all the methods. Example: you can develop a subclass algorithm for Random that interacts with its seed in some way (through multiplication, division, a bit of both) like using the current system time from your computer (e.g., total seconds from some predefined date or randomized date). Some applications will find the random method in class Math (Math.random) simpler to use, as it creates a pseudorandom double greater than or equal to 0.0 and less than 1.0.

24 Multiple Program Files

25 Multiple Files (Programs) Separating main from classes to create more manageable code a main file one or more class files an optional.txt text file for configuration, additional input, or output (like creating a log file) Things to remember when dealing with multiple.java files: class name must match file name All files must be grouped together in the same area (folder, directory, desktop, drive, etc.) jgrasp automatically saves any changes made in the class files when compiling main, but I would get in the habit of recompiling all class files first before compiling main since other compilers behave differently.

26 SINGLE FILE STYLE 1 import becker.robots.*; public class MrRoboto extends Robot public MrRoboto(City thecity, int avenue, int street, Direction adirection) super(thecity, avenue, street, adirection); public void turnaround() this.turnleft(); this.turnleft(); public void move3() this.move(); this.move(); this.move(); public void turnright() this.turnaround(); this.turnleft(); In this style, since there is only one class name, then: the class name MrRoboto, the constructor name MrRoboto, and the file name MrRoboto must all be the same. public static void main(string[] args) City bothell = new City(); MrRoboto lisa = new MrRoboto(bothell, 3, 2, Direction.SOUTH); lisa.move3(); lisa.turnright(); lisa.move3(); lisa.turnaround();

27 SINGLE FILE STYLE 2 import becker.robots.*; class MrRoboto extends Robot // Construct a new MrRoboto public MrRoboto(City thecity, int avenue, int street, Direction adirection) super(thecity, avenue, street, adirection); public void turnaround() this.turnleft(); this.turnleft(); public void move3() this.move(); this.move(); this.move(); public void turnright() this.turnaround(); this.turnleft(); In this style, since there are two class names, then the file name must match the class name that contains the main method, MrRobotoMain. Also the class that holds the constructor and the new methods only starts with class, and the constructor starts with public. The class that holds main must start with public class public class MrRobotoMain extends Object public static void main(string[] args) City bothell = new City(); MrRoboto lisa = new MrRoboto(bothell, 3, 2, Direction.SOUTH); lisa.move3(); lisa.turnright(); lisa.move3(); lisa.turnaround();

28 Splitting MrRobotoMain.java into Two Files METHODS and MAIN: 1 File with 2 Classes METHODS: 1 File with 1 Class MAIN: 1 File with 1 Class

29 import becker.robots.*; Needs its own import statement class MrRoboto extends Robot // Construct a new MrRoboto public MrRoboto(City thecity, int avenue, int street, Direction adirection) super(thecity, avenue, street, adirection); MrRoboto.java SPLIT IN TWO public void turnaround() this.turnleft(); this.turnleft(); public void move3() this.move(); this.move(); this.move(); public void turnright() this.turnaround(); this.turnleft(); In this case, since there are two files, then the class names must match the files names, and both files must be in the same folder/directory. Each file needs to include the line import becker.robots.*; as well. import becker.robots.*; Needs its own import statement MrRobotoMan.java public class MrRobotoMain extends Object public static void main(string[] args) City bothell = new City(); MrRoboto lisa = new MrRoboto(bothell, 3, 2, Direction.SOUTH); lisa.move3(); lisa.turnright(); lisa.move3(); lisa.turnaround(); Always compile the file that contains main when working with multiple files, since you cannot compile a file that does not contain main

30 Multiple Files Go in Same Folder/Directory The files need to be able find each other to work correctly, so storing them in the same directory or folder greatly simplifies this discovery process. MrRoboto.java THE METHOD FILE MrRobotoMain.java THE MAIN FILE NOW A DEMONSTRATION Using MrRobotoMain.java

31 Assignment 3 Final Hint With Pseudo-Code public void NavigateMaze() while(!this.isatendspot() ) // Something happens here // Something happens here // Something happens here // if robot can not pick up a thing // if robot still has things in its backpack // put down a thing NESTED IF STATEMENTS There is an if statement INSIDE an if statement // Something happens here // print everything here See MAZE city next slide for demonstration

32

33 ICE: Overriding Inherited Methods ICE: Multiple File Programs Let s Look at Both ICEs Before Beginning REMEMBER: ALWAYS download your multiple files from the website first and then work on them and run them from the same folder/directory, or else things will not work correctly. NOTE: If you want to learn how I constructed a City using a separate text file, please refer to the Becker Robot Library > becker.robots > City and scroll down to the Constructor Detail on the right-hand side (the section begins with Construct a new city by reading information to construct it from a file )

Variables and Classes. In which we over-ride the super class, work with multiple classes, and move towards non-robot based programming

Variables and Classes. In which we over-ride the super class, work with multiple classes, and move towards non-robot based programming Variables and Classes In which we over-ride the super class, work with multiple classes, and move towards non-robot based programming Classes Class extends Class attributes:

More information

Lecture 6. Instructor: Craig Duckett

Lecture 6. Instructor: Craig Duckett Lecture 6 Instructor: Craig Duckett Assignment 1, 2, and A1 Revision Assignment 1 I have finished correcting and have already returned the Assignment 1 submissions. If you did not submit an Assignment

More information

BIT 115: Introduction To Programming LECTURE 3. Instructor: Craig Duckett

BIT 115: Introduction To Programming LECTURE 3. Instructor: Craig Duckett BIT 115: Introduction To Programming LECTURE 3 Instructor: Craig Duckett cduckett@cascadia.edu Lecture 3 Announcements By now everyone should be up and running with Java, jgrasp, and the Becker Robots

More information

Lecture 8. A series on variable types This episode starring Parameter Variables

Lecture 8. A series on variable types This episode starring Parameter Variables Lecture 8 A series on variable types This episode starring Parameter Variables Declaring an Integer Variable Variable Types Variable Type How it is defined Scope (how long it lasts) Uses Local Variable

More information

Asking For Help. BIT 115: Introduction To Programming 1

Asking For Help. BIT 115: Introduction To Programming 1 Asking For Help Start homeworks As Soon As Possible You may post homework questions to Canvas: Please do not cut and paste entire lines of code, but rather ask conceptual questions. You may also ask me

More information

Lecture 11. Instructor: Craig Duckett. Instance Variables

Lecture 11. Instructor: Craig Duckett. Instance Variables Lecture 11 Instructor: Craig Duckett Instance Variables Assignment Dates (By Due Date) Assignment 1 (LECTURE 5) GRADED! Section 1: Monday, January 22 nd Assignment 2 (LECTURE 8) GRADED! Section 1: Wednesday,

More information

Lecture 7. Instructor: Craig Duckett OUTPUT

Lecture 7. Instructor: Craig Duckett OUTPUT Lecture 7 Instructor: Craig Duckett OUTPUT Lecture 7 Announcements ASSIGNMENT 2 is due LECTURE 8 NEXT LECTURE uploaded to StudentTracker by midnight Assignment 2!!! Assignment Dates (By Due Date) Assignment

More information

Instructor: Craig Duckett

Instructor: Craig Duckett Instructor: Craig Duckett cduckett@cascadia.edu Announcements Assignment 1 Due Lecture 5 by MIDNIGHT I will double dog dare try to have Assignment 1 graded and back to you by Wednesday, January 24 th hopefully

More information

Lecture 10. Instructor: Craig Duckett

Lecture 10. Instructor: Craig Duckett Lecture 10 Instructor: Craig Duckett Announcements Assignment 1 Revision DUE TONIGHT in StudentTracker by midnight If you have not yet submitted an Assignment 1, this is your last chance to do so to earn

More information

Lecture 8 " INPUT " Instructor: Craig Duckett

Lecture 8  INPUT  Instructor: Craig Duckett Lecture 8 " INPUT " Instructor: Craig Duckett Assignments Assignment 2 Due TONIGHT Lecture 8 Assignment 1 Revision due Lecture 10 Assignment 2 Revision Due Lecture 12 We'll Have a closer look at Assignment

More information

Combo Lecture Lecture 14/15. Instructor: Craig Duckett

Combo Lecture Lecture 14/15. Instructor: Craig Duckett Combo Lecture Lecture 14/15 Instructor: Craig Duckett Assignment Dates (By Due Date) Assignment 1 (LECTURE 5) GRADED! Section 1: Monday, January 22 nd Assignment 2 (LECTURE 8) GRADED! Section 1: Wednesday,

More information

Robots. Byron Weber Becker. chapter 6

Robots. Byron Weber Becker. chapter 6 Using Variables Robots Learning to Program with Java Byron Weber Becker chapter 6 Announcements (Oct 3) Reminder: Reading for today y( (Oct 3 rd ) Ch 6.1-6.4 Reading for Wednesday (Oct 3 rd ) The rest

More information

Lecture 13. Instructor: Craig Duckett. Boolean Expressions, Logical Operators, and Return Values

Lecture 13. Instructor: Craig Duckett. Boolean Expressions, Logical Operators, and Return Values Lecture 13 Instructor: Craig Duckett Boolean Expressions, Logical Operators, and Return Values Assignment 3: The Maze DUE TONIGHT! Uploaded to StudentTracker by midnight If you are submitting as part of

More information

Lecture 17. Instructor: Craig Duckett. Passing & Returning Arrays

Lecture 17. Instructor: Craig Duckett. Passing & Returning Arrays Lecture 17 Instructor: Craig Duckett Passing & Returning Arrays Assignment Dates (By Due Date) Assignment 1 (LECTURE 5) GRADED! Section 1: Monday, January 22 nd Assignment 2 (LECTURE 8) GRADED! Section

More information

Lecture 2 Announcements

Lecture 2 Announcements Lecture 2 Announcements Home Computers and/or Laptops/Notebooks By now you should have installed Java SE 8 and jgrasp on your computers, set up the becker.jar file, and started working with some of the

More information

Media Computation. Lecture 16.1, December 8, 2008 Steve Harrison

Media Computation. Lecture 16.1, December 8, 2008 Steve Harrison Media Computation Lecture 16.1, December 8, 2008 Steve Harrison Today -- Details of Creating Classes From requirements to classes Creating a class that will simulate a number game Practice going from requirements

More information

Extending Classes with Services

Extending Classes with Services Extending Classes with Services 2 2 Author s Do-List: add a concept map Extending an existing class to do something new is the fundamental activity of object-oriented programming. Sometimes an existing

More information

Class 09 Slides: Polymorphism Preconditions. Table of Contents. Postconditions

Class 09 Slides: Polymorphism Preconditions. Table of Contents. Postconditions Class 09 Slides: Polymorphism Preconditions Students are familiar with inheritance and arrays. Students have worked with a poorly written program in A08 that could benefit from polymorphism. Students have

More information

Assignment Definition And General Feedback By Michael Panitz at Cascadia Community College (

Assignment Definition And General Feedback By Michael Panitz at Cascadia Community College ( For Loops: Will Tanna Assignment Definition And General Feedback By Michael Panitz at Cascadia Community College (http://www.cascadia.edu) Table of contents: Summary When To Use and Avoid This Example

More information

Title: Counting While Loops

Title: Counting While Loops Title: Counting While Loops Erik Boling, Panitz, Bit115, Winter Quarter 2011 Assignment Definition And General Feedback By Michael Panitz at Cascadia Community College (http://www.cascadia.edu) Table of

More information

Inheritance and Interfaces

Inheritance and Interfaces Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical

More information

Robots. Byron Weber Becker. chapter 6

Robots. Byron Weber Becker. chapter 6 Using Variables Robots Learning to Program with Java Byron Weber Becker chapter 6 Announcements (Oct 5) Chapter 6 You don t have to spend much time on graphics in Ch6 Just grasp the concept Reminder: Reading

More information

Developing and Reusing Methods

Developing and Reusing Methods Developing and Reusing Methods 3 In Chapter 2, we wrote new services such as turnright and turnaround. These services were very simple, consisting of only a few steps to accomplish the task. In this chapter,

More information

ASSIGNMENT 3 Classes, Objects and the Robot World

ASSIGNMENT 3 Classes, Objects and the Robot World ASSIGNMENT 3 Classes, Objects and the Robot World COMP-202B, Winter 2009, All Sections Due: Tuesday, March 3, 2009 (23:55) You MUST do this assignment individually and, unless otherwise specified, you

More information

ASSIGNMENT 4 Classes and Objects

ASSIGNMENT 4 Classes and Objects ASSIGNMENT 4 Classes and Objects COMP-202A, Fall 2010, All Sections Due: Friday, November 19, 2010 (23:55) You MUST do this assignment individually and, unless otherwise specified, you MUST follow all

More information

AP Computer Science Unit 1. Programs

AP Computer Science Unit 1. Programs AP Computer Science Unit 1. Programs Open DrJava. Under the File menu click on New Java Class and the window to the right should appear. Fill in the information as shown and click OK. This code is generated

More information

Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Interfaces vs. Inheritance Abstract Classes Inner Classes Readings This Week: No new readings. Consolidate! (Reminder: Readings

More information

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2. Class #10: Understanding Primitives and Assignments Software Design I (CS 120): M. Allen, 19 Sep. 18 Java Arithmetic } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = 2 + 5 / 2; 3.

More information

COMP 110 Programming Exercise: Simulation of the Game of Craps

COMP 110 Programming Exercise: Simulation of the Game of Craps COMP 110 Programming Exercise: Simulation of the Game of Craps Craps is a game of chance played by rolling two dice for a series of rolls and placing bets on the outcomes. The background on probability,

More information

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide AP Computer Science Chapter 10 Implementing and Using Classes Study Guide 1. A class that uses a given class X is called a client of X. 2. Private features of a class can be directly accessed only within

More information

CSE 113 A. Announcements - Lab

CSE 113 A. Announcements - Lab CSE 113 A February 21-25, 2011 Announcements - Lab Lab 1, 2, 3, 4; Practice Assignment 1, 2, 3, 4 grades are available in Web-CAT look under Results -> Past Results and if looking for Lab 1, make sure

More information

Slide 1 CS 170 Java Programming 1 Testing Karel

Slide 1 CS 170 Java Programming 1 Testing Karel CS 170 Java Programming 1 Testing Karel Introducing Unit Tests to Karel's World Slide 1 CS 170 Java Programming 1 Testing Karel Hi Everybody. This is the CS 170, Java Programming 1 lecture, Testing Karel.

More information

AP Computer Science Summer Work Mrs. Kaelin

AP Computer Science Summer Work Mrs. Kaelin AP Computer Science Summer Work 2018-2019 Mrs. Kaelin jkaelin@pasco.k12.fl.us Welcome future 2018 2019 AP Computer Science Students! I am so excited that you have decided to embark on this journey with

More information

Initial Coding Guidelines

Initial Coding Guidelines Initial Coding Guidelines ITK 168 (Lim) This handout specifies coding guidelines for programs in ITK 168. You are expected to follow these guidelines precisely for all lecture programs, and for lab programs.

More information

Lecture 02, Fall 2018 Friday September 7

Lecture 02, Fall 2018 Friday September 7 Anatomy of a class Oliver W. Layton CS231: Data Structures and Algorithms Lecture 02, Fall 2018 Friday September 7 Follow-up Python is also cross-platform. What s the advantage of Java? It s true: Python

More information

public class Foo { private int var; public int Method1() { // var accessible anywhere here } public int MethodN() {

public class Foo { private int var; public int Method1() { // var accessible anywhere here } public int MethodN() { Scoping, Static Variables, Overloading, Packages In this lecture, we will examine in more detail the notion of scope for variables. We ve already indicated that variables only exist within the block they

More information

CS 112 Introduction to Programming. (Spring 2012)

CS 112 Introduction to Programming. (Spring 2012) CS 112 Introduction to Programming (Spring 2012) Lecture #32: Inheritance and Class Hierarchy Zhong Shao Department of Computer Science Yale University Office: 314 Watson http://flint.cs.yale.edu/cs112

More information

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE Program 10: 40 points: Due Tuesday, May 12, 2015 : 11:59 p.m. ************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE *************

More information

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount

More information

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

Outline. Turtles. Creating objects. Turtles. Turtles in Java 1/27/2011 TOPIC 3 INTRODUCTION TO PROGRAMMING. Making things to program with.

Outline. Turtles. Creating objects. Turtles. Turtles in Java 1/27/2011 TOPIC 3 INTRODUCTION TO PROGRAMMING. Making things to program with. 1 Outline 2 TOPIC 3 INTRODUCTION TO PROGRAMMING Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

More information

One of these "compartments" is more correctly referred to as an element of the array

One of these compartments is more correctly referred to as an element of the array An array is a special type of variable in that it can contain many values If a standard variable is like a box, think of an array as being like a box with compartments: One of these "compartments" is more

More information

CS112 Lecture: Extending Classes and Defining Methods

CS112 Lecture: Extending Classes and Defining Methods Objectives: CS112 Lecture: Extending Classes and Defining Methods Last revised 1/9/04 1. To introduce the idea of extending existing classes to add new methods 2. To introduce overriding of inherited methods

More information

Inf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics

Inf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics Inf1-OP Inf1-OP Exam Review Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein School of Informatics March 20, 2017 Overview Overview of examinable material: Lectures Week 1

More information

Inheritance (Outsource: )

Inheritance (Outsource: ) (Outsource: 9-12 9-14) is a way to form new classes using classes that have already been defined. The new classes, known as derived classes, inherit attributes and behavior of the pre-existing classes,

More information

CS112 Lecture: Introduction to Karel J. Robot

CS112 Lecture: Introduction to Karel J. Robot CS112 Lecture: Introduction to Karel J. Robot Last revised 1/17/08 Objectives: 1. To introduce Karel J. Robot as an example of an object-oriented system. 2. To explain the mechanics of writing simple Karel

More information

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab CSC 111 Fall 2005 Lab 6: Methods and Debugging Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab Documented GameMethods file and Corrected HighLow game: Uploaded by midnight of lab

More information

Inf1-OOP. OOP Exam Review. Perdita Stevens, adapting earlier version by Ewan Klein. March 16, School of Informatics

Inf1-OOP. OOP Exam Review. Perdita Stevens, adapting earlier version by Ewan Klein. March 16, School of Informatics Inf1-OOP OOP Exam Review Perdita Stevens, adapting earlier version by Ewan Klein School of Informatics March 16, 2015 Overview Overview of examinable material: Lectures Topics S&W sections Week 1 Compilation,

More information

Object-Oriented Programming in Java. Topic : Objects and Classes (cont) Object Oriented Design

Object-Oriented Programming in Java. Topic : Objects and Classes (cont) Object Oriented Design Electrical and Computer Engineering Object-Oriented in Java Topic : Objects and Classes (cont) Object Oriented Maj Joel Young Joel.Young@afit.edu 11-Sep-03 Maj Joel Young Using Class Instances Accessing

More information

Lesson 10: Quiz #1 and Getting User Input (W03D2)

Lesson 10: Quiz #1 and Getting User Input (W03D2) Lesson 10: Quiz #1 and Getting User Input (W03D2) Balboa High School Michael Ferraro September 1, 2015 1 / 13 Do Now: Prep GitHub Repo for PS #1 You ll need to submit the 5.2 solution on the paper form

More information

Week 2: Data and Output

Week 2: Data and Output CS 170 Java Programming 1 Week 2: Data and Output Learning to speak Java Types, Values and Variables Output Objects and Methods What s the Plan? Topic I: A little review IPO, hardware, software and Java

More information

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics COMP-202 Unit 1: Introduction Announcements Did you miss the first lecture? Come talk to me after class. If you want

More information

Creating objects TOPIC 3 INTRODUCTION TO PROGRAMMING. Making things to program with.

Creating objects TOPIC 3 INTRODUCTION TO PROGRAMMING. Making things to program with. 1 Outline TOPIC 3 INTRODUCTION TO PROGRAMMING Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

More information

This course supports the assessment for Scripting and Programming Applications. The course covers 4 competencies and represents 4 competency units.

This course supports the assessment for Scripting and Programming Applications. The course covers 4 competencies and represents 4 competency units. This course supports the assessment for Scripting and Programming Applications. The course covers 4 competencies and represents 4 competency units. Introduction Overview Advancements in technology are

More information

Lecture 14. 'for' loops and Arrays

Lecture 14. 'for' loops and Arrays Lecture 14 'for' loops and Arrays For Loops for (initiating statement; conditional statement; next statement) // usually incremental body statement(s); The for statement provides a compact way to iterate

More information

BCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER COURSE WEBSITE

BCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER   COURSE WEBSITE COURSE WEBSITE http://www.steveguynes.com/bcis3630/bcis3630/default.html Instructor: Dr. Guynes Office: BLB 312H Phone: (940) 565-3110 Office Hours: By Email Email: steve.guynes@unt.edu TEXTBOOK: Starting

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

Arrays Classes & Methods, Inheritance

Arrays Classes & Methods, Inheritance Course Name: Advanced Java Lecture 4 Topics to be covered Arrays Classes & Methods, Inheritance INTRODUCTION TO ARRAYS The following variable declarations each allocate enough storage to hold one value

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created. + Inheritance + Inheritance Classes that we design in Java can be used to model some concept in our program. For example: Pokemon a = new Pokemon(); Pokemon b = new Pokemon() Sometimes we need to create

More information

Function Call Stack and Activation Records

Function Call Stack and Activation Records 71 Function Call Stack and Activation Records To understand how C performs function calls, we first need to consider a data structure (i.e., collection of related data items) known as a stack. Students

More information

Announcements. 1. Forms to return today after class:

Announcements. 1. Forms to return today after class: Announcements Handouts (3) to pick up 1. Forms to return today after class: Pretest (take during class later) Laptop information form (fill out during class later) Academic honesty form (must sign) 2.

More information

Review 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 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 information

Creating Java Programs with Greenfoot

Creating Java Programs with Greenfoot Creating Java Programs with Greenfoot Using Randomization and Understanding Dot Notation and Constructors 1 Copyright 2012, Oracle and/or its affiliates. All rights Overview This lesson covers the following

More information

Tips from the experts: How to waste a lot of time on this assignment

Tips from the experts: How to waste a lot of time on this assignment Com S 227 Spring 2018 Assignment 1 100 points Due Date: Friday, September 14, 11:59 pm (midnight) Late deadline (25% penalty): Monday, September 17, 11:59 pm General information This assignment is to be

More information

CS112 Lecture: Defining Instantiable Classes

CS112 Lecture: Defining Instantiable Classes CS112 Lecture: Defining Instantiable Classes Last revised 2/3/05 Objectives: 1. To describe the process of defining an instantiable class 2. To discuss public and private visibility modifiers. Materials:

More information

CSC-140 Assignment 6

CSC-140 Assignment 6 CSC-140 Assignment 6 1 Introduction In this assignment we will start out defining our own classes. For now, we will design a class that represents a date, e.g., Tuesday, March 15, 2011, or in short hand

More information

Unit E Step-by-Step: Programming with Python

Unit E Step-by-Step: Programming with Python Unit E Step-by-Step: Programming with Python Computer Concepts 2016 ENHANCED EDITION 1 Unit Contents Section A: Hello World! Python Style Section B: The Wacky Word Game Section C: Build Your Own Calculator

More information

AP Computer Science in Java Course Syllabus

AP Computer Science in Java Course Syllabus CodeHS AP Computer Science in Java Course Syllabus College Board Curriculum Requirements The CodeHS AP Java course is fully College Board aligned and covers all seven curriculum requirements extensively

More information

Mat 2170 Week 9. Spring Mat 2170 Week 9. Objects and Classes. Week 9. Review. Random. Overloading. Craps. Clients. Packages. Randomness.

Mat 2170 Week 9. Spring Mat 2170 Week 9. Objects and Classes. Week 9. Review. Random. Overloading. Craps. Clients. Packages. Randomness. Spring 2014 Student Responsibilities Reading: Textbook, Sections 6.1 6.3 Attendance Recall: Writing Methods Decomposition: break a problem down into smaller subproblems Use methods whenever you can in

More information

TaxiBot New attributes Variables Math! TaxiBot

TaxiBot New attributes Variables Math! TaxiBot TaxiBot New attributes Variables Math! TaxiBot TaxiBot operates in the city BUT it charges you for its actions TaxiBot extends RobotSE TaxiBot displays how much is owed 1 TaxiBot charges Moving 1 space

More information

Assignment #1: /Survey and Karel the Robot Karel problems due: 1:30pm on Friday, October 7th

Assignment #1:  /Survey and Karel the Robot Karel problems due: 1:30pm on Friday, October 7th Mehran Sahami Handout #7 CS 06A September 8, 06 Assignment #: Email/Survey and Karel the Robot Karel problems due: :0pm on Friday, October 7th Email and online survey due: :9pm on Sunday, October 9th Part

More information

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018 Java + OOP CSC207 Winter 2018 1 Why OOP? Modularity: code can be written and maintained separately, and easily passed around the system Information-hiding: internal representation hidden from the outside

More information

Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017

Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017 Due: Wednesday, October 18, 11:59 pm Collaboration Policy: Level 1 Group Policy: Pair-Optional Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017 In this week s lab, you will write a program that can solve

More information

Mehran Sahami Handout #7 CS 106A September 24, 2014

Mehran Sahami Handout #7 CS 106A September 24, 2014 Mehran Sahami Handout #7 CS 06A September, 0 Assignment #: Email/Survey and Karel the Robot Karel problems due: :pm on Friday, October rd Email and online survey due: :9pm on Sunday, October th Part I

More information

CS1004: Intro to CS in Java, Spring 2005

CS1004: Intro to CS in Java, Spring 2005 CS1004: Intro to CS in Java, Spring 2005 Lecture #23: OO Design, cont d. Janak J Parekh janak@cs.columbia.edu Administrivia HW#5 due Tuesday And if you re cheating on (or letting others see your) HW#5

More information

Specification Load Mountain.java and study its method explore(). Complete the Exercises on the next page.

Specification Load Mountain.java and study its method explore(). Complete the Exercises on the next page. Lab07 Exploration Objective Polymorphism. Background Some other variations on creating an object: Robot karel = new Robot(); Robot lisa; lisa = new Robot(); Robot maria; maria = new Athlete(); Robot maria

More information

Guessing Game with Objects

Guessing Game with Objects Objectives Lab1: Guessing Game with Objects Guessing Game with Objects 1. Practice designing and implementing an object-oriented program. 2. Use Console I/O in Java. Tasks 1. Design the program (problem

More information

https://asd-pa.perfplusk12.com/admin/admin_curric_maps_display.aspx?m=5507&c=618&mo=18917&t=191&sy=2012&bl...

https://asd-pa.perfplusk12.com/admin/admin_curric_maps_display.aspx?m=5507&c=618&mo=18917&t=191&sy=2012&bl... Page 1 of 13 Units: - All - Teacher: ProgIIIJavaI, CORE Course: ProgIIIJavaI Year: 2012-13 Intro to Java How is data stored by a computer system? What does a compiler do? What are the advantages of using

More information

CSE 143 Lecture 12 Inheritance

CSE 143 Lecture 12 Inheritance CSE 143 Lecture 12 Inheritance slides created by Ethan Apter http://www.cs.washington.edu/143/ Intuition: Employee Types Consider this (partial) hierarchy of employee types: Employee Clerical Professional

More information

Lecture 5: Methods CS2301

Lecture 5: Methods CS2301 Lecture 5: Methods NADA ALZAHRANI CS2301 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Solution public static int sum(int i1, int i2) { int

More information

School of Computer Science CPS109 Course Notes 6 Alexander Ferworn Updated Fall 15. CPS109 Course Notes 6. Alexander Ferworn

School of Computer Science CPS109 Course Notes 6 Alexander Ferworn Updated Fall 15. CPS109 Course Notes 6. Alexander Ferworn CPS109 Course Notes 6 Alexander Ferworn Unrelated Facts Worth Remembering Use metaphors to understand issues and explain them to others. Look up what metaphor means. Table of Contents Contents 1 ITERATION...

More information

Student Responsibilities. Mat 2170 Week 9. Notes About Using Methods. Recall: Writing Methods. Chapter Six: Objects and Classes

Student Responsibilities. Mat 2170 Week 9. Notes About Using Methods. Recall: Writing Methods. Chapter Six: Objects and Classes Student Responsibilities Mat 2170 Week 9 Objects and Classes Spring 2014 Reading: Textbook, Sections 6.1 6.3 Lab 9 Attendance 1 2 Recall: Writing Methods 3 Decomposition: break a problem down into smaller

More information

Declaring and ini,alizing 2D arrays

Declaring and ini,alizing 2D arrays Declaring and ini,alizing 2D arrays 4 2D Arrays (Savitch, Chapter 7.5) TOPICS Multidimensional Arrays 2D Array Allocation 2D Array Initialization TicTacToe Game // se2ng up a 2D array final int M=3, N=4;

More information

Full file at

Full 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 information

Reviewing 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 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 information

COMP 202 Java in one week

COMP 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 information

Instructor: Craig Duckett. Lecture 02: Thursday, March 29 th, 2018 SQL Basics and SELECT, FROM, WHERE

Instructor: Craig Duckett. Lecture 02: Thursday, March 29 th, 2018 SQL Basics and SELECT, FROM, WHERE Instructor: Craig Duckett Lecture 02: Thursday, March 29 th, 2018 SQL Basics and SELECT, FROM, WHERE 1 Assignment 1 is due LECTURE 5, Tuesday, April 10 th, 2018 in StudentTracker by MIDNIGHT MID-TERM EXAM

More information

Today. Homework 1 / Test 1 Making decisions in Java If statements If/Else ( Either-or ) statements Logical NOT operator

Today. Homework 1 / Test 1 Making decisions in Java If statements If/Else ( Either-or ) statements Logical NOT operator Today Homework 1 / Test 1 Making decisions in Java If statements If/Else ( Either-or ) statements Logical NOT operator BIT 115: Introduction To Programming 1 Something to Remember: In parameter order,

More information

Formatting & Style Examples

Formatting & Style Examples Formatting & Style Examples The code in the box on the right side is a program that shows an example of the desired formatting that is expected in this class. The boxes on the left side show variations

More information

CS2102: Lecture on Abstract Classes and Inheritance. Kathi Fisler

CS2102: Lecture on Abstract Classes and Inheritance. Kathi Fisler CS2102: Lecture on Abstract Classes and Inheritance Kathi Fisler How to Use These Slides These slides walk you through how to share common code (i.e., create helper methods) across classes I recommend

More information

Revising CS-M41. Oliver Kullmann Computer Science Department Swansea University. Linux Lab Swansea, December 13, 2011.

Revising CS-M41. Oliver Kullmann Computer Science Department Swansea University. Linux Lab Swansea, December 13, 2011. Computer Science Department Swansea University Linux Lab Swansea, December 13, 2011 How to use the revision lecture The purpose of this lecture (and the slides) is to emphasise the main topics of this

More information

If you don t, it will return the same thing as == But this may not be what you want... Several different kinds of equality to consider:

If you don t, it will return the same thing as == But this may not be what you want... Several different kinds of equality to consider: CS61B Summer 2006 Instructor: Erin Korber Lecture 5, 3 July Reading for tomorrow: Chs. 7 and 8 1 Comparing Objects Every class has an equals method, whether you write one or not. If you don t, it will

More information

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018 Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018 Due: Tuesday, September 18, 11:59 pm Collaboration Policy: Level 1 (review full policy for details) Group Policy: Individual This lab will give you experience

More information

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course : Advanced Java Concepts + Additional Questions from Earlier Parts of the Course 1. Given the following hierarchy: class Alpha {... class Beta extends Alpha {... class Gamma extends Beta {... In what order

More information

RANDOM NUMBER GAME PROJECT

RANDOM NUMBER GAME PROJECT Random Number Game RANDOM NUMBER GAME - Now it is time to put all your new knowledge to the test. You are going to build a random number game. - The game needs to generate a random number between 1 and

More information

Week 11: Class Design

Week 11: Class Design Week 11: Class Design 1 Most classes are meant to be used more than once This means that you have to think about what will be helpful for future programmers There are a number of trade-offs to consider

More information

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software. Introduction to Netbeans This document is a brief introduction to writing and compiling a program using the NetBeans Integrated Development Environment (IDE). An IDE is a program that automates and makes

More information

Programming overview

Programming 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 information

Programming assignment A

Programming assignment A Programming assignment A ASCII Minesweeper Official release on Feb 14 th at 1pm (Document may change before then without notice) Due 5pm Feb 25 th Minesweeper is computer game that was first written in

More information