COSC 122 Programming II


The purpose of this assignment is to acquaint you with the environment in which we will be developing Java programs.


  1. Preparing for the assignment

    If you are not using your own laptop, log into a lab workstation using your username and password. If you wish to use your own laptop computer to complete the assignments for this course, you should acquire and install the following free tools:

    1. Oracle's Java SE 7u4 (JDK 1.7.0_04). Install this software first. Because you will be developing Java programs, you need the JDK (Java Developer Kit), not just the JRE (Java Rutime Environment). You really need both, but the JDK installer will install the JRE at the same time.
    2. Eclipse for Java developers. Do not run Eclipse until you have installed Java, as Eclipse requires Java to run.

    If you are working on a lab machine, you should save your work on a USB drive.

  2. Teams

    You may work with a partner for this lab. Working with a teammate offers several advanages:

    • Two people do not think alike. By collaborating with another you can gain insights on programming concepts that might otherwise escape you.
    • You have a built in support system: You can have an immediate answer to a simple question that your teammate has, or vice-versa. Sometimes students are hesitant to ask a teacher questions they perceive to be "stupid questions," but teammates are less threatening.
    • Working with a classmate is more fun.

    You may elect to work alone, if you prefer.

    Regardless of whether you work alone or with a partner, on this and all furture labs you are responsible for understanding all aspects of the work required to complete the assignment.

  3. Using the Eclipse integrated development environment

    Create a new Java project as demonstrated in class:

    1. Create the new project: From Eclipse's main menu, FileNewJava Project.
    2. Create the new class: FileNewClass. You should check the option to create a main method in the class.
    3. In the main method automatically created by Eclipse, add a statement that prints your name.

    When you are finished with this part of the assignment, show your program to the teaching assistant and/or instructor.

    The purpose of this part of the assignment is to ensure that your developement environment is working properly.

  4. Getting and working with the code we develop in class

    To start this part of the lab you should not have Eclipse open.

    We will work on many programs in class, and all the code we develop in class is available online at the link provided below. It is very useful to get the code we do in class and play with it (modify it, break it, etc.) until you better understand how it works. If you do not bring a laptop to class, this beats copying it down on paper in class and then typing it into Eclipse later. Even if you do bring a laptop and type in the code as we go, the code repository can be useful to help you find typographical errors in your code.

    Direct your browser to http://computing.southern.edu/halterman/repository/ClassCode/cosc122/.

    Download a Java program that we developed in class and be sure you can place the code within a Java project, build, and execute it.

    Be sure you are able to build and run all the programs we have written in class.

    The code repository site is updated after each class.

    Sometimes it is handy to copy parts of programs we write in class and paste them into your own projects.

    When you are finished with this part of the assignment, show your program to the teaching assistant and/or instructor.

    The purpose of this part of the assignment is to ensure that you can retrieve and examine any code that we develop in class.

  5. Creating a simple Java program

    In Eclipse, create a new project, and write a Java program that allows the users to enter in any number of non-negative integers, whitespace delimited. The user terminates the list of numbers with a negative integer. The program then should print the average of non-negative numbers entered.

    Particulars:

    • Your program should print nothing if the user enters no non-negative numbers; that is, the user enters a negative number immediately.
    • For this assignment you need not worry about faulty user input. You may assume the user will enter only valid integer values separated by whitespace. This is not a reasonable assumption for general programming, and we will examine ways to deal with bad input in the future.
    • Zero is a non-negative number.
    • The terminating non-negative integer is not part of the average computation.

    When you are finished with this part of the assignment, show your program to the teaching assistant and/or instructor. You may be asked to modify part of this assignment to behave slightly differently to demonstrate your complete understanding of the code.

  6. Check out

    The instructor and/or teaching assistant will review your assignment with you before you leave. At that time you will know your score for the assignment. Assignments that meet all the requirements receive 10 points. Assignments that do not meet all the requirements or are late will receive fewer points.

  7. Finish up

    You always should close Eclipse when you are finished working with it. Select FileExit.

  8. Log out

    Don't forget to safely remove your USB drive (if necessary) and log out of your lab workstation (if necessary) before you leave.