Homework 4 (130 points available)
41. Write test code that instantiates some student and course objects and prints them out. Each
student has a name and
The Math class contains many useful functions, some
shown below. Note that it does NOT have to be imported
in order to be used; it's automatically included (like the
System class and String class).
"First, solve the problem. Then, write the code." John
Algorithms should be:
All, At Least One, How Many, Which
Decompose Programs into Functions
Declaring & Initializing Arrays
Accessing Array Elements
Index starts at 0
Cannot be changed
Arrays of Objects are better than "Parallel Arrays"
Iterating Through Arrays for-each loop
Always use a for-e
Selection Sort and Insertion Sort
Sorting Bounded Numbers is easy
Pigeonhole Sort Look at each element once; O(n)
Find smallest, second-smallest, etc.
Sort first 2 elements, first 3 elements, etc.
Collection of Pairs of Elements
Indexed by Keys
Each Key Maps to a Value
Keys are Unique
Using Maps in Java
A map is a data structure that holds key to value
Keys are used for indexing into the map
Accessing or mo
Objects store Memory References
Assignment between objects creates Aliases
Two variables that refer to the same object
Changing the instance variables of one changes the other!
Copying Classes need a method to create an object
Arrays as Objects
Arrays as Objects
Testing arrays for equality
Copying Parts of Arrays
Inserting and Deleting Elements
Variable Number of Arguments
Using Arrays to Replace M
Static Variables and Methods
final cannot be changed
Instance variables and local variables can be final
Methods and classes can be final (see "Inheritance"
Variable shared by all objects of the class.
CAN be mo
Merge Sort and Quick Sort
Repeatedly split collection of items into 2 halves until the sub-lists
become small, then repeatedly merge them into sorted lists.
Repeatedly split collection of items into those less than
Sorting in Java
Class must implement Comparable
contains a compareTo method
returns an integer indicating which item is "bigger"
The sort functions are written so that they can
operate on ite
An interface contains abstract methods (method headers).
A class implements an interface.
Provides actual code for the method headers in the interface.
An interface variable can reference any object that is instantiated
Time taken increases in proportion to the number
Time taken increases in proportion to the LOG of
the number of elements.
Much faster than Linear Search, but can only
be used if data i
Two-Dimensional (2-D) Arrays
Array of arrays
An array whose elements are arrays.
Each element corresponds to a row of the 2-D array.
Print using deepToString or a nested for-each loop.
Testing for Equality
Suppose the Book class has instance variables for the author,
title, and date of the book.
Book x = new Book("Joe Soap", "My Life", 1970);
Book y = new Book("Joe Soap", "My Life", 1970);
x = y will return false
This is because x and
Static & Dynamic Typing
A language is statically typed if type-checking is done at
compile-time. This requires the programmer to declare types.
Types are associated with variables.
int x makes x an int.
x is ALWAYS an int.
A language is dy
extends(keyword used to denote inheritance of class or interface)
super (refers to object in subclass as if it were in parent class)
Overriding (method in subclass is called instead of method in parent
Object class (a
Samantha and Esteban
Homework 10 (130 points available)
Modify the Student class (and Course class, if necessary) so that each
Homework 12 (120 points available)
I have always wished for my computer to be as easy to use as my
telephone; my wish has come true, because I can no longer figure
out how to use my telephone. - Bjarne Stroustrup,
Homework 13 (125 points available)
131. Implement the remove method for the OurLinkedList class. You may use your own
code or the code on Scholar.
The method should remove an element at a specified position, as fo
Homework 14 (110 points available)
141. Use Radix Sort to sort the following strings alphabetically. SHOW ALL STEPS! (15 points)
computer science comb compare scene compli
Homework 1 (150 points available)
Read the syllabus and let me know if you have any questions. Done
Visit my office (Carver 201) during an office hour (or any time when I'm there).
Samantha Schwarz And Scott Henry
Homework 6 (125 points available)
We want to modify the Student class to enable a student to add and drop courses.
Make the following changes. You dont need to provide answers for
Homework 7 (120 points available)
If debugging is the process of removing bugs, then programming
must be the process of putting them in. - Edsger Dijkstra
71. Consider the function mystery below.
public static int
Homework 5 (130 points available)
Write and test a method that has as parameters an array of integers and two floating point
numbers and returns true if ALL the integers in the array are strictly between the two n
Linked Lists in Java
Linked List Class
Methods (add, remove, get, etc)
Looping use for-each loop
Integer for int, Double for double, etc.
Implemented by both ArrayList and LinkedLis
Functions that call themselves
Direct vs Indirect Recursion
Base case and recursive case
How Recursion Works
Each call has its own copies of parameters & local
A class defined in terms of itse