Class Tasks
Class 1: Jan 5
Class 2: Jan 10
- What is the output of this program and why?
- Write a program that computes and displays (using os_log and print(..)) the Fibonacci Numbers between 0 and 10.
Fibonacci Numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21 .... where
Fibonacci(n) = 0 if n = 0
Fibonacci(n) = 1 if n = 1
Fibonacci(n) = Fibonacci(n - 1) + Fibonacci(n - 2) otherwise
Class 3: Jan 12
- Define a class called XYPoint that will hold a Cartesian coordinate (x,y) where x and y are Floats.
Define an initializer to individually set the x and y coordinates of a point. Have your class implement the CustomStringConvertible protocol.
Define an add method, e.g. func add(anotherPoint: XYPoint) -> XYPoint {...} that adds the corresponding x and y values and
returns a new XYPoint instance. Write a program to implement your new class and verify its correctness. Explain the results of running the following:
var aPoint = XYPoint(x: 100, y: 200)
var secondPoint = XYPoint(x: 200, y: 300)
var thirdPoint = secondPoint.add(aPoint)
print(aPoint)
print(secondPoint)
print(thirdPoint)
print(secondPoint.add)
print(XYPoint.add(aPoint))
- Define a class called Rectangle. Keep track of the rectangle's height and width as Ints. Write methods
to return the rectangle's area and perimeter. Have your class implement the CustomStringConvertible protocol. Test your new class and methods
Class 4: Jan 17
- Modify the methods add, subtract, multiply, and divide in the Calculator class
to return the value of the accumulator
- Add a memory instance variable to your Calculator and the following methods:
- func memoryClear() -> Float {..} clear memory
- func memoryStore() -> Float {..} set memory to the accumulator
- func memoryRecall() -> Float {..} set accumulator to the memory
- func memoryAdd(amount: Float) -> Float {..} add amount to memory
- func memorySubtract(amount: Float) -> Float {..} subtract amount from memory
- Add XCTests for testing all of your Calculator methods/behavior
Class 5: Jan 19
- A triangular number can be generated for any integer value of n by the formula:
triangularNumber = n(n+1)/2
Write a function that displays every fifth triangular number between 5 and 50, e.g. 5, 10 ..., 50
- Write a function that calculates the sum of digits of an integer. For example, the sum of digits of the number 123 is 1 + 2 + 3 = 6
- Write a program that asks the user to type in two integer values. Test the two numbers to determine if the first
is evenly divisible by the second and display an appropriate message. Use this helper class for keyboard input.
- Modify this function so that it returns the n’th prime number
- Test your functions for correctness
Class 6: Jan 26
- Using this keyboard class as a startring point create a KeyboardInput class that is implemented as a Singleton.
In your main.swift file run the following code to prove to yourself your code works:
import Foundation
var words: String = "Nothing entered yet"
var number: Int = 0
var keyboard: Keyboard = Keyboard.sharedInstance
print("Type something in: ")
words = keyboard.input()
print("Your entered: \(words)")
print("Type in an integer: ")
number = keyboard.inputInteger()
print("Your entered: \(number)")
- Create an Observer class. Have it observer your Keyboard class. Every time the Keyboard class has
its inputInteger() method invoked, the observer should be notified and display something in the console that
indicates this fact, as shown in the class demo
Class 7: Jan 31
- Add a new class called ClassC, which is a subclass of ClassB, using the implementation of of classes found in these classes. Break up the classes into individual Swift class files.
- Make a description and and initVariable method for ClassC, as in ClassA, that creates a String representing the instance
and sets the value of its instance variable x to 300
- Write tests that create instances of
ClassA, ClassB, and ClassC and invoke their corresponding initVariable methods. Print out the instances and
make sure the results are what you expect.
- Explain the results to your TA.
Class 8: Jan 31
- Complete the implementation of the two Person and Address classes.
This request implies you must complete the Equatable, Comparable, Hashable protocols as required. In addition, implement a copy function for both Person and Address
that creates a deep copy
- Provide XCTestCase tests for your new functions
Class 9: Feb 2
- Define three new classes, called Song, Playlist, and MusicLibrary. A Song
will contain information about a particular song, such as its title, artist, album,
and playing time. A Playlist will contain the name of the playlist and
a collection (Array) of songs. A MusicLibrary will contain a collection (Dictionary) of
playlists, including a special master playlist called library that contains every song
in the collection. Define these three classes and write methods to do the following:
- Create a Song class.
- Create a Playlist class that can add and remove songs from it, and return the number of songs it contains. A
new song should be added to the playlist if it’s not already there. Make
sure that if a song is removed from the playlist, it is removed from all
playlists in the music collection as well. Have these functions return true or false depending on if the operation was
succesful.
- Create a MusicLibrary class that can add and remove playlists to and from the collection. Don't forget to update the master list.
- Write a function in the MusicLibrary that searches the MusicLibrary for a song based on the song's title and returns it.
Class 7-8-9: Feb 7
- Work on Class Tasks 7, 8, and 9 in class and show TA
Class 10: Feb 9
- Create an Xcode single view app that has two buttons and two labels. For each button, everytime it is clicked, log that it has been clicked and display the number of times it has been clicked
in one of the corresponding labels.
Class 11: Feb 14
- Create an iOS app based on the Tab Bar Application Template. Add a Label and a PickerView to the first controller that has two columns of first and last names.
NSLog what has been selected in the PickerView and show in the Label.
Feb 16: Midterm Exam
Class 12: Feb 28
- Create an iOS app based on the Single View Template. Display the contents of a hardcoded array in the Table.
Display in the console and in a TextView in the app the contents of the row that was selected in the table.
Have each cell in the table end in a tick mark that is toggled to appear and disappear every time a cell is selected.
Class 14: Mar 2
- Install Android Studio
- Create and Run BlankActivity app
- Can you find where the Hello world! string is located?
- Modify the string to your name and run the app again.
Class 15: Mar 7
- Create a new Adroid project with one activity
- Make it run to look similar to the following picture (TextView, Button, CheckBox, CheckedTextView, Chronometer, TextClock, DatePicker)
- Add one new layout file called linear.xml. Populate the file with the linear layout found at http://developer.android.com/guide/topics/ui/declaring-layout.html
- Change your app so it runs using each of the two layouts (you have to change your activity Java source file to make this work too.
Class 16: Mar 9
- Write two JUnit Test Cases to test BankAccount.java: BankAccountMethodTestCase, and BankAccountConstructorTestCase
- Write a JUnit Test Suite to run both BankAccountMethodTestCase, and BankAccountConstructorTestCase
Class 17: Mar 14
- Create two activities (FirstActivity.java, SecondActivity.java) with layouts as follows:
- When the Switch button is clicked in the FirstActivity, bring up the SecondActivity
- When the back button on the Android Simulator is clicked while currenly running the SecondActivity, the FirstActivity should replace it.
- Log whenever one of your activities is destroyed.
- Have the "Switch" button change its text every time it is selected. E.g., toggle between "Switch" and "Switch Back"
Class 18: Mar 16
- Create three activities (MainActivity.java, Class18SecondActivity.java, and Class18ThirdActivity.java) with layouts as follows:
- Create an action bar menu that has two entires: File and Settings.
- Attach a different menu to the Class18Activity Text field's context menu that has entries Main, Second, and Third.
- Selecting Main, Second or Third should bring up the corresponding activity, e.g., Class18SecondActivity.java or Class18ThirdActivity.java
- Selecting File or Settings should log an invalid selection
Class18MainActivity.java Layout
Class18MainActivity Context Menu
Class18SecondActivity.java Layout
Class18ThirdActivity.java Layout
Class 19: Mar 28
- Create a new project with a layout containing an AutoCompleteTextView and two buttons as follows:
- The AutoCompleteTextView should autocomplete the strings final String[] SIZES = { "tall", "grande", "venti", };
- The Complex Toast Button should popup a toast in the middle of the screen with an Icon and text. Use a special layout to achieve this goal
- The Simple Toast Button should just popup some text
Class 19 Layout
Class 21: Mar 30
- Create a project with an Activity that has a single button that pops up an AlertDialog as shown in the following figure.
- Show a Toast of what the user selects in the Alert after it closes.
- The Alert should close when one of the two Alert button is selected.
Class 21 Alert Dialog
Class 22 ListViews: April 4:
- Create a project with an Activity that displays a simple list as found here
- Show a Toast when the user selects a row in the list indicating its position and value.
Class 22 ListView