Program Comments
Programming exercises are key component of learning any programming language. For this course, there are seven programming assignments that are arranged from the simplest case to more complex tasks as you progress through the course.
The textbook comes with a CD-ROM that includes Java. Students may install and use this version of Java for all course assignments. The CD-ROM also may include an integrated development environment (IDE). You do not need to use the IDE to complete these assignments, however, you are welcome to learn and use the IDE if you wish.
Downloading the latest version of Java from the Sun web site is a excellent idea, provided you have a fast Internet connection. Sun also provides a downloadable IDE called NetBeans. This IDE has a level of support from Sun that the IDE on the CD-ROM may not.
For your assignment to be graded, you must identify yourself by including Java comment block at the beginning of your program source code. This comment block must include your name, the date, the assignment number, and your student identification number. You also must provide a description and list of key variables and parameters used.
An example of the minimum Java comment block is:
/**
* Name: Jacob Hood
* Date: When you did the work.
* Assignment: Number
* Student Number: HO3009983
* Description: This program does a, b, and c.
*/
You must name your Java class files (your source code) by concatenating the assignment number (A1 through A7) and your student identification number. For example, if your student number were HO3009983, the your Java class file would be named: HO300983...HO300983
If any assignment fails to compile cleanly, it must be reworked. It will be embarrassing if any of your programs were to fail to compile because the filename and class name did not agree.
In naming your variables, it is essential that you use an acceptable, consistent style and reasonable variable names. Variable names like x, y, and z are to be avoided. If your program needs to compute a total, then an appropriate variable for storing the value would be total or totValue or another meaningful identifier.
In addition, when you declare an important variable, place an inline comment using //, followed by a brief explanation of the variable's use in the program. For example:
int idxR = 0; // Row Index
float inpLen = 0.0; // Input Length
Finally, your .java file should be in plain text suitable for editing using Notepad. It should not have embedded tabs or graphic characters.
Good luck!
Programming Assignment 0: Hello, Java!
Click here to download. (369.521 Kb)
The first programming assignment is intended to help you get started. Do not submit Assignment 0 for review. It is neither graded nor required. But if you have trouble doing Assignment 0, then you are not likely to be successful with the other assignments, so ask for help if necessary.
The attached PDF gives you detailed instructions on how to write a simple console program using Java. This program has a single output statement, which writes "Hello, Java!" to your display screen.
When you download and install the software development kit, be sure to read the instructions carefully. It is important that you download the correct files for your operating system.
The instructions take you step-by-step from writing the source code, to compiling, and then executing. These instructions are as close to "cookbook" instructions as feasible. You likely will have to adapt these instructions to your PC environment in order to get things to work.
Assignment 0: NetBeans Version
Click here to download. (325.468 Kb)
For students who wish to use NetBeans, the attached primer offers detailed steps for getting a simple first program running. Note that you must read the instructions provided with NetBean carefully. It also has tutorial information. Using NetBeans is not required for you to be successful in this course. Do not submit Assignment 0 for review. It is neither graded nor required.
Programming Assignment 1 (Follows Module 2)
Write a console program that prompts the user to input the length and width of a rectangle and then prints the rectangle's area and perimeter. Note that a "console program" is one that is runnable from the MS-DOS command prompt.
Include your source code and compiled files as attachments. Clearly identify yourself and indicate the assignment in the source code file as a comment at the start of the file.
Programming Assignment 2 (Follows Module 5)
Write a console program that uses a while loop to perform the following steps:
Prompt the user to input two integers: firstNum and secondNum (Hint: Ensure that firstNum is less than secondNum).
Output all results to a file, placing an appropriate label between each section of output.
Output all odd numbers between firstNum and secondNum
Output the sum of all even numbers between firstNum and secondNum.
Output the numbers and their square between firstNum and secondNum.
Output the sum of the squares of the odd numbers between firstNum and secondNum.
Programming Assignment 3 (Follows Module 5)
Write a GUI program to convert all letters in a string to uppercase letters. For example, Alb34ert will be converted to ALB34ERT.
Programming Assignment 4 (Follows Module 8)
Rational fractions are of the form a / b, where a and b are integers and b != 0. In this exercise, by "fractions" we mean rational fractions. Suppose a / b and c / d are fractions. Arithmetic operations on fractions are defined by the following rules:
a/b + c/d = (ad + bc) / bd
a/b - c/d = (ad - bc) / bd
a/b * c/d = ac / bd
(a/b) / (c/d) = ad / bc Hint: Check carefully to avoid divide by zero!
Design the class Fraction that can be used to manipulate fractions in a program. Among others, the class Fraction must include methods to add, subtract, multiply, and divide fractions. When you add, subtract, multiply, or divide fractions, your answer need not be in the lowest terms.
Write a Java console program using the class Fraction that performs operations on fractions. Override the method toString so that the fraction can be output using the output statement.
Programming Assignment 5 (Follows Module 10)
Write a method, removeAll, that takes three parameters: an array of integers, the length of the array, and an integer, say, removeItem. The method should find and delete all occurrences of removeItem in the array. If the value does not exist or the array is empty, output an appropriate message. (Note that after deleting the element, the array size will be reduced.) You may assume that the array is unsorted.
Programming Assignment 6 (Follows Module 12)
The Programming Example: Calculator in Chapter 12 is designed to do operations on integers. Write a similar program that can be used to do operations on decimal numbers. (Note: If division by zero occurs with values of the int data type, the program throws a division by zero exception. However, if you divide a decimal number by zero, Java does not throw the division by zero exception; it returns the answer as infinity. However, if division by zero occurs, your calculator program must output the message ERROR: / by zero.)
Programming Assignment 7 (Follows Module 13)
Modify the WhiteBoard.java source code given in Chapter 13 to make it work as an applet. Create an HTML file that uses it.