Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 2
|
|
- Edwin Hardy
- 6 years ago
- Views:
Transcription
1 !"#
2 $ Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 2
3 % % % & ' &' " Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 3
4 &' () &' * &' ' " $ ) &' + " Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 4
5 %,, -. / %+!01#2 Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 5
6 boolean finished = false; while(!finished) { do something } if(exit condition) { finished = true; } else { do something more } Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 6
7 String input = reader.getinput();... String response = responder.generateresponse(); System.out.println(response); Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 7
8 %- String input = reader.getinput(); if(input.startswith("bye")) { finished = true; } '' 5 Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 8
9 $ 7 6%8 * $' ' 9) Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 9
10 * * Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 10
11 / 2 /2 Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 11
12 9 /- 2" %& " Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 12
13 & 9&", ) import java.util.arraylist; & ) import java.util.*; Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 13
14 ,),: if(input == "bye") {... } tests identity if(input.equals("bye")) {... } tests equality,/ 2' '.equals Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 14
15 :! /;,2) ) Fred ) Jill person1 person2 person1 == person2? Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 15
16 :< /;,2) ) Fred ) Fred person1 person2 person1 == person2? Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 16
17 := /;,2) ) Fred ) Fred person1 person2 person1 == person2? Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 17
18 :/,2 String input = reader.getinput(); if(input == "bye") {... } >> ), "bye" ), "bye" input / 2? Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 18
19 :/,2 String input = reader.getinput(); if(input.equals("bye")) {... } : ), "bye" ), "bye" input? Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 19
20 $ %Random import java.util.random;... Random randomgenerator = new Random();... int index1 = randomgenerator.nextint(); int index2 = randomgenerator.nextint(100); Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 20
21 @ public Responder() { randomgenerator = new Random(); responses = new ArrayList(); fillresponses(); } public String generateresponse() { int index = randomgenerator.nextint(responses.size()); return (String) responses.get(index); } public void fillresponses()... Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 21
22 " & " 8&' &&+ " - )&" Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 22
23 ',& )6 A9B A A8A A 6", A A/C=!20=0<DCEFA A/D#<2DC=1D1FDA A/00E2CDEE#!<=A Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 23
24 HashMap phonebook = new HashMap(); phonebook.put("charles Nguyen", "(531) "); phonebook.put("lisa Jones", "(402) "); phonebook.put("william H. Smith", "(998) "); String number = (String)phoneBook.get("Lisa Jones"); System.out.println(number); Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 24
25 import java.util.hashset; import java.util.iterator;... HashSet myset = new HashSet(); myset.add("one"); myset.add("two"); myset.add("three"); Iterator it = myset.iterator(); while(it.hasnext()) { call it.next() to get the next object do something with that object } Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 25
26 %&., public HashSet getinput() { System.out.print("> "); String inputline = readinputline().trim().tolowercase(); StringTokenizer tokenizer = new StringTokenizer(inputLine); HashSet words = new HashSet(); } while(tokenizer.hasmoretokens()) { words.add(tokenizer.nexttoken()); } return words; Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 26
27 (' ' " ' " &GG? Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 27
28 H! 4 Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 28
29 H! Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 29
30 9 ) /** * The Responder class represents a response * generator object. It is used to generate an * automatic response. * Michael Kölling and David J. Barnes 1.0 (1.Feb.2002) */ Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 30
31 ) /** * Read a line of text from standard input (the text * terminal), and return it as a set of words. * prompt A prompt to print to screen. A set of Strings, where each String is * one of the words typed by the user */ public HashSet getinput(string prompt) {... } Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 31
32 / " " ' " " Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 32
33 7 " I' ' +' " " " Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 33
34 9 Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 34
35 9 private static final int gravity = 3; private) + static) final) Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 35
36 $' -" ' " % ' ' &' / 2" % / 2" ' / + 2" Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling 36
More sophisticated behaviour
Objects First With Java A Practical Introduction Using BlueJ More sophisticated behaviour Using library classes to implement some more advanced functionality 2.0 Main concepts to be covered Using library
More informationMain loop structure. A Technical Support System. The exit condition. Main loop body
Main concepts to be covered More sophisticated behavior Using library classes Reading documentation Using library classes to implement some more advanced functionality 5.0 2 The Java class library Thousands
More informationCITS1001 week 6 Libraries
CITS1001 week 6 Libraries Arran Stewart April 12, 2018 1 / 52 Announcements Project 1 available mid-semester test self-assessment 2 / 52 Outline Using library classes to implement some more advanced functionality
More information5 More sophisticated behavior
Main concepts to be covered 5 More sophisticated behavior Using library classes to implement some more advanced functionality BK Chap. 6 Maps and sets Random number generation Equality vs identity Class
More informationMore Sophisticated Behaviour
More Sophisticated Behaviour Technical Support System V2.0 Produced by: Dr. Siobhán Drohan Mairead Meagher Based on Ch. 5, Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes,
More informationMore Sophisticated Behaviour
More Sophisticated Behaviour Technical Support System V3.0 Produced by: Dr. Siobhán Drohan Mairead Meagher Department of Computing and Mathematics http://www.wit.ie/ Topic List Recap: Technical Support
More informationMore Sophisticated Behaviour
More Sophisticated Behaviour Technical Support System V1.0 Produced by: Dr. Siobhán Drohan Mairead Meagher Based on Ch. 5, Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes,
More informationText User Interfaces. Keyboard IO plus
Text User Interfaces Keyboard IO plus User Interface and Model Model: objects that solve problem at hand. User interface: interacts with user getting input from user giving output to user reporting on
More informationGrouping objects. Main concepts to be covered
Grouping objects Collections and iterators 3.0 Main concepts to be covered Collections Loops Iterators Arrays Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling
More informationGrouping objects. The requirement to group objects
Grouping objects Introduction to collections 4.0 The requirement to group objects Many applications involve collections of objects: Personal organizers. Library catalogs. Student-record system. The number
More informationPackage: java.util It generates random numbers An instance is created by using one of the two constructors:
Exercise 5.2 The documentation contains the following sections: Overall description of the class: its purpose and how to use it A brief summary of the fields A brief summary of the constructors A brief
More informationSome miscellaneous concepts
Some miscellaneous concepts Static, Javadoc and Calculated Data Produced by: Dr. Siobhán Drohan Mairead Meagher Department of Computing and Mathematics http://www.wit.ie/ Topic List Static Variables Static
More informationMODULE 6q - Exceptions
MODULE 6q - Exceptions THE TRY-CATCH CONSTRUCT Three different exceptions are referred to in the program below. They are the ArrayIndexOutOfBoundsException which is built-into Java and two others, BadLuckException
More informationCITS1001 week 4 Grouping objects
CITS1001 week 4 Grouping objects Arran Stewart March 20, 2018 1 / 31 Overview In this lecture, we look at how can group objects together into collections. Main concepts: The ArrayList collection Processing
More informationScope of this lecture. Repetition For loops While loops
REPETITION CITS1001 2 Scope of this lecture Repetition For loops While loops Repetition Computers are good at repetition We have already seen the for each loop The for loop is a more general loop form
More informationMore sophisticated behaviour Lecture 09
More sophisticated behaviour Lecture 09 Waterford Institute of Technology February 22, 2016 John Fitzgerald Waterford Institute of Technology, More sophisticated behaviour Lecture 09 1/42 Presentation
More informationObject Oriented Design: Identifying Objects
Object Oriented Design: Identifying Objects Review What did we do in the last lab? What did you learn? What classes did we use? What objects did we use? What is the difference between a class and an object?
More informationTicket Machine Project(s)
Ticket Machine Project(s) Understanding the basic contents of classes Produced by: Dr. Siobhán Drohan (based on Chapter 2, Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes,
More informationObjects First with Java A Practical Introduction using BlueJ
Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling Extensions by H.-J. Bungartz and T. Neckel 2.1 Course Contents Introduction to object-oriented programming with
More informationObjects First with Java A Practical Introduction using BlueJ
Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling Extensions by H.-J. Bungartz, T. Neckel and M. Roderus 2.1 Course Contents Introduction to object-oriented programming
More informationThe class diagram contains only 2 elements: LabClass and Student. The LabClass class is linked to the Student class.
Instant download and all chapters Solution Manual Objects First with Java A Practical Introduction Using BlueJ 5th Edition David J. Barnes Michael Kolling https://testbankdata.com/download/solution-manual-objects-first-java-practicalintroduction-using-bluej-5th-edition-david-j-barnes-michael-kolling/
More informationJava code(assembler) ******************************************************************* package A1;
Java code(assembler) ******************************************************************* package A1; import java.io.bufferedreader; import java.io.fileinputstream; import java.io.filewriter; import java.io.inputstreamreader;
More information1B1a Arrays. Arrays. Indexing. Naming arrays. Why? Using indexing. 1B1a Lecture Slides. Copyright 2003, Graham Roberts 1
Ba Arrays Arrays A normal variable holds value: An array variable holds a collection of values: 4 Naming arrays An array has a single name, so the elements are numbered or indexed. 0 3 4 5 Numbering starts
More informationOBJECT INTERACTION. CITS1001 week 3
OBJECT INTERACTION CITS1001 week 3 2 Fundamental concepts Coupling and Cohesion Internal/external method calls null objects Chaining method calls Class constants Class variables Reading: Chapter 3 of Objects
More informationLab: PiggyBank. Defining objects & classes
Lab: PiggyBank Defining objects & classes Review: Basic class structure public class ClassName { Fields Constructors Methods } Three major components of a class: Fields store data for the object to use
More informationLec #6: Review, Generics and Recursion
Lec #6: Review, Generics and Recursion 1 Introductions and sounding out? (5 min) 2 Review (25 min) 3 Generics (15 min) 4 Recursion (40 min) 5 Forward guidance (5 min) Timings approximate: Interruptions
More informationWell-behaved Objects. Most of the chapter focuses on testing Our first project will involve a diary
Well-behaved Objects Most of the chapter focuses on testing Our first project will involve a diary We will study the code and then look at some test programs We will see how testing can be automated We
More informationPROGRAMMING FUNDAMENTALS
PROGRAMMING FUNDAMENTALS Q1. Name any two Object Oriented Programming languages? Q2. Why is java called a platform independent language? Q3. Elaborate the java Compilation process. Q4. Why do we write
More informationTopic 10: The Java Collections Framework (and Iterators)
Topic 10: The Java Collections Framework (and Iterators) A set of interfaces and classes to help manage collections of data. Why study the Collections Framework? very useful in many different kinds of
More informationOBJECT INTERACTION CITS1001
OBJECT INTERACTION CITS1001 Overview Coupling and Cohesion Internal/external method calls null objects Chaining method calls Class constants Class variables A digital clock Abstraction and modularization
More informationCS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes
CS111: PROGRAMMING LANGUAGE II Lecture 1: Introduction to classes Lecture Contents 2 What is a class? Encapsulation Class basics: Data Methods Objects Defining and using a class In Java 3 Java is an object-oriented
More informationCS111: PROGRAMMING LANGUAGE II
CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1(c): Java Basics (II) Lecture Contents Java basics (part II) Conditions Loops Methods Conditions & Branching Conditional Statements A
More informationAlgorithms. Produced by. Eamonn de Leastar
Algorithms Produced by Eamonn de Leastar (edeleastar@wit.ie) Collections ± Collections Architecture ± Definition ± Architecture ± Interfaces ± Collection ± List ± Set ± Map ± Iterator ± Implementations
More informationIntroduc)on to tes)ng with JUnit. Workshop 3
Introduc)on to tes)ng with JUnit Workshop 3 We have to deal with errors Early errors are usually syntax errors. The compiler will spot these. Later errors are usually logic errors. The compiler cannot
More informationSoftware Design Models, Tools & Processes. Lecture 6: Transition Phase Cecilia Mascolo
Software Design Models, Tools & Processes Lecture 6: Transition Phase Cecilia Mascolo UML Component diagram Component documentation Your own classes should be documented the same way library classes are.
More informationChapter 10 Collections
Chapter 10 Collections I. Scott MacKenzie 1 Outline 2 1 What is a Collection? A collection is an aggregation with a variable number of components, or elements Examples Portfolio - a collection of Investment
More informationWhat is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one
Iterators What is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one 9-2 2-2 What is an Iterator? An iterator is an abstract data
More informationScope of this lecture
ARRAYS CITS11 2 Scope of this lecture Arrays (fixed size collections) Declaring and constructing arrays Using and returning arrays Aliasing Reading: Chapter 7 of Objects First with Java 6 th Edition Chapter
More informationSet<Integer> s = new TreeSet<Integer>(); s.add( 7 ); s.add( 7 ); System.out.println( s.size() );
Advanced Java Concepts Maps and Sets and Miscellany Exercises and Programs 1. This code a) contains a compiler error. b) contains a runtime error. c) displays 1 d) displays 2 2. This code a) contains a
More informationComputational Expression
Computational Expression ArrayList Iterators Janyl Jumadinova 7-14 November, 2018 Janyl Jumadinova Computational Expression 7-14 November, 2018 1 / 11 Collections Collection: an object that stores data;
More informationUNDERSTANDING CLASS DEFINITIONS CITS1001
UNDERSTANDING CLASS DEFINITIONS CITS1001 Main concepts to be covered Fields / Attributes Constructors Methods Parameters Source ppts: Objects First with Java - A Practical Introduction using BlueJ, David
More informationImplementation. Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations
Readings List Implementations Chapter 20.2 Objectives Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations Additional references:
More informationMIT AITI Lecture 18 Collections - Part 1
MIT AITI 2004 - Lecture 18 Collections - Part 1 Collections API The package java.util is often called the "Collections API" Extremely useful classes that you must understand to be a competent Java programmer
More informationUnderstanding class definitions. Looking inside classes (based on lecture slides by Barnes and Kölling)
Understanding class definitions Looking inside classes (based on lecture slides by Barnes and Kölling) Main Concepts fields constructors methods parameters assignment statements Ticket Machines (an external
More informationToday's Agenda. > To give a practical introduction to data structures. > To look specifically at Lists, Sets, and Maps
Today's Agenda > To give a practical introduction to data structures > To look specifically at Lists, Sets, and Maps > To talk briefly about Generics in Java > To talk about interfaces in Java Data Structures
More informationJava for Interfaces and Networks (DT3010, HT11)
Java for Interfaces and Networks (DT3010, HT11) Networking with Threads and Federico Pecora School of Science and Technology Örebro University federico.pecora@oru.se Federico Pecora Java for Interfaces
More informationOverview of Java ArrayList, HashTable, HashMap, Hashet,LinkedList
Overview of Java ArrayList, HashTable, HashMap, Hashet,LinkedList This article discusses the main classes of Java Collection API. The following figure demonstrates the Java Collection framework. Figure
More informationIntroduction to Computer Science I
Introduction to Computer Science I Iterators ArrayList Janyl Jumadinova October 31, 2016 Iterators One of the most useful operations for any collection is the ability to run through each of the elements
More information//instance variables //methods. Foo x = new Foo(); Interface: also a type of objects public interface Bar {
BASIC CONCEPTS Class: a type of objects public class Foo { //instance variables //methods Foo x = new Foo(); Interface: also a type of objects public interface Bar { //method headers without implementation
More informationJava for Interfaces and Networks (DT3029)
Java for Interfaces and Networks (DT3029) Lecture 4 Networking with Threads and Containers Federico Pecora federico.pecora@oru.se Center for Applied Autonomous Sensor Systems (AASS) Örebro University,
More informationIntroduction to programming the FRDM/MBED in Java David J. https://www.cs.kent.ac.uk/~djb/
Introduction to programming the FRDM/MBED in Java David J. Barnes d.j.barnes@kent.ac.uk @kentdjb https://www.cs.kent.ac.uk/~djb/ Introduction This document is an introduction to programming a FRDM/MBED
More informationmith College Computer Science Sets and Hashing CSC212 Fall 2014 Dominique Thiébaut
mith College Computer Science Sets and Hashing CSC22 Fall 204 Dominique Thiébaut dthiebaut@smith.edu The Problem: Large amount of live tweets Want the list of all tweeters Each only listed once What data
More informationRepetition, Looping. While Loop
Repetition, Looping Last time we looked at how to use if-then statements to control the flow of a program. In this section we will look at different ways to repeat blocks of statements. Such repetitions
More informationGuessing 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 informationCollections. James Brucker
Collections James Brucker Collection A Collection is a group of objects. Set an unordered collection no duplicates List ordered collection duplicates are allowed can add or remove elements anywhere in
More informationAP Programming - Chapter 6 Lecture
page 1 of 21 The while Statement, Types of Loops, Looping Subtasks, Nested Loops I. The while Statement Note: Loop - a control structure that causes a sequence of statement(s) to be executed repeatedly.
More informationWeek 4, Wednesday (Spring 2015). Dr. Yoder. Sec 051. Page 1 of 5
CS2852 Exam 1 Name: No note-sheets, calculators, or other study aids on this exam. Write your initials at the top of each page except this one. Read through the whole exam before you get started. Have
More informationGrouping objects Lecture 7
Grouping objects Lecture 7 Waterford Institute of Technology February 2, 2016 John Fitzgerald Waterford Institute of Technology, Grouping objects Lecture 7 1/36 Presentation outline Estimated duration
More informationComputing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer
Computing Science 114 Solutions to Midterm Examination Tuesday October 19, 2004 INSTRUCTOR: I E LEONARD TIME: 50 MINUTES In Questions 1 20, Circle EXACTLY ONE choice as the best answer 1 [2 pts] What company
More information1. Suppose you are using a HashMap<String,Integer>. What is the runtime of put and get assuming you have a reasonable hash function?
Data Structures Brett Bernstein Lecture 10: BitSets and Packages Exercises 1. Suppose you are using a HashMap. What is the runtime of put and get assuming you have a reasonable hash function?
More informationAppendix A: Interfaces and Classes in the AP Java Subset (AB)
Appendix A: Interfaces and Classes in the AP Java Subset (AB) class java.lang.object int hashcode() java.lang: interface java.lang.comparable ; class java.lang.integer Integer(int value) int intvalue()
More informationCS 211 Programming Practicum Spring 2017
Due: Tuesday, 3/28/17 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a JAVA program that will evaluate an infix expression. The algorithm REQUIRED for this program will
More informationCMPS 290G Topics in Software Engineering Winter 2004 Software Validation and Defect Detection Homework 5
CMPS 290G Topics in Software Engineering Winter 2004 Software Validation and Defect Detection Homework 5 Due: by email to cormac@cs.ucsc.edu before or on 18 March 2004 This homework is in the form of a
More informationDepartment of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Final Exam: 2 Hours, Open Book and Open Notes
Department of Civil and Environmental Engineering, Spring Semester, 2017 ENCE 688R: Final Exam: 2 Hours, Open Book and Open Notes Name : Question Points Score 1 50 2 30 3 20 Total 100 1 Question 1: 50
More informationBBM 102 Introduction to Programming II Spring 2017
BBM 102 Introduction to Programming II Spring 2017 Collections Framework Instructors: Ayça Tarhan, Fuat Akal, Gönenç Ercan, Vahid Garousi 1 Today The java.util.arrays class Java Collection Framework java.util.collection
More informationBBM 102 Introduction to Programming II Spring 2017
BBM 102 Introduction to Programming II Spring 2017 Collections Framework Today The java.util.arrays class Java Collection Framework java.util.collection interface java.util.list interface java.util.arraylist
More informationCS1083 Week 2: Arrays, ArrayList
CS1083 Week 2: Arrays, ArrayList mostly review David Bremner 2018-01-08 Arrays (1D) Declaring and using 2D Arrays 2D Array Example ArrayList and Generics Multiple references to an array d o u b l e prices
More informationReview. CSE 143 Java. A Magical Strategy. Hash Function Example. Want to implement Sets of objects Want fast contains( ), add( )
Review CSE 143 Java Hashing Want to implement Sets of objects Want fast contains( ), add( ) One strategy: a sorted list OK contains( ): use binary search Slow add( ): have to maintain list in sorted order
More informationLecture 9: Lists. MIT-AITI Kenya 2005
Lecture 9: Lists MIT-AITI Kenya 2005 1 In this lecture we will learn. ArrayList These are re-sizeable arrays LinkedList brief overview Differences between Arrays and ArrayLists Casting Iterator method
More informationCS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle
Boggle If you are not familiar with the game Boggle, the game is played with 16 dice that have letters on all faces. The dice are randomly deposited into a four-by-four grid so that the players see the
More informationCOSC 123 Computer Creativity. Java Lists and Arrays. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 123 Computer Creativity Java Lists and Arrays Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Objectives 1) Create and use arrays of base types and objects. 2) Create
More informationWhat happens if someone new wants to join our awesome club?
If a variable is like a box an array is like a box with compartments The compartments in arrays are numbered (the element number, starting at 0) and they have a fixed length Once the length is set it cannot
More informationThe class Object. Lecture CS1122 Summer 2008
The class Object http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object.html Lecture 10 -- CS1122 Summer 2008 Review Object is at the top of every hierarchy. Every class in Java has an IS-A relationship
More information// initialize array to true. for (i = 0; i < s; i++) f[i] = true; // get rid of known non-primes f[0] = f[1] = false;
Listing 1: GeneratePrimes.java This class Generates prime numbers up to a user specified maximum. The algorithm used is the Sieve of Eratosthenes. Eratosthenes of Cyrene, b. c. 276 BC, Cyrene, Libya
More informationCS 146 Spring 2017 Homework 4 Sections 5 and 6. The homework assignment is available at:
The homework assignment is available at: http://www.jennylam.cc/courses/146-s17/homework04.html 1. Here is a working Java solution which runs in linear time in the total length of the input lists. /**
More informationToday: Java Library Classes for lists. Iterators, ListIterators. CS61B Lecture #7. Last modified: Fri Sep 12 14:41: CS61B: Lecture #7 1
Today: Java Library Classes for lists. Iterators, ListIterators CS61B Lecture #7 Last modified: Fri Sep 12 14:41:31 2008 CS61B: Lecture #7 1 Abstracting Listness So far, we ve seen fairly primitive types
More informationSCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming
s SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177 Programming Time allowed: THREE hours: Answer: ALL questions Items permitted: Items supplied: There is
More informationExample Program. public class ComputeArea {
COMMENTS While most people think of computer programs as a tool for telling computers what to do, programs are actually much more than that. Computer programs are written in human readable language for
More information1. ArrayList and Iterator in Java
1. ArrayList and Iterator in Java Inserting elements between existing elements of an ArrayList or Vector is an inefficient operation- all element after the new one must be moved out of the way which could
More informationModule Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1
UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2017-18 PROGRAMMING 1 CMP-4008Y Time allowed: 2 hours Answer FOUR questions. All questions carry equal weight. Notes are
More informationTECHNICAL WHITEPAPER. Performance Evaluation Java Collections Framework. Performance Evaluation Java Collections. Technical Whitepaper.
Performance Evaluation Java Collections Framework TECHNICAL WHITEPAPER Author: Kapil Viren Ahuja Date: October 17, 2008 Table of Contents 1 Introduction...3 1.1 Scope of this document...3 1.2 Intended
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: Tuesday 10:00 AM 12:00 PM * Wednesday 4:00 PM 5:00 PM Friday 11:00 AM 12:00 PM OR
More informationCS 211 Programming Practicum Spring 2018
Due: Thursday, 4/5/18 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a C++ program that will evaluate an infix expression. The algorithm REQUIRED for this program will
More informationCOMP-202: Foundations of Programming. Lecture 26: Review; Wrap-Up Jackie Cheung, Winter 2016
COMP-202: Foundations of Programming Lecture 26: Review; Wrap-Up Jackie Cheung, Winter 2016 Announcements Final is scheduled for Apr 21, 2pm 5pm GYM FIELD HOUSE Rows 1-21 Please submit course evaluations!
More informationAbout This Lecture. Repetition Control Structures - while. Outline. Repetition
2 About This Lecture Repetition Control Structures - while Cmput 114 - Lecture 16 Department of Computing Science University of Alberta z So far our programs execute each statement exactly once or zero
More informationEXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2011 Trimester 2, MID-TERM TEST COMP103 Introduction
More informationUniversity of Massachusetts Amherst, Electrical and Computer Engineering
University of Massachusetts Amherst, Electrical and Computer Engineering ECE 122 Midterm Exam 1 Makeup Answer key March 2, 2018 Instructions: Closed book, Calculators allowed; Duration:120 minutes; Write
More informationLecture 22: Java. Overall Structure. Classes & Objects. Every statement must end with ';' Carl Kingsford, , Fall 2015
Carl Kingsford, 0-0, Fall 0 Lecture : Java Overall Structure Classes & Objects Every function in Java must be inside a class, which are similar to Go's struct s. For example: 8 9 0 8 9 class MyProgram
More informationCS2110: Software Development Methods. Maps and Sets in Java
CS2110: Software Development Methods Maps and Sets in Java These slides are to help with the lab, Finding Your Way with Maps Today s lab uses Maps (and Sets but just a little). Readings from textbook:
More informationSolution to Test of Computer Science 203x Level Score: / 100 Time: 100 Minutes
Solution to Test of Computer Science 203x Level Score: / 100 Time: 100 Minutes PART I: Multiple Choice (3 points each) Note: The correct answer can be any combination of A, B, C, D. Example, Sample Question:
More informationCS 310: Maps and Sets and Trees
CS 310: Maps and Sets and Trees Chris Kauman Week 8-2 Logistics Oce hours Wednesday normal: 4:30-5:30pm Thursday 2-3pm special oce hours Reading Weiss Ch. 6 (Java Library Classes/Interfaces) 6.7 Sets,
More informationInterfaces, collections and comparisons
תכנות מונחה עצמים תרגול מספר 4 Interfaces, collections and comparisons Interfaces Overview Overview O Interface defines behavior. Overview O Interface defines behavior. O The interface includes: O Name
More informationCSE 143 Au03 Midterm 2 Page 1 of 7
CSE 143 Au03 Midterm 2 Page 1 of 7 Question 1. (4 points) (a) If a precondition is not true when a method is called, two possible ways to detect and handle the situation are to use an assert statement
More informationAhmadu Bello University, Zaria Department of Computer Science
Ahmadu Bello University, Zaria Department of Computer Science 216/217 First Semester Test 2 COSC 211 Object Oriented Programming I Date: February 1, 217 Time Allowed: 6 Minutes Instructions: Attempt Question
More informationMore on Strings. String methods and equality. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Compu<ng and Mathema<cs h=p://www.wit.
More on Strings String methods and equality Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Compu
More informationEXAMINATION INSTRUCTIONS
EXAMINATION INSTRUCTIONS This examination has 6 pages. Check that you have a complete paper. Each candidate should be prepared to produce, upon request, his or her SUNY/UB card. This examination has 5
More informationInheritance. Exploring Polymorphism. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics
Inheritance Exploring Polymorphism Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Lectures and Labs This weeks lectures and labs are based on
More informationCS 310: Maps and Sets
CS 310: Maps and Sets Chris Kauffman Week 9-1 Logistics Goals Today HW2 Discussion Maps and Sets HW2 Discussion Milestones due Thu 7/6 Discuss AdditiveList Iterator Implementation O(1) Undo/Redo Reading
More informationStrings. Strings and their methods. Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics
Strings Strings and their methods Produced by: Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list Primitive Types: char Object Types: String Primitive vs Object Types
More information1.00/ Introduction to Computers and Engineering Problem Solving. Final / December 13, 2004
1.00/1.001 Introduction to Computers and Engineering Problem Solving Final / December 13, 2004 Name: Email Address: TA: Section: You have 180 minutes to complete this exam. For coding questions, you do
More information