Course Information

Emacs Reference Card (PDF)

Help Schedule

Lab 1: Getting Started

Lab 2: Writing Classes

Lab 3: Putting Classes Together

Lab 4: Inheritance and Interfaces

Lab 5: ADTs and Exceptions

Lab 6: ADT: Linked Lists

Project 2: ADTs: Arrays, Linked Lists and Trees

Sample Input Data

Project 2 Sample Solution

Lab 7: Android SDK and Eclipse

Lab 7: Download Android SDK (Windows)

Lab 8: Android Programming Part 1

Lab 8: Android Programming Part 2

CS251: Intermediate Programming with Java

Course Information

Prof. Kelley's Course Website

Lab Instructor: Matthew Fricke

Email: mfricke@cs.unm.edu

Website: cs.unm.edu/~mfricke

Mailing List: Subscribe to cs251f12@cs.unm.edu

Office: Farris Engineering Center Room 126

Office Hours: Monday 1:00-2:00pm and Thursday 9:30-10:30am.

Grading: Your lab grade is based on quizzes and small programming assignments and is worth 15% of your final grade in CS251. Towards the end of the semester you will be working on projects assigned by Prof. Kelley during lab. Those projects are worth 45% of your final CS251 grade. So work you do in lab altogether makes up 60% of your grade for the course - DON'T SKIP LAB.

Lab section 2 is taught by Jan Monterrubio his website is here http://www.cs.unm.edu/~jmonter/CS251/F12/. Jan and I will be assigning the labs and grading together so feel free to go to either of our office hours.

Tips:

"Keep a safe place to stand" - write your programs incrementally, work on one small part at a time. Only move on to the next when you are sure the code you have written so far works exactly as you expect.

"Be lazy" - write each part of your program assuming the methods you use all work properly. Even though many of those methods will be written by you at a later time. This is just another way of saying abstract away the complexity by only thinking about the structure of one part of your program at a time. This is why programming languages have methods and classes.

"Practice makes perfect" - like every other task programming requires practice to get better.

"Use your brain to write code not the compiler" - it is tempting to write code, compile, look through the compiler errors and fix each line and then repeat. It is harder but much better to really think about your code before compiling so you don't end up with code that compiles but you don't really understand why.

"Don't steal" - using other people's code is essential for all programmers. In a university course where you are being evaluated for a grade it is very important that you do your own work, in industry stealing code will get your company sued. You can seek help from other students, books, and the internet but don't copy code without attribution. If your code looks like another student's we will likely believe you are both cheating even if they look the same because you got the code from the same internet site. There is nothing wrong with taking code from the internet just make sure you say so in a comment.

CS251 TA and CS Tutors Schedule Fall 2012

Monday
1:00 - 2:00 PM (M. Fricke)
2:00 - 3:50 PM (CS Tutor)

Tuesday
11:00 AM - Noon (CS Tutor)

Wednesday
Noon - 3:00 PM (CS Tutor)
3:00 - 5:00 PM (J. Monterrubio)
5:00 - 8:00 PM (CS Tutor)

Thursday
9:30 - 10:30 AM (M. Fricke)
2:00 - 5:00 PM (CS Tutor)

Friday
2:00 - 4:00 PM (J. Monterrubio)

Saturday
1:00 - 3:00 PM (CS Tutor)

If these hours don't work for you, you can send an email to either one of the CS251 Ta's or to the CS Tutor email (csundergradhelp@cs.unm.edu) and schedule some time to get the help that you need.

Lab 1: Getting Started

First do the following two things

Send me an email with Subject: CS251 [your lab section] [your name]

Sign up for the class mailing list above

The goal of this lab is to make sure you can write, compile, and run a java program in the lab environment. The java program you will write is called WordPlay.

Tools: Secure Telnet (ssh client), XMing (X11 Server), Ubuntu Precise Pangolin (linux), a linux text editor of your choice, javac (Java compiler), java, and JavaDocs (Java Reference).

Connecting to Linux

  1. Find XMing under the Start Menu and start it. Close any dialogs that ask you for firewall permissions.
  2. Find Secure Telnet under the Start Menu
  3. Run Secure Telnet and cancel the login dialog
  4. Choose Settings under the Edit menu
  5. Click on Tunneling and check the Tunnel X11 Connections checkbox
  6. Press OK
  7. Press Quick Connect. Answer yes to the error box.
  8. Enter moons.cs.unm.edu as the host and your CS Account username
  9. Enter your CS Account password and login
If that all worked you are now able to open a text editor such as Emacs.

WordPlay

Specification:

Wordplay takes text as an argument, performs three operations on that text, and prints the result of each operation. WordPlay prints an error message and exits if the input is not correct.

Input: a single word of text containing letters only

Output: prints the result of applying stringDouble, stringReverse, and stringInvertCase

Operations

stringDouble(): takes a string and returns a new string with each letter repeated once.

stringReverse(): takes a string and returns a new string with each letter in reverse order.

stringInvertCase(): takes a string and returns a new string with with each capital letter replaced with a lowercase letter and each lowercase letter replaced with a capital letter.

Example

java Wordplay ExampleText

EExxaammpplleeTTeexxtt

txeTelpmaxE

eXAMPLEtEXT

Program Skeleton

public class WordPlay{

    /**
     * Duplicates the characters within a particular string and returns a String with the duplicated characters of the original string.
     * @arg TODO What is being passed into the method?
     * @return the String containing duplicated characters from the original string
     */
    private static String stringDouble(String s){
	//TODO duplicate the characters here
	return s;
    }
    
  /**
     * Reverses the characters of a particular String and returns the reversed character String.
* @arg s the String of characters to be reversed * @return TODO What does it return? */ private static String stringReverse(String s){ //TODO reverse the characters here return s; } /** * Prints out a String with the upper and lower case characters reversed. * @arg s the String to reverseCamelCase */ private static void stringInvertCase(String s){ //TODO print the camelCase characters here } public static void main(String[] args){ //TODO check the length of args //TODO Access the String in the args array //TODO call the stringDouble method //TODO Call the stringReverse method //TODO Call the stringInvertCase method } }

Requirements

Send me an email with Subject: CS251

SIGN UP FOR THE CLASS mailing list

Submit "WordPlay.java" (see below for submission instructions)

You must have ONE method (or function) per operation.
Your main() method must show all three operations being used with the same input text
Have comments in your program

Use WordPlay to read a string from the command line. If No argument is passed to the command line or more than one argument is passed, your program must exit (ie System.exit(1) ) with a NON-ZERO value

Your program output must look something like this, input given ABCedFG
AABBCCeeddFFGG
GFdeCBA
abcEDfg

Grading

75% Meets Requirements
25% Code Style
10% Extra Credit: Only allow ALPHABETIC Chars (a-z and A-Z). And exits with a status wth NON-ZERO value if the String containts non alphabetic characters

Tips

READ THE WHOLE LAB BEFORE STARTING
Look at the Program Skeleton
For the ReverseCamelCase operation think of characters in their ASCII value
Try to use enhanced-for loops (a google search might enlighten you more)
If you're comfortable with reading the API and want to try something new, try using a StringBuilder
ASK QUESTIONS IF YOU NEED SOME HELP

Submissions

For this week's lab, you must do two things:
Send your file "WordPlay.java" to the email cs251f12@gmail.com . The Subject of your file must be Formated as such FIRSTNAME-LASTNAME-SECTION DateOfLab. IE, my submission would be "Matthew-Fricke-001 8/28".
Turn in a PRINTED version of your lab (you will receive comments about style). The printed version must be turned in AT THE START of your next lab

Lab 2: Writing Classes

September 4th, 2012

Background

Classification of birds was one of Charles Darwin's favorite hobbies. Tweeter, the newly founded social network has hired you to create a database of birds. Tweeter is interested in the sounds birds make, and whether or not they're correlated to the color of their feathers or whether the pitch is determined by the bird's ability to fly.

Requirements

  • You must have a file named Bird.java
  • Your Bird class definition MUST have the following fields
    • String for the name of the bird
    • boolean determining whether a bird can fly or not
    • int for the height of the bird in cm
    • double to represent the weight of the bird
    • String[] with all the colors of the Bird
  • Your bird class MUST have the following public methods
    • getName() returns a String which represents the name of the Bird
    • canFly() returns a boolean indicating whether the Bird can fly or not
    • getHeight() returns an int indicating the height of the Bird
    • getWeight() returns a double indicating the weight of the Bird
    • printColors() prints out all the colors this Bird can have, output MUST be of the form:
      Colors: 
      Blue
      Red
      
  • Your class MUST have the following STATIC method
    • getBirdCount() returns an int representing the number of Birds that have been created.
  • Your class MUST have the following CONSTRUCTORS
    • (String name, int height, double weight, boolean canFly, String[] colors) creates a Bird specifying the name, height, weight, if it can fly or not and an array of Strings which represents the colors of the bird.
    • (String name, int height, double weight, String[] colors) creates a Bird specifying the name, height, weight and an array of Strings which represents the colors of the bird. This constructor assumes that the bird can fly.

    You will also want to write a "driver" program. This program contains your main() function and you will use it to test your Bird class. When we grade your lab we will write our own driver, compile it with the Bird.java you submit and use it to perform some tests. We will not grade your driver program.

    Grading

  • 75% meets requirements
  • 25% code style. You will have to write PROPER javadoc comments for this weeks assignment
  • Tips

  • Read the whole lab before starting
  • Refer to chapter 2 in your book (The Java Programming Language, 4th Edition)
  • Ask questions if you need help
  • Submissions

  • Send your file "Bird.java" to the email cs251f12@gmail.com. The Subject of your file must be formated as such NAME-LASTNAME-SECTION DateOfLab. IE, my submission would be Matthew Fricke-002 9/4