CSci 2101 Takehome exam 1.

Due Tuesday, February 21st, at 11:59pm. No late submissions accepted.

You may not spend more than 8 hours on this test.

The time does not have to be all in one stretch. However, it must include, in addition to all your programming time, the time for all reading that you did after you have first seen the problems and all of your non-programming time spent on the test (drawing pictures, writing sketches of code, etc).

38 points

You may use the textbook, your lecture notes, in-class examples, and other materials for this class. Other Java textbooks and online Java resources may be used with preapproval only (send me an e-mail if you plan to use any). You may not google for any problem-specific keywords.

The work is strictly individual. You may ask me questions in person or by e-mail, you may not ask anyone else any questions about any material on the test.

You may submit a file per problem, or combine files, within reason. Please include your name in comments in each file and comment the program appropriately.

Please state your assumptions about the data (the program is allowed to break if the assumptions do not hold). Your assumptions must be reasonable.

Submit all your test data and conclusions (it may be in comments or in a separate file). The conclusions may be as simple as "in all of these cases the program ran as expected". If your tests are not passing, include them in your program (you may comments them out) and indicate why you think they may not be passing.

If any of the required functionality is missing, please include that in comments. Adding notes on how you would proceed if you had more time may gain you partial credit.

Problem 1 (6 points): pick characters

Write and test a method pick that takes a string and an array of integers and returns a string that contains characters of the original string at the positions specified in the array. The elements of the array are assumed to be in increasing order, all different, and correspond to valid indices in the string. The array may be empty, in which case an empty string is returned.
For instance,

Problem 2 (10 points): remove elements

Write and test a void method removeElements that takes an array list of strings and an array of integers and removes from the given array list all strings that are at the indices given in the array.
For instance,

Once again, the indices are given in increasing order, and you may assume that all indices are valid for the given array list.

Problem 3 (10 points): reverse a stack

Write a method copyInReverse that takes a stack of integers and returns a new stack of integers that has all of the same elements, but in reverse order. The given stack is unchanged after the method call.
The given stack may be empty, in which case an empty stack is returned.
You may use any data structure as intermediate storage. You may only use pop, push, peek, and empty as stack methods.

Problem 4 (12 points): relatively prime elements

Write a method relativelyPrime that takes an array of non-zero integers and returns true> if all of the elements are relatively prime to each other, and false otherwise.
Two integers are relatively prime if their greatest common divisor is 1. There is a recursive algorithm for finding the greatest common divisor, known as Euclidean algorithm. Feel free to use it (and you can google for it if you would like to), although there are other approaches to this problem.
Examples of the method results:

Grading criteria

Your solution will be graded on:

How to submit

Please submit it by e-mail to me with the subject 2101 Midterm 1.


CSci 2101 course web site.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.