CS 170 Java Programming 1. Week 15: Interfaces and Exceptions
|
|
- Neil Blair
- 5 years ago
- Views:
Transcription
1 CS 170 Java Programming 1 Week 15: Interfaces and Exceptions
2 Your "IC" or "Lab" Document Use Word or OpenOffice to create a new document Save the file as IC15.doc (Office compatible) Place on your network U: drive or on a thumb drive Put your name and today's date at the top of the sheet Title it "CS 170 Lab Exercises Week 15" Start DrJava and we'll review a few basic inheritance concepts from last week
3 Week 14 Review Two basic strategies for building new classes Specialization (regular) inheritance Subclass inherits non-private attributes and methods of superclass (but not constructors), adds members Example of an isa relationship; subclass object is substitutable for instance of superclass Composition: create new type with instances as parts Example of a hasa relationship Forward or delegate requests to instance variables
4 Introducing Abstract Classes Classes using the modifier abstract in the header public abstract class Shape { private int x, y; } The Shape class contains fields (x andy) that can be used to store its location on the display Add other fields and methods just like a regular class
5 Why Abstract Classes? Abstract classes allow you to create generic classes Common functionality only needs to be written once Know a method is needed but don t know the details A program like Visio needs to draw() shapes Each different kind of shape is drawn in a different way A generic deal() method for CardGame is useless Each concrete game deals its cards differently Abstract classes guarantee that all subclasses will implement a particular method, like draw() or deal()
6 Abstract Class Vocabulary Abstract classes are "incomplete" They cannot be used to create objects They may be extended to create new classes Abstract classes represent "generic" functionality The Component class is abstract, for instance It contains methods common to Buttons and Labels You cannot create a Component object You can create a Component variable You can also extend the Component class The subclasses are called concrete classes
7 Give Yourself a Hand 15.1: open the Hand class in DrJava Represents a generic hand of cards Add code to make Hand an abstract class Shoot a screen-shot 15.2: modify BeginnersBlackjack Add two Hand instance variables Name one player and the other dealer What happens if you initialize the variable? Try it and shoot a screen-shot
8 Abstract Methods An abstract method is a mandatory method Use the modifier abstract when defining the method Replace the body of the method with a semicolon public abstract class Shape { private int x, y; public abstract void draw(graphics g); } Class may also have normal methods
9 Evaluate Your Hand 15.3: add an abstract method to Hand Name the method evaluatehand() Returns an int representing the value of the specific hand based on the game being played (Snap) 15.4: add a regular method that calls your abstract method in the Hand class Name the method compareto(hand other) Return the difference between evaluating the current hand and the other hand. Snap a pic.
10 Extending an Abstract Class To use the abstract class, you extend the class and then override any (and all) abstract methods The resulting class is your concrete class 15.5: create a new class in DrJava Name: BlackjackHand Specify the Hand class as the superclass Try to compile. DrJava tells you what method is missing. Add actual scoring code from evaluatehand.txt (Q:) Uncomment testing code in init(), run and snap
11 Show the Score 15.6: write a showscore() method that takes a Hand object as its parameter Inside the method call the evaluatehand() method and display the result in the statuslbl on the screen. Call showscore() with your player variable Run and shoot a screenshot NOTICE: this is Polymorphism
12 What Are Interfaces? Something like an extremely abstract class Groups together otherwise unrelated classes An abstract class works with related classes An interface specifies what methods must be written Interfaces guarantee that an object will know how to respond to a particular message If you implement Comparable, Java "knows" your class contains a compareto() method An interface can contain onlyabstract methods Can write generic methods that accept interface types
13 Defining Interfaces Place in a file with the extension.java, just like a class Use the keyword interface instead of class public interface Paintable { public void paint(graphics g); } All methods are automaticallyabstract You don't have to use the abstract keyword The interface and all methods must be public
14 Using Interfaces You don't extend an interface, you implement it public class Whatever extends Widget implements Paintable { // Implement interface methods here } Class must contain a paint() method You may implement multiple interfaces
15 Sorting Cards In the Deck class, we used shuffle() to shuffle the Cards inside an ArrayList The shuffle() method orders the elements randomly The contents of each element don't matter The Collections class also has a sort() method Put each of the elements in a specific order 15.7A: Add a sort() method to the Deck class Call the Collections.sort() just like shuffle Compile: shoot a screenshot of error
16 The Problem with Sorting The sort() method doesn't care what kind of thing we want to sort, but it doesn't know how to sort cards! The PlayingCard class itself has to tell it which card must go first and when two cards are equal Do this by implementing the Comparable interface 15.7B : add this to the PlayingCard class header: implementscomparable<playingcard> Compile. Notice DrJava tells you what method to add You must add a compareto() method Snap a picture of the error
17 The Comparable Interface To make sort() work, we a method with this signature: // a.compareto(b) returns 0, >0, or <0 public int compareto(card othercard) { } If two cards are equal, return 0 If a is < b then return < 0; If a is > b then return > 0 Uncomment compareto() at bottom of class Places cards in rank-major order 15.7C: run CardSortDemo, press each button and snap
18 Java's Event-handling Java uses interfaces for all of its event handling These interfaces are called "listeners" Defined in the java.awt.event package Implement interfaces to respond to these events The classes you create to do this are called listener classes Most common "real-world" method of event handling uses anonymous inner classes to respond to each event The inner class will implement the appropriate interface This listener class will be defined inside your class
19 Subscribing to Events A JButton needs to know that you want events This works like subscribing to the paper You may be able to read it, but unless you "sign up" it won't be delivered to your door Add code like this to hook up the button: ActionListener handler = new MyHandler(); thebtn.addactionlistener(handler); Creates an instance of the MyHandler class and tells the thebtn to notify it whenever it is clicked
20 Anonymous Inner Classes Since we need only one handler class for each button, we can create an object at the same time as we define our class. Neither the class nor the object are named. This simplified syntax works for both classes and interfaces btn.addactionlistener( new ActionListener() { // anonymous class public void actionperformed(actionevent e) { // Carry out your actions here } } ); Called when clicked Access to outer vars
21 Deal a Hand 15.9: Locate the code for actionperformed() attached to the dealhandbtn Move the code from the "testing" section inside it Add dealerpile.removeall() as first line Removes cards from previous hands Modify the code so that the newdeck() method is called only if deck is null or it has fewer than 2 cards Run and click the dealhandbtnjbutton Shoot me a screen-shot
22 JButton Event Enabling Often, you'll want to enable or disable buttons depending on the results of a particular action Do that with the JButton'ssetEnabled() method newhandbtn.setenabled(true); // active hitbtn.setenabled(false); // deactivate 15.10: modify showscore() method Score 21: Win message, hit and stand off, deal on Score < 21: Hit or stand activated, deal off Score > 21: Bust message, hit & stand off
23 Do you want to Hit? 15.11: Here's what you should do for the Hit button If the deck has less than 1 card, call newdeck Add the top card to the player's hand Run and make sure you can hit. Snap a picture
24 Standing and Scoring 15.12: Here's what you should do for the Stand button Call newdeck if there are fewer than 2 cards Create a new hand for the dealer and add two cards Use a loop to keep adding cards to the dealer's hand while the score is <= 17. Call newdeck if you run out of cards Display the dealers cards in the dealerpile Call scoregame(), passing dealer and player. Run, play a game and snap me a picture.
25 Finishing Up If you didn't complete your IC "lab" document you may follow along in the online lessons this week to get the parts that you missed. Otherwise, just submit it now. Homework Assignments Six homework problems, no quiz 5 ArrayList problems 1 Inheritance problem Final Exam and Proficiency Makeup Next Week Sample exam available on BBV
CS 170 Java Programming 1. Week 12: Creating Your Own Types
CS 170 Java Programming 1 Week 12: Creating Your Own Types What s the Plan? Topic 1: A Little Review Work with loops to process arrays Write functions to process 2D Arrays in various ways Topic 2: Creating
More informationCS 170 Java Programming 1. Week 9: Learning about Loops
CS 170 Java Programming 1 Week 9: Learning about Loops What s the Plan? Topic 1: A Little Review ACM GUI Apps, Buttons, Text and Events Topic 2: Learning about Loops Different kinds of loops Using loops
More informationCS 170 Java Programming 1. Week 13: Classes, Testing, Debugging
CS 170 Java Programming 1 Week 13: Classes, Testing, Debugging What s the Plan? Short lecture for makeup exams Topic 1: A Little Review How to create your own user-defined classes Defining instance variables,
More informationCS 170 Java Programming 1. Week 5: Procedures and Functions
CS 170 Java Programming 1 Week 5: Procedures and Functions What s the Plan? Topic 1: More on graphical objects Creating your own custom Turtle types Introducing media, pictures and sounds Topic 2: Decomposition:
More informationCS 170 Java Programming 1. Week 10: Loops and Arrays
CS 170 Java Programming 1 Week 10: Loops and Arrays What s the Plan? Topic 1: A Little Review Use a counted loop to create graphical objects Write programs that use events and animation Topic 2: Advanced
More informationExpress Yourself. Writing Your Own Classes
Java Programming 1 Lecture 5 Defining Classes Creating your Own Classes Express Yourself Use OpenOffice Writer to create a new document Save the file as LastFirst_ic05 Replace LastFirst with your actual
More informationStructured Programming
CS 170 Java Programming 1 Objects and Variables A Little More History, Variables and Assignment, Objects, Classes, and Methods Structured Programming Ideas about how programs should be organized Functionally
More informationWeek 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 informationWeek 3: Objects, Input and Processing
CS 170 Java Programming 1 Week 3: Objects, Input and Processing Learning to Create Objects Learning to Accept Input Learning to Process Data What s the Plan? Topic I: Working with Java Objects Learning
More informationCS 170 Java Programming 1. Week 7: More on Logic
CS 170 Java Programming 1 Week 7: More on Logic What s the Plan? Topic 1: A Little Review Use relational operators to compare values Write functions using if and else to make decisions Topic 2: New Logical
More informationCSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:
CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Thursday 12:00 PM 2:00 PM Friday 8:30 AM 10:30 AM OR request appointment via e-mail
More informationJAVA MOCK TEST JAVA MOCK TEST II
http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your
More informationPolymorphism: Inheritance Interfaces
Polymorphism: Inheritance Interfaces 256 Recap Finish Deck class methods Questions about assignments? Review Player class for HW9 (starter zip posted) Lessons Learned: Arrays of objects require multiple
More informationName: CSC143 Exam 1 1 CSC 143. Exam 1. Write also your name in the appropriate box of the scantron
Name: CSC143 Exam 1 1 CSC 143 Exam 1 Write also your name in the appropriate box of the scantron Name: CSC143 Exam 1 2 Multiple Choice Questions (30 points) Answer all of the following questions. READ
More informationCS 251 Intermediate Programming Inheritance
CS 251 Intermediate Programming Inheritance Brooke Chenoweth University of New Mexico Spring 2018 Inheritance We don t inherit the earth from our parents, We only borrow it from our children. What is inheritance?
More informationWeek 9. Abstract Classes
Week 9 Abstract Classes Interfaces Arrays (Assigning, Passing, Returning) Multi-dimensional Arrays Abstract Classes Suppose we have derived Square and Circle subclasses from the superclass Shape. We may
More informationCS 11 java track: lecture 3
CS 11 java track: lecture 3 This week: documentation (javadoc) exception handling more on object-oriented programming (OOP) inheritance and polymorphism abstract classes and interfaces graphical user interfaces
More informationCS Exam 1 Review Suggestions
CS 235 - Fall 2015 - Exam 1 Review Suggestions p. 1 last modified: 2015-09-30 CS 235 - Exam 1 Review Suggestions You are responsible for material covered in class sessions, lab exercises, and homeworks;
More informationJava Programming Lecture 7
Java Programming Lecture 7 Alice E. Fischer Feb 16, 2015 Java Programming - L7... 1/16 Class Derivation Interfaces Examples Java Programming - L7... 2/16 Purpose of Derivation Class derivation is used
More informationExpress Yourself. What is Eclipse?
CS 170 Java Programming 1 Eclipse and the for Loop A Professional Integrated Development Environment Introducing Iteration Express Yourself Use OpenOffice or Word to create a new document Save the file
More informationSlide 1 CS 170 Java Programming 1
CS 170 Java Programming 1 Objects and Methods Performing Actions and Using Object Methods Slide 1 CS 170 Java Programming 1 Objects and Methods Duration: 00:01:14 Hi Folks. This is the CS 170, Java Programming
More informationCreating 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 informationCSE 70 Final Exam Fall 2009
Signature cs70f Name Student ID CSE 70 Final Exam Fall 2009 Page 1 (10 points) Page 2 (16 points) Page 3 (22 points) Page 4 (13 points) Page 5 (15 points) Page 6 (20 points) Page 7 (9 points) Page 8 (15
More informationCOMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )
COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) ) Course Evaluations Please do these. -Fast to do -Used to
More informationSTUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes
STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes Java Curriculum for AP Computer Science, Student Lesson A20 1 STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes INTRODUCTION:
More informationReview sheet for Final Exam (List of objectives for this course)
Review sheet for Final Exam (List of objectives for this course) Please be sure to see other review sheets for this semester Please be sure to review tests from this semester Week 1 Introduction Chapter
More informationUniversity of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner
University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Inheritance II Lecture 23, Thu Mar 30 2006 based on slides by Kurt Eiselt http://www.cs.ubc.ca/~tmm/courses/cpsc111-06-spr
More informationChapter 14 Abstract Classes and Interfaces
Chapter 14 Abstract Classes and Interfaces 1 What is abstract class? Abstract class is just like other class, but it marks with abstract keyword. In abstract class, methods that we want to be overridden
More informationINHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U
C A N A D I A N I N T E R N A T I O N A L S C H O O L O F H O N G K O N G INHERITANCE & POLYMORPHISM P2 LESSON 12 P2 LESSON 12.1 INTRODUCTION inheritance: OOP allows a programmer to define new classes
More informationMidterm assessment - MAKEUP Fall 2010
M257 MTA Faculty of Computer Studies Information Technology and Computing Date: /1/2011 Duration: 60 minutes 1-Version 1 M 257: Putting Java to Work Midterm assessment - MAKEUP Fall 2010 Student Name:
More informationUsing the API: Introductory Graphics Java Programming 1 Lesson 8
Using the API: Introductory Graphics Java Programming 1 Lesson 8 Using Java Provided Classes In this lesson we'll focus on using the Graphics class and its capabilities. This will serve two purposes: first
More informationMIT AITI Swing Event Model Lecture 17
MIT AITI 2004 Swing Event Model Lecture 17 The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the user. But how do GUIs interact with users? How do applications
More informationInterfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics
Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics 1 Collections (from the Java tutorial)* A collection (sometimes called a container) is simply an object that
More informationThroughout the exam, write concisely and underline key words or phrases. Have fun! Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031.
SE1021 Exam 2 Name: You may have an 8.5x11 note sheet for this exam. No calculators or other study aids on this exam. Write your initials at the tops of the following pages and read through the exam before
More informationAbstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.
a and Interfaces Class Shape Hierarchy Consider the following class hierarchy Shape Circle Square Problem AND Requirements Suppose that in order to exploit polymorphism, we specify that 2-D objects must
More informationCSE 331 Software Design and Implementation. Lecture 19 GUI Events
CSE 331 Software Design and Implementation Lecture 19 GUI Events Leah Perlmutter / Summer 2018 Announcements Announcements Quiz 7 due Thursday 8/9 Homework 8 due Thursday 8/9 HW8 has a regression testing
More informationDEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1
DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1 Objectives 1 6.1 Methods 1 void or return 1 Parameters 1 Invocation 1 Pass by value 1 6.2 GUI 2 JButton 2 6.3 Patterns
More informationInheritance and Interfaces
Inheritance and Interfaces what is inheritance? examples & Java API examples inheriting a method overriding a method polymorphism Object tostring interfaces Ex: sorting and Comparable interface Inheritance
More informationCSE 331 Software Design & Implementation
CSE 331 Software Design & Implementation Hal Perkins Spring 2017 GUI Event-Driven Programming 1 The plan User events and callbacks Event objects Event listeners Registering listeners to handle events Anonymous
More informationAP 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 informationGUI DYNAMICS Lecture July 26 CS2110 Summer 2011
GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI Statics and GUI Dynamics 2 Statics: what s drawn on the screen Components buttons, labels, lists, sliders, menus,... Containers: components that contain
More informationSlide 1 CS 170 Java Programming 1 Multidimensional Arrays Duration: 00:00:39 Advance mode: Auto
CS 170 Java Programming 1 Working with Rows and Columns Slide 1 CS 170 Java Programming 1 Duration: 00:00:39 Create a multidimensional array with multiple brackets int[ ] d1 = new int[5]; int[ ][ ] d2;
More information5.6.1 The Special Variable this
ALTHOUGH THE BASIC IDEAS of object-oriented programming are reasonably simple and clear, they are subtle, and they take time to get used to And unfortunately, beyond the basic ideas there are a lot of
More informationCSCE 156 Computer Science II
CSCE 156 Computer Science II Lab 04 - Classes & Constructors Dr. Chris Bourke Prior to Lab 1. Review this laboratory handout prior to lab. 2. Read Object Creation tutorial: http://download.oracle.com/javase/tutorial/java/javaoo/objectcreation.
More informationAdapter Pattern Structural
Adapter Pattern Structural Intent» Convert the interface of a class into a different interface that a client expects.» Lets classes work together that otherwise could not Adapter-1 Class Adapter Motivation
More informationCST242 Object-Oriented Programming Page 1
CST4 Object-Oriented Programming Page 4 5 6 67 67 7 8 89 89 9 0 0 0 Objected-Oriented Programming: Objected-Oriented CST4 Programming: CST4 ) Programmers should create systems that ) are easily extensible
More informationCSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction
CSC 160 LAB 8-1 DIGITAL PICTURE FRAME PROFESSOR GODFREY MUGANDA DEPARTMENT OF COMPUTER SCIENCE 1. Introduction Download and unzip the images folder from the course website. The folder contains 28 images
More informationCSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community
CSCI-12 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Provide a detailed explanation of what the following code does: 1 public boolean checkstring
More informationCreating Java Programs with Greenfoot
Creating Java Programs with Greenfoot Working with Source Code and Documentation 1 Copyright 2012, Oracle and/or its affiliates. All rights Objectives This lesson covers the following topics: Demonstrate
More informationTo gain experience using GUI components and listeners.
Lab 5 Handout 7 CSCI 134: Fall, 2017 TextPlay Objective To gain experience using GUI components and listeners. Note 1: You may work with a partner on this lab. If you do, turn in only one lab with both
More informationCIT 590 Homework 10 Battleship
CIT 590 Homework 10 Battleship Purposes of this assignment: To give you more experience with classes and inheritance General Idea of the Assignment Once again, this assignment is based on a game, since
More informationChapter 10 Classes Continued. Fundamentals of Java
Chapter 10 Classes Continued Objectives Know when it is appropriate to include class (static) variables and methods in a class. Understand the role of Java interfaces in a software system and define an
More informationDecisions: Logic Java Programming 2 Lesson 7
Decisions: Logic Java Programming 2 Lesson 7 In the Java 1 course we learned about if statements, which use booleans (true or false) to make decisions. In this lesson, we'll dig a little deeper and use
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 35 November 29, 2017 Swing II: Building GUIs Inner Classes Chapter 29 Announcements Game Project Complete Code Due: December 11 th NO LATE SUBMISSIONS
More information5. In JAVA, is exception handling implicit or explicit or both. Explain with the help of example java programs. [16]
Code No: R05220402 Set No. 1 1. (a) java is freeform language. Comment (b) Describe in detail the steps involved in implementing a stand-alone program. (c) What are command line arguments? How are they
More informationLecture 19 GUI Events
CSE 331 Software Design and Implementation Lecture 19 GUI Events The plan User events and callbacks Event objects Event listeners Registering listeners to handle events Anonymous inner classes Proper interaction
More informationSlide 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 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 informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 34 April 11, 2016 Swing II: Inner Classes and Layout Announcements (Review) Final exam: May 2, 3-5PM If you have two finals at the same time, you can
More informationSolution register itself
Observer Pattern Context: One object (the Subject) is the source of events. Other objects (Observers) want to know when an event occurs. Or: several objects should be immediately updated when the state
More informationG51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread
G51PGP Programming Paradigms Lecture 008 Inner classes, anonymous classes, Swing worker thread 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals
More informationFinal Exam CS 251, Intermediate Programming December 13, 2017
Final Exam CS 251, Intermediate Programming December 13, 2017 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible
More informationCS 3331 Advanced Object-Oriented Programming. Final Exam
1 Fall 2006 (Thursday, December 7) Name: CS 3331 Advanced Object-Oriented Programming Final Exam This test has 6 questions and pages numbered 1 through 12. Reminders This test is open book. You may also
More informationCS/ENGRD 2110 SPRING 2018
CS/ENGRD 2110 SPRING 2018 Lecture 7: Interfaces and http://courses.cs.cornell.edu/cs2110 1 2 St Valentine s Day! It's Valentines Day, and so fine! Good wishes to you I consign.* But since you're my students,
More informationLogistics. Final Exam on Friday at 3pm in CHEM 102
Java Review Logistics Final Exam on Friday at 3pm in CHEM 102 What is a class? A class is primarily a description of objects, or instances, of that class A class contains one or more constructors to create
More informationInheritance 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 informationSoftware Paradigms (Lesson 3) Object-Oriented Paradigm (2)
Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Table of Contents 1 Reusing Classes... 2 1.1 Composition... 2 1.2 Inheritance... 4 1.2.1 Extending Classes... 5 1.2.2 Method Overriding... 7 1.2.3
More informationObject Oriented Programming. Java-Lecture 11 Polymorphism
Object Oriented Programming Java-Lecture 11 Polymorphism Abstract Classes and Methods There will be a situation where you want to develop a design of a class which is common to many classes. Abstract class
More informationJava Programming Lecture 6
Java Programming Lecture 6 Alice E. Fischer Feb 15, 2013 Java Programming - L6... 1/32 Dialog Boxes Class Derivation The First Swing Programs: Snow and Moving The Second Swing Program: Smile Swing Components
More information1. (5 points) In your own words, describe what an instance is.
SE1021 Exam 2 Name: 1. (5 points) In your own words, describe what an instance is. 2. (5 points) Consider the Apple class in the UML diagram on the right. Write a couple lines of code to call the instance
More informationGlobal Gomoku Lab 4 in D0010E
Luleå University of Technology February 20, 2012 Computer Science Håkan Jonsson Global Gomoku Lab 4 in D0010E 1 Introduction Modern forms of communication are more and more carried out over the Internet,
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 35 November 28, 2018 Swing II: Inner Classes and Layout Chapter 30 Announcements Game Project Complete Code Due: December 10 th NO LATE SUBMISSIONS
More informationFinal 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 informationCOURSE 2 DESIGN PATTERNS
COURSE 2 DESIGN PATTERNS CONTENT Fundamental principles of OOP Encapsulation Inheritance Abstractisation Polymorphism [Exception Handling] Fundamental Patterns Inheritance Delegation Interface Abstract
More informationImplementing Graphical User Interfaces
Chapter 6 Implementing Graphical User Interfaces 6.1 Introduction To see aggregation and inheritance in action, we implement a graphical user interface (GUI for short). This chapter is not about GUIs,
More informationUCLA PIC 20A Java Programming
UCLA PIC 20A Java Programming Instructor: Ivo Dinov, Asst. Prof. In Statistics, Neurology and Program in Computing Teaching Assistant: Yon Seo Kim, PIC University of California, Los Angeles, Summer 2002
More informationAbstract Classes and Interfaces
Abstract methods Abstract Classes and Interfaces You can declare an object without defining it: Person p; Similarly, you can declare a method without defining it: public abstract void draw(int size); Notice
More information8. Polymorphism and Inheritance
8. Polymorphism and Inheritance Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch/info1 Objectives Describe polymorphism and inheritance in general Define interfaces
More information+! Today. Lecture 3: ArrayList & Standard Java Graphics 1/26/14! n Reading. n Objectives. n Reminders. n Standard Java Graphics (on course webpage)
+! Lecture 3: ArrayList & Standard Java Graphics +! Today n Reading n Standard Java Graphics (on course webpage) n Objectives n Review for this week s lab and homework assignment n Miscellanea (Random,
More informationPART1: Choose the correct answer and write it on the answer sheet:
PART1: Choose the correct answer and write it on the answer sheet: (15 marks 20 minutes) 1. Which of the following is included in Java SDK? a. Java interpreter c. Java disassembler b. Java debugger d.
More informationCheck out FilesAndExceptions from SVN. Exam 2 Review File I/O, Exceptions Vector Graphics Project
Check out FilesAndExceptions from SVN Exam 2 Review File I/O, Exceptions Vector Graphics Project Exam 2 review File I/O and Exceptions Vector Graphics project kickoff Exam is in class tomorrow Test on
More informationM257 Past Paper Oct 2008 Attempted Solution
M257 Past Paper Oct 2008 Attempted Solution Part 1 Question 1 A version of Java is a particular release of the language, which may be succeeded by subsequent updated versions at a later time. Some examples
More information[ L5P1] Object-Oriented Programming: Advanced Concepts
[ L5P1] Object-Oriented Programming: Advanced Concepts Polymorphism Polymorphism is an important and useful concept in the object-oriented paradigm. Take the example of writing a payroll application for
More informationCS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM
CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM Introduction to the Assignment In this lab, you will finish the program to allow a user to solve Sudoku puzzles.
More informationSubclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented
Table of Contents L01 - Introduction L02 - Strings Some Examples Reserved Characters Operations Immutability Equality Wrappers and Primitives Boxing/Unboxing Boxing Unboxing Formatting L03 - Input and
More informationSE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts
SE1021 Exam 2 Name: You may use a note-sheet for this exam. But all answers should be your own, not from slides or text. Review all questions before you get started. The exam is printed single-sided. Write
More informationCSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2015
CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2015 Name: This exam consists of 5 problems on the following 7 pages. You may use your double- sided hand- written 8 ½ x 11 note sheet
More informationPractice for Chapter 11
Practice for Chapter 11 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Object-oriented programming allows you to derive new classes from existing
More informationThis 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 informationCO Java SE 8: Fundamentals
CO-83527 Java SE 8: Fundamentals Summary Duration 5 Days Audience Application Developer, Developer, Project Manager, Systems Administrator, Technical Administrator, Technical Consultant and Web Administrator
More informationCS111: PROGRAMMING LANGUAGE II
1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 8(a): Abstract Classes Lecture Contents 2 Abstract base classes Concrete classes Dr. Amal Khalifa, 2014 Abstract Classes and Methods
More informationCS 3331 Advanced Object-Oriented Programming Final Exam
Fall 2015 (Thursday, December 3) Name: CS 3331 Advanced Object-Oriented Programming Final Exam This test has 5 questions and pages numbered 1 through 10. Reminders This test is closed-notes and closed-book.
More informationCS211 GUI Dynamics. Announcements. Motivation/Overview. Example Revisted
CS211 GUI Dynamics Announcements Prelim 2 rooms: A-M are in Olin 155 N-A are in Olin 255 Final exam: final exam 5/17, 9-11:30am final review session (TBA, likely Sun 5/15) Consulting: regular consulting
More informationInheritance, Polymorphism, and Interfaces
Inheritance, Polymorphism, and Interfaces Chapter 8 Inheritance Basics (ch.8 idea) Inheritance allows programmer to define a general superclass with certain properties (methods, fields/member variables)
More informationSlide 1 CS 170 Java Programming 1 Arrays and Loops Duration: 00:01:27 Advance mode: Auto
CS 170 Java Programming 1 Using Loops to Initialize and Modify Array Elements Slide 1 CS 170 Java Programming 1 Duration: 00:01:27 Welcome to the CS170, Java Programming 1 lecture on. Loop Guru, the album
More informationCMSC 132: Object-Oriented Programming II
CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation
More informationCS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG
CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG 1 Notice Reading Assignment Chapter 1: Introduction to Java Programming Homework 1 It is due this coming Sunday
More informationAbstract Classes and Polymorphism CSC 123 Fall 2018 Howard Rosenthal
Abstract Classes and Polymorphism CSC 123 Fall 2018 Howard Rosenthal Lesson Goals Define and discuss abstract classes Define and discuss abstract methods Introduce polymorphism Much of the information
More informationCritical Thinking Assignment #6: Java Program #6 of 6 (70 Points)
Critical Thinking Assignment #6: Java Program #6 of 6 (70 Points) Java Interactive GUI Application for Number Guessing with Colored Hints (based on Module 7 material) 1) Develop a Java application that
More informationReview Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous
Assignment 3 Methods Review CSC 123 Fall 2018 Notes: All homework must be submitted via e-mail. All parts of assignment must be submitted in a single e-mail with multiple attachments when required. Notes:
More information