CS1011
Homework
There are four sources for the homework problems: * [CodingBat](http://codingbat.com) assignment (with link to assignment provided). * Exercise: 3.4 means exercise number 4 at the end of chapter 3. * Instructor written assignment. ## Week 1 (doable by Tuesday of week 2) * Write a paragraph or code snipet that demonstrates attainment of each Week 1 [outcome](Outcomes) * Exercise 3.4 ## Week 2 (doable by end of week 2) Note: You'll need to [create an account on the CodingBat](http://www.codingbat.com/pref?docreate=1) site (make sure you enter your name in the Name field (even though it says it is optional). You will also need to put your instructor's email address in the "Share To" field (see [preferences](http://www.codingbat.com/pref)). ([5 minute tutorial video](../cs1011f10/1011-hw.html)) * Rewatch the [explanation of lab 1 program](lectures/1011-lab1.mp4) starting 12 minutes in and see if it makes more sense now * Write a paragraph or code snipet that demonstrates attainment of each Week 2 [outcome](Outcomes) * [CodingBat: sum](http://www.codingbat.com/prob/p214024) * [CodingBat: helloName](http://www.codingbat.com/prob/p171896) * [CodingBat: makeAbba](http://www.codingbat.com/prob/p161056) * Exercise: 2.5 (long form only) * Download [this file](https://raw.githubusercontent.com/bcdennis/se1011/be5786d5d1eae27bf6dc25836a7827c8729ada8b/src/Strings.java). For each part, first predict what you think will be displayed, then run the code (commenting/uncommenting as needed) and verify your prediction. * Download [this file](https://raw.githubusercontent.com/bcdennis/se1011/cb2a5f113bf7a530dc1276f20c0f77b0f31b29d6/src/Arithmetic.java). For each part, first predict what you think will be displayed, then run the code (commenting/uncommenting as needed) and verify your prediction. * Write a program that will initialize a variable named `myHelloWorld` with the string literal `"My Hello World"` and print to the console the index of the letter <kbd>H</kbd>. * Write a program that will initialize a variable named `firstName` with your first name. Without using loops, print to the console each letter in your name on a separate line by using the `charAt()` method. * Using the [String class documentation](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html), explain what the `replace()` method does and write a program to demonstrate its usefulness. * Using the [String class documentation](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html), explain what the `trim()` method does and write a program to demonstrate its usefulness. ## Week 3 (doable by end of week 3) * Write a paragraph or code snipet that demonstrates attainment of each Week 3 [outcome](Outcomes) * [CodingBat: comboString](http://www.codingbat.com/prob/p168564) * [CodingBat: sortaSum](http://www.codingbat.com/prob/p183071) * [CodingBat: alarmClock](http://www.codingbat.com/prob/p160543) * [CodingBat: twoAsOne](http://www.codingbat.com/prob/p113261) * [CodingBat: inOrder](http://www.codingbat.com/prob/p154188) * [CodingBat: bobThere](http://www.codingbat.com/prob/p175762) * [CodingBat: starOut](http://www.codingbat.com/prob/p139564) ## Week 4 (doable by Tuesday of week 4) * [CodingBat: closeFar](http://www.codingbat.com/prob/p138990) * [CodingBat: makeChocolate](http://www.codingbat.com/prob/p191363) ([video solution](lectures/1011-4-hw.mp4)) * [CodingBat: sumDigits](http://www.codingbat.com/prob/p197890) * [CodingBat: middleThree](http://www.codingbat.com/prob/p115863) * Exercise: 4.9, 5.5 ### if Write a program that asks the user to enter a three letter word. The program should indicate whether the letters in the word are in alphabetical order, reverse alphabetical order, or neither. Sample interaction should look like this: <pre> Enter three letters: aim The three letters entered are in alphabetical order. Enter three letters: toe The three letters entered are in reverse alphabetical order. Enter three letters: bye The three letters entered are not in order. </pre> ### switch Suppose you are making a game that needs to control a character on the screen. The following key mappings should be used: <key>h</key> - left, <key>j</key> - down, <key>k</key> - up, <key>l</key> - right. Write a program that accepts a character and prints the appropriate direction. Sample interaction should look like this: <pre> j down k up h left </pre> ### Rewrite for loop as while loop Rewrite the following `for` loop as a `while` loop: ``` for(int i=1; i<10; i=i+1) { System.out.println(i + "^2 = " + i*i); } ``` ### Loops [video solution](../se1011f16/lectures/1011-3-3-4.mp4) Write a program that asks the user to enter a word. The program should indicate whether the letters in the word are in alphabetical order, reverse alphabetical order, or neither. Sample interaction should look like this: <pre> Enter a word: abhors The letters entered are in alphabetical order. Enter a word: soon The letters entered are in reverse alphabetical order. Enter a word: typical The letters entered are not in order. </pre> ### do while loop Write a program that asks the user to enter something. If the user just hits enter without entering any characters first, the program should ask the user again (repeatedly, until the user enters something). The program should then end. Hint: use `nextLine()`. ### Loops Ask the user to enter two integer values: height and width. Your program should then generate a box of <key>*</key>s that is height tall and width wide. Sample interaction may look like this: <pre> Please enter the height: 3 Please enter the width: 5 ***** ***** ***** </pre> ### Loops Ask the user to enter a name and print all of the letters in the name, one per line. Include line numbers for the lines. Sample interaction may look like this: <pre> Enter a name: Chris Letters: 1. C 2. h 3. r 4. i 5. s </pre> ### Loops [video solution](../se1011f16/lectures/1011-3-3-8.mp4) Ask the user to enter as many positive integers as the user wants followed by a non-positive integer. The program should then display the sum of all positive values that are divisible by 3. Sample interaction may look like this: <pre> Enter a bunch of positive integers followed by a non-positive integer: 1 2 3 4 5 6 7 8 9 10 11 18 0 Answer: 36 </pre> ### Loops Suppose you are making a game that needs to control a character on the screen. The following key mappings should be used: <key>h</key> - left, <key>j</key> - down, <key>k</key> - up, <key>l</key> - right. Write a program that accepts a string of characters and generates a sequence of moves. Characters other than the directional characters specified earlier should be ignored. Sample interaction should look like this: <pre> jjlllk down down right right right up </pre> ### Loops Rewrite the program in the previous exercise so that the output matches the sample below. <pre> jjlllk 2 down 3 right 1 up </pre> ## Week 5 (doable by Friday of week 5) * Write a paragraph or code snipet that demonstrates attainment of each Week 4 [outcome](Outcomes) * Write a paragraph or code snipet that demonstrates attainment of each Week 5 [outcome](Outcomes) * Exercise: 5.3, 5.7, 5.8 ## Week 6 (doable by Friday of week 6) * Write a paragraph or code snipet that demonstrates attainment of each Week 6 [outcome](Outcomes) * Exercise: 6.6, 6.10, 6.11, 6.13, 7.2 * In the `Student` class developed in lecture, add an instance variable with [`LocalDate date`](http://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html). Hint: `java.time.temporal.ChronoUnit.YEARS.between(a, b);` returns the number of years between two `LocalDate`s. * Study [this Taylorial page](https://taylorial.com/cs1011/Classes.htm) and prepare at least one question to ask your instructor. (Be prepared to ask Monday of week 7) ## Week 7 (doable by Thursday of week 7) * Write a paragraph or code snipet that demonstrates attainment of each Week 7 [outcome](Outcomes) * Implement a class that represents a dog. The class should keep track of the dogs color, weight, and age. * Write an instance method for the `Dog` class, `swap(Dog that)`, that swaps the contents of the current dog with the dog passed to the method. * Exercise: 7.2, 7.7 ## Week 8 (doable by on Tuesday of week 8) * Write a paragraph or code snipet that demonstrates attainment of each Week 8 [outcome](Outcomes) * Exercise: 9.9 * Implement `calculateTermQuizScore()` that accepts an array of `int`s as an argument and returns a `double` representing the quiz grade for the quarter. ## Week 9 (doable by Friday of week 9) * Exercise: 10.7, 10.9, 10.10 * [CodingBat: lucky13](http://www.codingbat.com/prob/p194525) * [CodingBat: sum28](http://www.codingbat.com/prob/p199612) * [CodingBat: centeredAverage](http://www.codingbat.com/prob/p136585) * The above centeredAverage problem with an ArrayList instead. (`public int centeredAverage(ArrayList<Integer> nums)`) * [CodingBat: linearIn](http://www.codingbat.com/prob/p134022) * Exercise: 10.10 * Write a paragraph or code snipet that demonstrates attainment of each Week 9 [outcome](Outcomes) * [CodingBat: shiftLeft](http://www.codingbat.com/prob/p105031) * [CodingBat: tripleUp](http://www.codingbat.com/prob/p137874) * [CodingBat: seriesUp](http://www.codingbat.com/prob/p104090) * [CodingBat: copyEvens](http://www.codingbat.com/prob/p134174) * [CodingBat: fix34](http://www.codingbat.com/prob/p159339) ## Week 10 (doable by Friday of week 10) * Write a paragraph or code snipet that demonstrates attainment of each Week 10 [outcome](Outcomes) * Redo the week 9 homework using ArrayLists instead of arrays

Wednesday, 06-Nov-2019 04:01:33 EST