Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Similar documents
Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Tips from the experts: How to waste a lot of time on this assignment

Tips from the experts: How to waste a lot of time on this assignment

Tips from the experts: How to waste a lot of time on this assignment

Our second exam is Thursday, November 10. Note that it will not be possible to get all the homework submissions graded before the exam.

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm

Our second exam is Monday, April 3. Note that it will not be possible to get all the homework submissions graded before the exam.

Tips from the experts: How to waste a lot of time on this assignment

Com S 227 Spring 2018 Assignment points Due Date: Wednesday, March 28, 11:59 pm (midnight) "Late" deadline: Thursday, March 29, 11:59 pm

CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists

Com S 227 Assignment Submission HOWTO

Assignment Submission HOWTO

CMPSCI 187 / Spring 2015 Sorting Kata

CMPSCI 187 / Spring 2015 Hangman

CMPSCI 187 / Spring 2015 Hanoi

Announcements. 1. Forms to return today after class:

CSCI544, Fall 2016: Assignment 1

CS 2110 Fall Instructions. 1 Installing the code. Homework 4 Paint Program. 0.1 Grading, Partners, Academic Integrity, Help

Web API Lab. The next two deliverables you shall write yourself.

CIT 590 Homework 5 HTML Resumes

Programming assignment A

Initial Coding Guidelines

CSCI544, Fall 2016: Assignment 2

Due: Tuesday 29 November by 11:00pm Worth: 8%

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CS 116. Lab Assignment # 1 1

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018

6.170 Laboratory in Software Engineering Java Style Guide. Overview. Descriptive names. Consistent indentation and spacing. Page 1 of 5.

CS 463 Project 1 Imperative/OOP Fractals

CS161: Introduction to Computer Science Homework Assignment 10 Due: Monday 11/28 by 11:59pm

BCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER COURSE WEBSITE

You must pass the final exam to pass the course.

Computer Science 210: Data Structures

Debugging. CSE 2231 Supplement A Annatala Wolf

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator

EE 422C HW 6 Multithreaded Programming

CS 051 Homework Laboratory #2

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

Express Yourself. Writing Your Own Classes

Lab 1 Implementing a Simon Says Game

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts)

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab

Lab 1 Implementing a Simon Says Game

Lab Exercise 6: Abstract Classes and Interfaces CS 2334

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE

Xcode Tricks. ios App Development Fall 2010 Lecture 13

Be sure check the official clarification thread for corrections or updates to this document or to the distributed code.

Slide 1 CS 170 Java Programming 1

CS Fall Homework 5 p. 1. CS Homework 5

Lab 1: Setup 12:00 PM, Sep 10, 2017

Writeup for first project of CMSC 420: Data Structures Section 0102, Summer Theme: Threaded AVL Trees

Web API Lab folder 07_webApi : webapi.jsp your testapijs.html testapijq.html that works functionally the same as the page testapidomjs.

Problem 1: Building and testing your own linked indexed list

CSE : Python Programming

CS3114 (Fall 2013) PROGRAMMING ASSIGNMENT #2 Due Tuesday, October 11:00 PM for 100 points Due Monday, October 11:00 PM for 10 point bonus

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

15-110: Principles of Computing, Spring 2018

Summary. Recursion. Overall Assignment Description. Part 1: Recursively Searching Files and Directories

CS131 Compilers: Programming Assignment 2 Due Tuesday, April 4, 2017 at 11:59pm

Using System.out.println()

CS 170 Java Programming 1. Week 10: Loops and Arrays

CS446: Machine Learning Fall Problem Set 4. Handed Out: October 17, 2013 Due: October 31 th, w T x i w

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Assignment3 CS206 Intro to Data Structures Fall Part 1 (50 pts) due: October 13, :59pm Part 2 (150 pts) due: October 20, :59pm

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #29 Arrays in C

Due Friday, March 20 at 11:59 p.m. Write and submit one Java program, Sequence.java, as described on the next page.

Assignment 5: MyString COP3330 Fall 2017

CS Homework 11 p. 1. CS Homework 11

Homework 09. Collecting Beepers

CMSC 132: Object-Oriented Programming II. Administrivia

ECE 1778 Creative Applications for Mobile Devices January Programming Assignment P1, for Programmers

Programming Assignment III

CS 4349 Lecture August 21st, 2017

Lab 0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio

Lab 1: Space Invaders. The Introduction

Program 1: Generating Summation Puzzles

CSC D84 Assignment 2 Game Trees and Mini-Max

CISC 181 Lab 2 (100 pts) Due: March 4 at midnight (This is a two-week lab)

CSCI 1301: Introduction to Computing and Programming Spring 2019 Lab 10 Classes and Methods

CS 170 Java Programming 1. Week 12: Creating Your Own Types

CS103 Handout 50 Fall 2018 November 30, 2018 Problem Set 9

Assignment 3: Distance COP3330 Fall 2017

CS 170 Java Tools. Step 1: Got Java?

Stage 11 Array Practice With. Zip Code Encoding

COMPSCI 220 Programming Methodology Project Assignment 06: Expression Evaluator

Project #3. Computer Science 2334 Fall Create a Graphical User Interface and import/export software for a Hurricane Database.

15-110: Principles of Computing, Spring 2018

CS 3813/718 Fall Python Programming. Professor Liang Huang.

CIS 121 Data Structures and Algorithms with Java Spring 2018

[ 8 marks ] Demonstration of Programming Concepts

EEE-425 Programming Languages (2013) 1

COP4530 Data Structures, Algorithms and Generic Programming Recitation 3 Date: January 20 & 22, 2009

Chapter 1 Getting Started

CS 215 Software Design Homework 3 Due: February 28, 11:30 PM

Assignment #1: and Karel the Robot Karel problems due: 3:15pm on Friday, October 4th due: 11:59pm on Sunday, October 6th

Programming Project 1

CSE 5A Introduction to Programming I (C) Homework 4

Transcription:

Com S 227 Fall 2017 Miniassignment 1 50 points Due Date: Monday, October 16, 11:59 pm (midnight) Late deadline (25% penalty): Tuesday, October 17, 11:59 pm General information This assignment is to be done on your own. See the Academic Dishonesty policy in the syllabus, http://www.cs.iastate.edu/~cs227/syllabus.html#ad, for details. You will not be able to submit your work unless you have completed the Academic Dishonesty policy acknowledgement on the Homework page on Blackboard. Please do this right away. If you need help, see your instructor or one of the TAs. Lots of help is also available through the Piazza discussions. Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit. Overview The purpose of this miniassignment is to give you lots of practice writing loops and working with strings. For this miniassignment you will implement one class, called DNASequence, that is a simple model of a strand of DNA. For our purposes, a DNA sequence is essentially a sequence of characters A, G, C, or T. We say that character A is the complement of T and the character G is the complement of C. One character forms a bond (a "base pair") with another when it is aligned side-by-side with its complement.

Given two DNA sequences, they tend to align with each other so that the number of bonds is maximized. Here's an example. Suppose we start with the sequence represented by the string and we want to examine possible alignments with another DNA sequence, If we align them as then the number of bonds is two (T with A, and C with G): But if we shift the second sequence one space to the right, then the number of bonds is just one (T with A). If we shift two spaces to the right, then there are no bonds, and if we shift three to the right, there is one bond (T with A). We could also shift the second sequence to the left:

where there are no bonds. If we shift left by 2, there are three bonds. We could also try shifting left by 3, in which case there are no bonds, or by 4, with one bond; by 5, with one bond; or by 6, where there are no bonds. Thus the maximum possible number of bonds, for all possible alignments of the two sequences, is 3 (which occurs when the second sequence is shifted left by 2). It is also useful to identify the characters at which the bonds occur. One possible notation would be to represent the unmatched letters as dashes. For example, with the given string TCAT and the alignment we could represent the matches formed in TCAT using the string "TC-T".

Specification The specification for this asssignment includes this pdf, any "official" clarifications posted on Piazza, and the online javadoc: http://web.cs.iastate.edu/~cs227/homework/mini1/doc/mini1/dnasequence.html The skeleton code There is a complete skeleton for the DNASequence class linked on Piazza. It includes a declaration for one instance variable data of type String, which is initialized in the constructor and returned by the tostring method. You are not required to implement it this way, but this is the simplest approach. You really should not need any additional instance variables. To get started, create a new, empty project; within it create a package mini1, and within it create a class DNASequence. You can copy/paste the sample code into this class. It should compile without errors. If strings are immutable, how do I ever change the data? You can make a new string and assign it to the instance variable. String temp =... // do some work to make a new String data = temp; To modify or remove characters in a string, you can just iterate over it while making a new string that has the characters you want. For example, you can remove the vowels from a string like this: String s = "cauliflower"; String temp = ""; for (int i = 0; i < s.length(); i += 1) { char ch = s.charat(i); if ("AEIOUaeiou".indexOf(ch) < 0) // if ch is not a vowel { temp += ch; } } // now temp is "clflwr"

It's also possible to use the class java.util.stringbuilder, which is like a mutable form of String. String s = "cauliflower"; StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i += 1) { char ch = s.charat(i); if ("AEIOUaeiou".indexOf(ch) < 0) { sb.append(ch); } } String temp = sb.tostring(); // now temp is "clflwr" System.out.println(temp); (The code isn't any simpler, but most Java programmers would use the second version because it's slightly more efficient. In the first version, the Java compiler is actually creating a StringBuilder behind the scenes in each iteration.) You might be tempted to use the StringBuilder method deletecharat for the above problem of removing vowels. That is actually a bad idea - it's surprisingly tricky to delete elements from the sequence of things you're iterating over. Advice Start by doing simple, concrete examples with pencil and paper. Try to describe the steps of your solution in words, e.g. explain it to your little sister, explain it to your mom, explain it to your dog, until it makes sense to everyone. Then write it down in pseudocode. Be sure to give the dog a cookie. When a problem seems difficult, start with a simpler, related problem. For example, counting bonds might have some tricky cases, but you can start with simpler ones: Given a string, can you iterate over it and just print out the characters? Given two strings the same length, like "TCATT" and "AGCGA", can you iterate over them and count the bonds for corresponding characters? Given two strings of different lengths, like "TCATT" and "AGCGAGT", can you determine the number of overlapping positions? Iterate over just the overlapping part? Given a string s of length 5 and a string t of length 7, if t is shifted two characters to the right, how many positions overlap? What are the minimum and maximum indices in s? How about in t? What if s is the longer one? What if you are shifting t to the left instead?

Similarly, finding the maximum number of possible bonds may seem hard, but you can start with simpler problems: Given two strings s and t, what is the largest amount that t could be shifted to the right and still overlap with s? What's the largest amount that t could be shifted to the left? How would you keep track of the maximum of a sequence of numbers that are being given to you one at a time? Can you find the maximum possible bonds, looking only at shifting to the right? Can you find the maximum possible bonds, looking only at shifting to the left? The method issubsequence may seem tricky too. Again, start by doing concrete examples by hand. You can try some related but simpler problems: Given two strings s and t, does every character of t also occur somewhere in s? Given a string s and character c, can you find the first index at which c occurs in s? Given a string s, character c, and integer pos, can you determine whether c occurs in s after position pos? Can you find its index in s? Work incrementally and test as you go. Each simple example you do by hand can be turned into a test case. And if you get stuck on a small step, you'll have a simple, focused question to ask. Getting started 1. As in previous assignments, create a new, empty project and add a package called mini1. Create the class DNASequence and copy/paste the skeleton code. 2. Method willbond is pretty easy to start with, and will be useful in many of the other methods. You don't even need a loop. 3. You could try allvalid, which is kind of a warm-up problem, and is not a tricky loop to write. 4. The methods complement() and fix() are independent of everything else, and might be good as warm-up problems too. Be sure you have read the previous section "If strings are immutable...". Method issubsequence() is also independent of the other methods, but is a bit harder.

5. You'd probably want to work on countbondswithshift before the rest. Read the "Advice" section above. Work incrementally and test things as you go. For example, you could implement the method incrementally so that it works... when the two strings are the same length and shift = 0, then when the 'other' string is longer, but shift = 0, then when the 'other' string is shorter, but shift = 0. when the shift is positive ('other' string is shifted right), then when the shift is negative ('other' string is shifted left - this is likely to be a separate case). Note: When you think about "shifting", remember that this is an accessor method, and you are not going to physically move or modify the characters in either sequence. Just adjust the indices when you iterate so that you compare the right pairs of characters. For example, if the shift amount is +2, as in this picture from page 1, then index 2 of 'this' sequence is being compared with index 0 of 'other', and so on. 6. The method findbondswithshift is very similar to countbondswithshift. It just requires you to construct a string to return instead of counting. Be sure you have read the previous section "If strings are immutable..." so that you know how to create a string in a loop (or use StringBuilder). 7. The method findmaxpossiblebonds depends on having correctly implemented countbondswithshift. See the "Advice" section above. 8. The method issubsequence may be the trickiest, but nothing else depends on it. I keep getting StringIndexOutOfBoundsException Hmm. Could it be that you have a string index that is out of bounds? Remember, you are in complete control over what your code does. If something hurts, stop doing it! Your first clue is in the exception message that appears in the console, which shows you exactly which line of code is causing the exception. Start reading at the top. When you see a reference to your own code, click on the link and it will take you to the line in your code where the exception occurred. That may be enough for you to spot the error.

If you don't immediately spot the error, take a simple test case and work through it by hand, to be sure you know what you want the code to do. Keep careful track of all the indices. Then trace by hand what your code is really doing. You can also use the debugger to step through the execution. There are some exercises in this week's lab, including a demo of a nice feature of the Eclipse debugger called "exception breakpoints" with which you can have the code stop execution just before an exception occurs, so you can examine the state of all the variables before the program crashes. For details, see this page of Lab 6: http://web.cs.iastate.edu/~cs227/labs/lab6/page08.html The SpecChecker Import and run the SpecChecker just as you practiced in Labs 1 and 2. It will run a number of functional tests and then bring up a dialog offering to create a zip file to submit. Remember that error messages will appear in the console output. There are many test cases so there may be an overwhelming number of error messages. Always start reading the errors at the top and make incremental corrections in the code to fix them. When you are happy with your results, click "Yes" at the dialog to create the zip file. See the document SpecChecker HOWTO, which can be found in the Piazza pinned messages under Syllabus, office hours, useful links if you are not sure what to do. Documentation and style Since this is a miniassignment, the grading is automated and in most cases we will not be reading your code. Therefore, there are no specific documentation and style requirements. If you have questions For questions, please see the Piazza Q & A pages and click on the folder miniassignment1. If you don t find your question answered, then create a new post with your question. Try to state the question or topic clearly in the title of your post, and attach the tag miniassignment1. But remember, do not post any source code for the classes that are to be turned in. It is fine to post source code for general Java examples that are not being turned in. (In the Piazza editor, use the button labeled pre to have Java code formatted the way you typed it.)

If you have a question that absolutely cannot be asked without showing part of your source code, make the post private so that only the instructors and TAs can see it. Be sure you have stated a specific question; vague requests of the form read all my code and tell me what s wrong with it will generally be ignored. Of course, the instructors and TAs are always available to help you. See the Office Hours section of the syllabus to find a time that is convenient for you. We do our best to answer every question carefully, short of actually writing your code for you, but it would be unfair for the staff to fully review your assignment in detail before it is turned in. Any posts from the instructors on Piazza that are labeled Official Clarification are considered to be part of the spec, and you may lose points if you ignore them. Such posts will always be placed in the Announcements section of the course page in addition to the Q&A page. (We promise that no official clarifications will be posted within 24 hours of the due date.) What to turn in Note: You will need to complete the "Academic Dishonesty policy questionnaire," found on the Homework page on Blackboard, before the submission link will be visible to you. Please submit, on Blackboard, the zip file that is created by the SpecChecker. The file will be named SUBMIT_THIS_mini1.zip. and it will be located in the directory you selected when you ran the SpecChecker. It should contain one directory, mini1, which in turn contains one file, DNASequence.java. Submit the zip file to Blackboard using the Miniassignment 1 submission link and verify that your submission was successful by checking your submission history page. If you are not sure how to do this, see the document "Assignment Submission HOWTO" which can be found in the Piazza pinned messages under Syllabus, office hours, useful links. We strongly recommend that you just submit the zip file created by the specchecker. If you mess something up and we have to run your code manually, you will receive at most half the points. We strongly recommend that you submit the zip file as created by the specchecker. If necessary for some reason, you can create a zip file yourself. The zip file must contain the directory mini1, which in turn should contain the file DNASequence.java. You can accomplish this by zipping up the src directory of your project. The file must be a zip file, so be sure you are using the Windows or Mac zip utility, and not a third-party installation of WinRAR, 7-zip, or Winzip.