CS 111 - Introduction to Computing, Fall 2014

Lab 1

For this assignment, we will write a simple Java program in the DrJava environment. You should look at the example program Lect0904a.java that was written in lecture on 9/4. This program shows the basics of output and calculations which you will need to do for this program.

The Dr Java Environment

The DrJava Development environment can be download from the main CS 111 Web Page using the zip file contained on that page. If you unzip this file to a flash drive, you can run the DrJava program on any machine that has the Java Development Kit installed on it.

Running DrJava on SOME machines in the ACCC Labs

DrJava can be found on SOME OF the machines in the ACCC Labs. Not all of the ACCC Labs have this software installed.
  1. clicking on the Start button (lower left corner of the display)
  2. clicking on the Programming folder
  3. clicking on the DrJava folder
  4. clicking on the DrJava RXXXX application (where XXXX is the release number of the software)
Otherwise download the zip file: bookClasses.zip to a flash drive. Unzip the the file. It contains the DrJava application and can be run on just about any machine that has the Java Development Kit installed on it.

Java Programming

When doing Java Programming, it is very important to follow a basic Java Template. Below is a file called Template.java

/**
 * Class for creating a template for a simple Java program
 *
 * @author Pat Troy: troy AT uic DOT edu */ 
 
// Note the name of the class in the following line MUST 
// match the name of the file. This is stored in a file 
// named: Template.java 
public class Template 
{
 public static void main (String[] args)
 { 
 System.out.println("Begin Java Exection"); 
 System.out.println(""); 
 
 // put your Java Program here 
 
 System.out.println(""); 
 System.out.println("End Java Exection"); 
 } 
} 
// end of Template class 

Output in Java

To output to the screen, we use the method System.out.println(). Between the parenthesis, we place the information that we wish to display. To display a string of values (i.e. words), we place the words in double quotes. Such as:
     System.out.println ("Hello.  Hope you have a good day."); 
To print out a number or the value of a variable, we place that information between the parenethesis. For example:
     System.out.println (57);
     System.out.println (number);  
We can print both some text and a value by placing both of these in between the parenthesis and separating them with a + sign, such as:
     System.out.println ("The result of the operation is " + number);  
Note, there also exists a method System.out.print(). This method will have the next printed item begin on the same line as this one ends. The System.out.println() always has the next printed item begin at the beginning of the next line.

Also note that to print a blank line in the output (i.e. to skip a line), use System.out.println() with nothing between the parathesis. In the program Template.java, this same thing was done by printing an empty string:

     System.out.println(""); 
Both produce the same result. You will notice that often the same result can be produced via different approaches.

Lab Assignment 1

Due: Wednesday 9/210/2014 by 11:59 pm (i.e. midnight)

Write a Java Program that will:

  1. Print out your name
  2. Print out your net-id
  3. Print out CS 111
  4. Print out your lab time
  5. Print out the additional information as described below:
As I Was Going to St. Ives

"As I was going to St Ives" is a traditional English language nursery rhyme which is generally thought to be a riddle.

The most common modern version is:

As I was going to St. Ives,
I met a man with seven wives,
Every wife had seven sacks,
Every sack had seven cats,
Every cat had seven kits,
Kits, cats, sacks, wives,
How many were going to St. Ives?

st_ives.jpg

The answer to the riddle is commonly thought to be 1, the narrator of the rhyme. The man, wives, cats and kits are thought to be going the other way (i.e. coming from St. Ives). You can check out the Wikipedia page on this for more information than you would ever need to know.

For the final output of the lab, print out the information about who the narrator "met" while going to St. Ives. That is, print out:

  • The number of wives
  • The number of sacks
  • The number of cats
  • The number of kits (note: "kits" is short for "kittens")
  • and, the total number of living things met
    i.e. totaling the man, the wives, the cats and the kits (note sacks are not living things)
You are required to use variables, multiplication and addition operations to calculate and determine the answers. For example:
//declaring variables  
int numMan;
int numWives;  
numMan = 1;             // determining the number of men 
numWives = numMan * 7;  // determining the number of wives 
Just storing the value of 7 into the variable numWives is not enough for full credit for the assignment.

You are also required display the values in the variables when showing the information about who the narrator met. When doing this you must also display some text describing any values prior to displaying the values. For example:

System.out.println ("The number of wives are: " + numWives); 

Submission of the Lab

The lab must be submitted electronically to the Assignment Link for Lab 1 inside of Blackboard. You will only need to submit the java source code file (just the ".java" file, not the ".java~" file or the ".class" file).

You are to name your program file (and the class) using both your NET-ID and the Lab Number. Thus for Lab 1, if you NET-ID was ptroy4, your program should be named: Ptroy4Lab1.java

-- Main.troy - 2014-09-05

Topic attachments
I Attachment Action Size Date Who Comment
JPEGjpg st_ives.jpg manage 32.8 K 2014-09-05 - 19:44 UnknownUser  
Topic revision: r1 - 2014-09-05 - 19:46:15 - Main.troy
 
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF