CS 307Assignment 1, Introduction to Software Tools, Creating and Implementing Algorithms, Java Expressions and Syntax, and Simple Java Programs
| Programming Assignment 1 | Individual Assignment. You must complete this assignment on
your own. You may not discuss their work with anyone except the instructor
and other members of the instructional staff (TA, section leader, or lab
proctor). You may not acquire from any source (e.g., another student or an
internet site) a partial or complete solution to a problem or project that
has been assigned. You may not show another student your
solution to an assignment. You may not have another person
(current student, former student, tutor, friend, anyone) “walk you through”
how to solve an assignment. Review the
class policy on collaboration
from the syllabus. Placed online: Friday, August 22 |
||||||
| Description | The purposes of this assignment are:
Assignment design in CS307: If you took CS305J one thing that will be different this term is you will not always be writing entire programs from scratch. You will often, but not always, be given a partial program and have to complete it. You will also be doing a lot of "coding to spec" or specification. The program will have already been designed and you must implement it given the design. Many of the methods you write won't ask the user for input or do any output. The "input" to the methods will be via parameters and the "output " will be the return value. Of course you can add user input and output in a method that calls the specified method to provide a way of interactively testing the methods you write, but this is not required. Download A1.java and complete method
Very important: The only methods from the Java library you may use
in completing method Also, very important. The method does not do any input or output on its own. You don't "ask the program user" for the input string or print out the result. The input comes as a parameter to the method and the output is the return value from the method. This method finds all complete matches of a target String in a source String. String matching is used in many different applications. Every time you use the find command or replace command in a word processing document or on a web page you are making use of string matching. String matching is also used in areas such as computer virus detection and mapping of DNA. Link to the Wikipedia article on string matching. You may implement a naive, brute force string matching algorithm as described below and you will not lose points for efficiency. Example of naive string matching algorithm. Assume target string is "aaa" and source string is "aaaabaaaa". The answer for this example is [0, 1, 5, 6]. Here is a detailed explanation of how to arrive at the answer for this example. The numbers indicate the position of each character in the source and target strings. Initial lineup per naive algorithm.
012345678 The above line up results in a match starting at index 0 in source. Next slide the target
down 1 spot. The above lineup results in a match starting at index 1 in source. Slide the target down another spot. 012345678 The above lineup is not a match. Slide the target down another spot. 012345678 The above lineup is not a match. Slide the target down another spot. 012345678 The above lineup is not a match. Slide the target down another spot. 012345678 The above lineup results in a match starting at index 5 in source. Slide the target down another spot. 012345678 The above lineup results in a match starting at index 6 on source. Tip: The real complexity in this problem is that you have to keep track of two different indices. The index in the target string and the index in the source string. These two values are not equal to each other, except for the first line up. In method matches you will be returning an ArrayList<Integer> result = new
ArrayList<Integer>(); The fastest known string matching algorithm is the Boyer-Moore String algorithm. If interested read sections 1- 4 from the original paper. You are NOT expected to implement the Boyer-Moore algorithm. Complete method findPrimes in A1.java. You may add helper methods if you wish. Very important. You may not use the Prime Numbers entry from Wikipedia Another explanation of prime numbers. Why are primes important? The Applications section of the Wikipedia article on prime numbers mentions some of their uses. Here is another set of answers. The file A1.java contains a main method with some tests for methods matches and findPrimes. Some of these tests may be incorrect. You are required to find and fix any incorrect tests. Use the class listserv to share information about other students about which tests are in error and how to correct them. Add more tests of your own to the main method. A simple way
to test these methods is to create
Fill in the header for A1.java. Replace <NAME> with your name. Note, you are stating, on your honor, that you did the assignment on your own, as required. If you copy yoru code from another source (internet, another student in the course, another student who previously took the course) you will be guilty of academic dishonesty and will receive am F in the course. When finished turn in your A1.java program using the turnin program. Turn in your file to your cs307 folder! Realize that your turnin account will have multiple folders (or directories) if you are registered for more than one computer science class. (For example CS313k). Ensure you turn your assignment in to your CS307 folder. We don't have access to your other folders so it will cost you 2 slip days if we have to take the time to straighten out the mistake. |
||||||
| Files |
|
||||||
| Checklist | Did you remember to:
|
||||||
| Tips |
|