Exercise Sheet 1 - Solutions
|
|
- Ursula Robinson
- 5 years ago
- Views:
Transcription
1 Exercise Sheet 1 - Solutions Alessandro Gnoatto October 23, Exercise 1 / 2 4 package de. lmu. firstclass ; 6 Alessandro Gnoatto 8 10 public class ComplexNumber { //fields 12 private double real ; private double imag ; //specify a constructor public ComplexNumber (double real, double imag ){ 18 this. real = real ; this. imag = imag ; //get methods public double getreal (){ 24 return this. real ; 26 public double getimag (){ 28 return this. real ; 30 //set methods 32 public void setreal (double real ){ this. real = real ; public void setimag (double imag ){ this. imag = imag ; //some methods public s t a t i c ComplexNumber add ( ComplexNumber a, ComplexNumber b){ 42 return new ComplexNumber (a. real +b.real,a. imag +b. imag ); 44 1
2 public s t a t i c ComplexNumber subtract ( ComplexNumber a, ComplexNumber b){ 46 return new ComplexNumber (a.real -b.real,a.imag -b. imag ); 48 public s t a t i c ComplexNumber multiply ( ComplexNumber a, ComplexNumber b){ 50 return new ComplexNumber ( a. real * b. real - a. imag * b. imag,a. imag * b. real + a. real * b. imag ); public s t a t i c ComplexNumber divide ( ComplexNumber a, ComplexNumber b){ return new ComplexNumber (( a. real * b. real + a. imag * b. imag ) 56 /(b. real * b. real - b. imag * b. imag ), (a. imag * b. real - a. real * b. imag ) 58 /(b. real * b. real - b. imag * b. imag )); 60 public s t a t i c double abs ( ComplexNumber a){ 62 return Math. sqrt (a. real *a. real +a. imag *a. imag ); Exercise Interface / 2 (c) Copyright Christian P. Fries, Germany. All rights reserved. Contact: @christian fries.de. 4 Created on package net. finmath. time ; 8 import java. util. ArrayList ; 10 Christian Fries 12 public interface TimeDiscretizationInterface extends Iterable < Double > { 14 / Returns the number of time discretization points. 18 int getnumberoftimes (); 20 Returns the number of time steps (= number of discretization points 1). 22 int getnumberoftimesteps (); 24 / 26 Returns the time for the given time index. 2
3 timeindex Time Returns the time for a given time index. 30 double gettime ( int timeindex ); 32 / 34 Returns the time step from the given time index to the next one. timeindex Time Returns the time step 38 double gettimestep ( int timeindex ); 40 / 42 Returns the time index for the given time. If the given time is not in the time discretization the method returns a negative number being ( insertionpoint 1). time The time. Returns the time index for a given time. 48 int gettimeindex (double time ); 50 / Returns the time index for the time in the time discretization which is the nearest 52 to the given time, being less or equal (i.e. max(i : timediscretization[i] time where timediscretization[i] timediscretization[j]). time Given time. Returns a time index 58 int gettimeindexnearestlessorequal (double time ); 60 / Returns the time index for the time in the time discretization which is the nearest 62 to the given time, being greater or equal (i.e. min(i : timediscretization[i] time where timediscretization[i] timediscretization[j]). time Given time. Returns a time index 68 int gettimeindexnearestgreaterorequal (double time ); 70 / Return a clone of this time discretization as <code> double[]</code>. The time discretization as <code>double[]</code> 74 double[] getasdoublearray (); 76 / Return a clone of this time discretization as <code> ArrayList<Double></code>. 78 Note that this method is costly in terms of performance. 3
4 The time discretization as <code>arraylist< Double></code> 82 ArrayList < Double > getasarraylist (); 84 / 86 Return a new time discretization where all time points have been shifted by a given time shift. timeshift A time shift applied to all discretization points. A new time discretization where all time points have been shifted by the given time shift. 92 TimeDiscretizationInterface gettimeshiftedtimediscretization (double timeshift ); 2.2 Class / 2 (c) Copyright Christian P. Fries, Germany. All rights reserved. Contact: @christian fries.de. 4 Created on package net. finmath. time ; 8 import java. io. Serializable ; import java. util. ArrayList ; 10 import java. util. Arrays ; import java. util. Iterator ; 12 / 14 This class represents a set of discrete points in time. <br> 16 It handles the mapping from time indices to time points and back. It uses a time tick size ("quantum") of 1.0 / ( ) (which corresponds to one hour if 1.0 is a non leap year): 18 Times are rounded to the nearest multiple of 1.0 / ( ). 20 Objects of this class are immutable. Christian public class TimeDiscretization implements Serializable, TimeDiscretizationInterface { private s t a t i c f i n a l long serialversionuid = L; private f i n a l double[] timediscretization ; 30 private f i n a l double timeticksize = 1.0 / (365.0 * 24.0) ; 32 public enum ShortPeriodLocation { 4
5 SHORT_PERIOD_AT_START, 34 SHORT_PERIOD_AT_END 36 / 38 Constructs a time discretization from a given set of doubles. times Given array or arguments list of discretization points. 42 public TimeDiscretization (double... times ) { super(); 44 this. timediscretization = times. clone (); java. util. Arrays. sort ( this. timediscretization ); / Constructs a time discretization from a given set of Doubles. times Given array or arguments list of discretization points 52 public TimeDiscretization ( Double [] times ) { 54 super(); this. timediscretization = new double[ times. length ]; 56 for ( int timeindex =0; timeindex < timediscretization. length ; timeindex ++) this. timediscretization [ timeindex ] = roundtotimeticksize ( times [ timeindex ]); java. util. Arrays. sort ( this. timediscretization ); / Constructs a time discretization from a given ArrayList of Doubles. timediscretization Given ArrayList of discretization points 64 public TimeDiscretization ( ArrayList < Double > timediscretization ) { 66 super(); this. timediscretization = new double[ timediscretization. size () ]; 68 for ( int timeindex =0; timeindex < timediscretization. size (); timeindex ++) this. timediscretization [ timeindex ] = roundtotimeticksize ( timediscretization. get ( timeindex )) ; java. util. Arrays. sort ( this. timediscretization ); / Constructs an equi distant time discretization with points timediscretization[i] being 74 <code>for(i=0; i timesteps; i++) timediscretization[ i] = initial + i deltat;</code> initial First discretization numberoftimesteps Number of time steps. deltat Time step size. 5
6 80 public TimeDiscretization (double initial, int numberoftimesteps, double deltat ) { super(); 82 timediscretization = new double[ numberoftimesteps +1]; for ( int timeindex =0; timeindex < timediscretization. length ; timeindex ++) timediscretization [ timeindex ] = roundtotimeticksize ( initial + timeindex * deltat ); / Constructs an equi distant time discretization with stub periods at start or end. initial First discretization point. last Last time deltat Time step size. shortperiodlocation Placement of the stub period. 94 public TimeDiscretization (double initial, double last, double deltat, ShortPeriodLocation shortperiodlocation ) { super(); 96 int numberoftimesteps = ( int )(( last - initial )/ deltat + 0.5) ; 98 // Adjust for short period, if any i f ( roundtotimeticksize ( initial + numberoftimesteps * deltat ) < roundtotimeticksize ( last )) numberoftimesteps ++; 100 timediscretization = new double[ numberoftimesteps +1]; 102 i f ( shortperiodlocation == ShortPeriodLocation. SHORT_PERIOD_AT_END ) { for ( int timeindex =0; timeindex < timediscretization. length ; timeindex ++) timediscretization [ timeindex ] = roundtotimeticksize ( initial + timeindex * deltat ); 104 timediscretization [ timediscretization. length -1] = last ; 106 else { for ( int timeindex =0; timeindex < timediscretization. length ; timeindex ++) timediscretization [ timeindex ] = roundtotimeticksize ( last - ( numberoftimesteps - timeindex ) * deltat ); 108 timediscretization [0] = initial ; 110 public int getnumberoftimes () { 114 return timediscretization. length ; 118 public int getnumberoftimesteps () { return timediscretization. length -1; 120 public double gettime ( int timeindex ) { 124 return timediscretization [ timeindex ]; 126 6
7 @Override 128 public double gettimestep ( int timeindex ) { return timediscretization [ timeindex +1] - timediscretization [ timeindex ]; 130 public int gettimeindex (double time ) { 134 int index = java. util. Arrays. binarysearch ( timediscretization, roundtotimeticksize ( time )); return index ; 136 public int gettimeindexnearestlessorequal (double time ) { 140 int index = java. util. Arrays. binarysearch ( timediscretization, roundtotimeticksize ( time )); i f ( index < 0) index = - index -2; 142 return index ; 146 public int gettimeindexnearestgreaterorequal (double time ) { int index = java. util. Arrays. binarysearch ( timediscretization, time ); 148 i f ( index < 0) index = - index -1; return index ; 150 public double[] getasdoublearray () { 154 // Note: This is a deep copy return timediscretization. clone (); 156 public ArrayList < Double > getasarraylist () { 160 ArrayList < Double > times = new ArrayList < Double >( timediscretization. length ); for (double atimediscretization : timediscretization ) times. add ( atimediscretization ); 162 return times ; 166 public TimeDiscretizationInterface gettimeshiftedtimediscretization (double timeshift ) { double[] newtimediscretization = new double[ timediscretization. length ]; 168 for ( int timeindex =0; timeindex < timediscretization. length ; timeindex ++) newtimediscretization [ timeindex ] = roundtotimeticksize ( timediscretization [ timeindex ]+ timeshift ); 170 java. util. Arrays. sort ( this. timediscretization ); return new TimeDiscretization ( newtimediscretization ); 172 public Iterator < Double > iterator () { 176 return this. getasarraylist (). iterator (); 178 7
8 @Override 180 public String tostring () { return " TimeDiscretization [ timediscretization =" Arrays. tostring ( timediscretization ) + ", timeticksize =" + timeticksize + "]"; private double roundtotimeticksize (double time ) { return Math. rint ( time / timeticksize )* timeticksize ; 188 8
Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.
CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java
More informationObjects and Iterators
Objects and Iterators Can We Have Data Structures With Generic Types? What s in a Bag? All our implementations of collections so far allowed for one data type for the entire collection To accommodate a
More informationData abstractions: ADTs Invariants, Abstraction function. Lecture 4: OOP, autumn 2003
Data abstractions: ADTs Invariants, Abstraction function Lecture 4: OOP, autumn 2003 Limits of procedural abstractions Isolate implementation from specification Dependency on the types of parameters representation
More informationcoe318 Lab 2 ComplexNumber objects
Objectives Overview coe318 Lab 2 objects Implement a class. Learn how immutable objects work. Week of September 15, 2014 Create a project with more than one class. Duration: one week. In mathematics, complex
More informationThis exam is open book. Each question is worth 3 points.
This exam is open book. Each question is worth 3 points. Page 1 / 15 Page 2 / 15 Page 3 / 12 Page 4 / 18 Page 5 / 15 Page 6 / 9 Page 7 / 12 Page 8 / 6 Total / 100 (maximum is 102) 1. Are you in CS101 or
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 informationExercise Sheet 4 - Solutions
Exercise Sheet 4 - Solutions Alessandro Gnoatto May 1, 015 1 Exercise 1 A good explanation of how to implement the inverse normal c.d.f. by the rational approximation of Abramowitz and Stegun can be found
More informationQUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March
QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March 2006 11.05-12.35 Please fill in your Examination Number here: Student Number here: MODEL ANSWERS All
More informationDOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS
Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationCSE 143 Lecture 4. Implementing ArrayIntList; Binary Search. reading:
CSE 143 Lecture 4 Implementing ArrayIntList; Binary Search reading: 15.1-15.3 slides adapted from Marty Stepp and Hélène Martin http://www.cs.washington.edu/143/ Exercise Let's write a class that implements
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 informationLanguage Features. 1. The primitive types int, double, and boolean are part of the AP
Language Features 1. The primitive types int, double, and boolean are part of the AP short, long, byte, char, and float are not in the subset. In particular, students need not be aware that strings are
More informationIBS Software Services Technical Interview Questions. Q1. What is the difference between declaration and definition?
IBS Software Services Technical Interview Questions Q1. What is the difference between declaration and definition? The declaration tells the compiler that at some later point we plan to present the definition
More informationTeenCoder : Java Programming (ISBN )
TeenCoder : Java Programming (ISBN 978-0-9887070-2-3) and the AP * Computer Science A Exam Requirements (Alignment to Tennessee AP CS A course code 3635) Updated March, 2015 Contains the new 2014-2015+
More informationCIT 590 Homework 6 Fractions
CIT 590 Homework 6 Fractions Purposes of this assignment: Get you started in Java and Eclipse Get you comfortable using objects in Java Start looking at some common object uses in Java. General Idea of
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 informationתרגול 9 מחלקות ואובייקטים
תרגול 9 מחלקות ואובייקטים 1 1. Complex Numbers Design class Complex, representing an immutable complex number. Use this class to read two complex numbers from the user, print their sum and product, and
More informationCOMP-202 More Complex OOP
COMP-202 More Complex OOP Defining your own types: Remember that we can define our own types/classes. These classes are objects and have attributes and behaviors You create an object or an instance of
More informationCS 302: Introduction to Programming in Java. Lecture 15
CS 302: Introduction to Programming in Java Lecture 15 Class Instances of the class (objects) only valid at runtime Private Instance Methods Instance methods usually public why? If we have an internal
More informationAP 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 informationCOP 3337 Test 3. private int minimumposition(int from) { Part 1: Selection Sort
COP 3337 Test 3 NAME Part 1: Selection Sort The SelectionSorter class implements a selection sort on an array of strings. It is missing the minimumposition() method that returns the index position of the
More informationCSE 143 Lecture 2. reading:
CSE 143 Lecture 2 Implementing ArrayIntList reading: 15.1-15.3 slides adapted from Marty Stepp, Hélène Martin, Ethan Apter and Benson Limketkai http://www.cs.washington.edu/143/ Exercise Pretend for a
More informationCompuScholar, Inc. 9th - 12th grades
CompuScholar, Inc. Alignment to the College Board AP Computer Science A Standards 9th - 12th grades AP Course Details: Course Title: Grade Level: Standards Link: AP Computer Science A 9th - 12th grades
More informationAnswers to review questions from Chapter 2
Answers to review questions from Chapter 2 1. Explain in your own words the difference between a method and a program. A method computes a value or performs some operation on behalf of the code for a program.
More informationThis page intentionally left blank
This page intentionally left blank Absolute Java, Global Edition Table of Contents Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents Chapter 1 Getting Started 1.1 INTRODUCTION
More informationMore About Objects and Methods
More About Objects and Methods Chapter 6 Objectives Define and use constructors Write and use static variables and methods Use methods from class Math Use predefined wrapper classes Use stubs, drivers
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 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 informationSoftware Construction
Lecture 7: Type Hierarchy, Iteration Abstraction Software Construction in Java for HSE Moscow Tom Verhoeff Eindhoven University of Technology Department of Mathematics & Computer Science Software Engineering
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationEECS2030 Week 7 worksheet Tue Feb 28, 2017
1. Interfaces The Comparator interface provides a way to control how a sort method (such as Collections.sort) sorts elements of a collection. For example, the following main method sorts a list of strings
More informationCollections Algorithms
Collections Algorithms 1 / 11 The Collections Framework A collection is an object that represents a group of objects. The collections framework allows different kinds of collections to be dealt with in
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 informationAPCS Semester #1 Final Exam Practice Problems
Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester
More informationRyerson University Vers HAL6891A-09 School of Computer Science CPS109 Midterm Test Fall 09 page 1 of 7
CPS109 Midterm Test Fall 09 page 1 of 7 Last Name First Name Student Number Instructions: (a) There are 4 questions on this test. The test is worth 35% of your final mark. (b) There is a time limit of
More informationCIS133J. Working with Numbers in Java
CIS133J Working with Numbers in Java Contents: Using variables with integral numbers Using variables with floating point numbers How to declare integral variables How to declare floating point variables
More informationList ADT. Announcements. The List interface. Implementing the List ADT
Announcements Tutoring schedule revised Today s topic: ArrayList implementation Reading: Section 7.2 Break around 11:45am List ADT A list is defined as a finite ordered sequence of data items known as
More informationIMACS: AP Computer Science A
IMACS: AP Computer Science A OVERVIEW This course is a 34-week, 4 classroom hours per week course for students taking the College Board s Advanced Placement Computer Science A exam. It is an online course
More informationBuilding Java Programs Chapter 13
Building Java Programs Chapter 13 Searching and Sorting Copyright (c) Pearson 2013. All rights reserved. Sequential search sequential search: Locates a target value in an array/list by examining each element
More informationAbout Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals
More informationGraphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub
Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java
More informationCIT Special final examination
CIT 590-2016 Special final examination Name (please write your official name) PennID Number Note that your PennID number is the 8 digit bold number on your penn card. DO NOT START WRITING (aside from name
More informationCMSC 132, Object-Oriented Programming II Summer Lecture 5:
CMSC 132, Object-Oriented Programming II Summer 2018 Lecturer: Anwar Mamat Lecture 5: Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 5.1 Comparable
More informationCS 520 Theory and Practice of Software Engineering Fall 2018
Logistics CS 520 Theory and Practice of Software Engineering Fall 2018 Best and worst programming practices September 11, 2018 Reminder Recap: software architecture vs. design Class website: https://people.cs.umass.edu/~brun/class/2018fall/cs520/
More informationWritten Test 2. CSE Section M, Winter p. 1 of 8. Family Name: Given Name(s): Student Number:
Written Test 2 CSE 1020 3.0 Section M, Winter 2010 p. 1 of 8 Family Name: Given Name(s): Student Number: Guidelines and Instructions: 1. This is a 50-minute test. You can use the textbook, but no electronic
More informationCSC 1351 The Twelve Hour Exam From Hell
CSC 1351 The Twelve Hour Exam From Hell Name: 1 Arrays (Ch. 6) 1.1 public class L { int [] data ; void append ( int n) { int [] newdata = new int [ data. length +1]; for ( int i =0;i< data. length ;i ++)
More informationCourse materials Reges, Stuart, and Stepp, Martin. Building Java Programs: A Back to Basics Approach. 2d ed. (Boston: Addison-Wesley, 2011).
AP Computer Science A Advanced Placement Computer Science A is a fast-paced course equivalent to a college introductory programming class. Students will learn about the exciting kinds of problems tackled
More informationComparing Objects 3/14/16
Comparing Objects 3/14/16 Agenda HW Notes Practice Tests Returned Searching Data One of the most important and useful things that computers do is search through huge amounts of data. Search Engines Patterns
More informationCS 520 Theory and Practice of Software Engineering Fall 2017
Logistics CS 520 Theory and Practice of Software Engineering Fall 2017 Best and worst programming practices September 12, 2017 Recap: software architecture vs. design Recap: software architecture examples
More informationJava 1.8 Programming
One Introduction to Java 2 Usage of Java 3 Structure of Java 4 Flexibility of Java Programming 5 Two Running Java in Dos 6 Using the DOS Window 7 DOS Operating System Commands 8 Compiling and Executing
More informationCS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM
CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM Objectives Defining a wellformed method to check class invariants Using assert statements to check preconditions,
More informationJava Programming with Eclipse
One Introduction to Java 2 Usage of Java 3 Structure of Java 4 Flexibility of Java Programming 5 Using the Eclipse Software 6 Two Running Java in Eclipse 7 Introduction 8 Using Eclipse 9 Workspace Launcher
More informationCS 520 Theory and Practice of Software Engineering Fall 2017
CS 520 Theory and Practice of Software Engineering Fall 2017 Best and worst programming practices September 12, 2017 Logistics Recap: software architecture vs. design Specification Architecture Development
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationCloning Enums. Cloning and Enums BIU OOP
Table of contents 1 Cloning 2 Integer representation Object representation Java Enum Cloning Objective We have an object and we need to make a copy of it. We need to choose if we want a shallow copy or
More informationFundamental Java Methods
Object-oriented Programming Fundamental Java Methods Fundamental Java Methods These methods are frequently needed in Java classes. You can find a discussion of each one in Java textbooks, such as Big Java.
More informationInheritance (Part 2) Notes Chapter 6
Inheritance (Part 2) Notes Chapter 6 1 Object Dog extends Object Dog PureBreed extends Dog PureBreed Mix BloodHound Komondor... Komondor extends PureBreed 2 Implementing Inheritance suppose you want to
More informationInheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.
Inheritance Inheritance is the act of deriving a new class from an existing one. Inheritance allows us to extend the functionality of the object. The new class automatically contains some or all methods
More informationTopic 7: Algebraic Data Types
Topic 7: Algebraic Data Types 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 5.5, 5.7, 5.8, 5.10, 5.11, 5.12, 5.14 14.4, 14.5, 14.6 14.9, 14.11,
More information3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal
APCS A Midterm Review You will have a copy of the one page Java Quick Reference sheet. This is the same reference that will be available to you when you take the AP Computer Science exam. 1. n bits can
More informationPractice 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 informationThe Java Collections Framework and Lists in Java Parts 1 & 2
The Java Collections Framework and Lists in Java Parts 1 & 2 Chapter 9 Chapter 6 (6.1-6.2.2) CS 2334 University of Oklahoma Brian F. Veale Groups of Data Data are very important to Software Engineering
More informationInheritance (Extends) Overriding methods IS-A Vs. HAS-A Polymorphism. superclass. is-a. subclass
Inheritance and Polymorphism Inheritance (Extends) Overriding methods IS-A Vs. HAS-A Polymorphism Inheritance (semantics) We now have two classes that do essentially the same thing The fields are exactly
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationCollections, Maps and Generics
Collections API Collections, Maps and Generics You've already used ArrayList for exercises from the previous semester, but ArrayList is just one part of much larger Collections API that Java provides.
More informationClassCastException. ClassCastException
ClassCastException ClassCastException ArrayList ArrayList Object StringContainer String value String getvalue value setvalue String value value value StringContainer String value value value String
More informationSolving Equations with Inverse Operations
Solving Equations with Inverse Operations Math 97 Supplement LEARNING OBJECTIVES 1. Solve equations by using inverse operations, including squares, square roots, cubes, and cube roots. The Definition of
More informationContents Chapter 1 Introduction to Programming and the Java Language
Chapter 1 Introduction to Programming and the Java Language 1.1 Basic Computer Concepts 5 1.1.1 Hardware 5 1.1.2 Operating Systems 8 1.1.3 Application Software 9 1.1.4 Computer Networks and the Internet
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 informationpublic Candy() { ingredients = new ArrayList<String>(); ingredients.add("sugar");
Cloning Just like the name implies, cloning is making a copy of something. To be true to the nature of cloning, it should be an exact copy. While this can be very useful, it is not always necessary. For
More informationInterview Questions I received in 2017 and 2018
Interview Questions I received in 2017 and 2018 Table of Contents INTERVIEW QUESTIONS I RECEIVED IN 2017 AND 2018... 1 1 OOPS... 3 1. What is the difference between Abstract and Interface in Java8?...
More informationRecitation #2 Abstract Data Types, Collection Classes, and Linked List
Recitation #2 Abstract Data Types, Collection Classes, and Linked List (1) Create an ADT Fraction that describes properties of fractions. Include the constructor, setter, getter, and tostring() methods
More informationChapter 4 Defining Classes I
Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the
More informationCS1020 Data Structures and Algorithms I
Midterm AY2013/14 Semester 2 Data Structures and Algorithms I ANSWER SHEETS Answers included! INSTRUCTIONS TO CANDIDATES 1. This document consists of EIGHT (8) printed pages. 2. Fill in your Matriculation
More informationJava Classes. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar
Java Classes Introduction to the Java Programming Language Produced by Eamonn de Leastar edeleastar@wit.ie Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie
More informationMODULE 3q - An Extended Java Object
MODULE 3q - An Extended Java Object THE BOX PROGRAM RENAMED Copy the file Box.java to Block.java and then make all the amendments indicated by comments in the program below. The name of the public class
More informationJava Magistère BFA
Java 101 - Magistère BFA Lesson 3: Object Oriented Programming in Java Stéphane Airiau Université Paris-Dauphine Lesson 3: Object Oriented Programming in Java (Stéphane Airiau) Java 1 Goal : Thou Shalt
More informationCS/ENGRD 2110 FALL Lecture 5: Local vars; Inside-out rule; constructors
1 CS/ENGRD 2110 FALL 2018 Lecture 5: Local vars; Inside-out rule; constructors http://courses.cs.cornell.edu/cs2110 Announcements 2 A1 is due tomorrow If you are working with a partner: form a group on
More informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More informationExam Duration: 2hrs and 30min Software Design
Exam Duration: 2hrs and 30min. 433-254 Software Design Section A Multiple Choice (This sample paper has less questions than the exam paper The exam paper will have 25 Multiple Choice questions.) 1. Which
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 informationOutline. runtime of programs algorithm efficiency Big-O notation List interface Array lists
Outline runtime of programs algorithm efficiency Big-O notation List interface Array lists Runtime of Programs compare the following two program fragments: int result = 1; int result = 1; for (int i=2;
More informationMAT 3670: Lab 3 Bits, Data Types, and Operations
MAT 3670: Lab 3 Bits, Data Types, and Operations Background In previous labs, we have used Turing machines to manipulate bit strings. In this lab, we will continue to focus on bit strings, placing more
More informationECM1406. Answer Sheet Lists
ECM1406 Answer Sheet Lists These questions are based on those found in Chapters 3 and 4 of the core text Data Structures Using Java by Malik and Nair. The source code for the ArrayListClass, UnorderedArrayList,
More informationGeneric BST Interface
Generic BST Interface Here s a partial generic BST interface: public class BST
More informationInheritance. Transitivity
Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated
More informationCS/ENGRD 2110 FALL Lecture 5: Local vars; Inside-out rule; constructors
1 CS/ENGRD 2110 FALL 2016 Lecture 5: Local vars; Inside-out rule; constructors http://courses.cs.cornell.edu/cs2110 References to text and JavaSummary.pptx 2 Local variable: variable declared in a method
More informationProgramming Problems 22nd Annual Computer Science Programming Contest
Programming Problems 22nd Annual Computer Science Programming Contest Department of Mathematics and Computer Science Western Carolina University 5 April 2011 Problem One: Add Times Represent a time by
More informationTest 1: CPS 100. Owen Astrachan. October 1, 2004
Test 1: CPS 100 Owen Astrachan October 1, 2004 Name: Login: Honor code acknowledgment (signature) Problem 1 value 20 pts. grade Problem 2 30 pts. Problem 3 20 pts. Problem 4 20 pts. TOTAL: 90 pts. This
More informationSummary. Recursion. Overall Assignment Description. Part 1: Recursively Searching Files and Directories
Recursion Overall Assignment Description This assignment consists of two parts, both dealing with recursion. In the first, you will write a program that recursively searches a directory tree. In the second,
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 informationCsci 102: Sample Exam
Csci 102: Sample Exam Duration: 65 minutes Name: NetID: Student to your left: Student to your right: DO NOT OPEN THIS EXAM UNTIL INSTRUCTED Instructions: Write your full name and your NetID on the front
More informationJava Review: Objects
Outline Java review Abstract Data Types (ADTs) Interfaces Class Hierarchy, Abstract Classes, Inheritance Invariants Lists ArrayList LinkedList runtime analysis Iterators Java references 1 Exam Preparation
More information(Constructor) public A (int n){ for (int i = 0; i < n; i++) { new A(i); } System.out.println("*"); }
!!#!#"! (Constructor) A public A (int n){ for (int i = 0; i < n; i++) { new A(i); System.out.println("*"); % 1. new A(0); 2. new A(1); 3. new A(2); 4. new A(3); & ) n 5. A a = new A(n);! '#" +"()* " %floating
More informationReview. these are the instance variables. these are parameters to the methods
Review Design a class to simulate a bank account Implement the class Write a demo program that creates bank accounts Write junit tests for the bank account class Review What data items are associated with
More informationThe return Statement
The return Statement The return statement is the end point of the method. A callee is a method invoked by a caller. The callee returns to the caller if the callee completes all the statements (w/o a return
More informationLast class. -More on polymorphism -super -Introduction to interfaces
Last class -More on polymorphism -super -Introduction to interfaces Interfaces Sometimes in Java, we will have 2 classes that both share a similar structure, but neither of them is clearly the parent or
More informationCSCI 200 Lab 4 Evaluating infix arithmetic expressions
CSCI 200 Lab 4 Evaluating infix arithmetic expressions Please work with your current pair partner on this lab. There will be new pairs for the next lab. Preliminaries In this lab you will use stacks and
More informationInheritance. Inheritance
1 2 1 is a mechanism for enhancing existing classes. It allows to extend the description of an existing class by adding new attributes and new methods. For example: class ColoredRectangle extends Rectangle
More information