CS 1721 Laboratory 1
Testing a simple class hierarchy based on the Coin class
Objectives:
- Become familiar with the rules and facilities.
- Log in to your Windows and Unix accounts.
- Set up your Windows and Unix accounts so that the passwords
agree.
- Use a Java development environment
- Create and run a simple Java program using simple classes.
Hand-in Requirements:
- Source code for Coin.java, Quarter.java, Dime.java,
Nickel.java and Penny.java (15 pts)
- Source code for CoinTester (5 pts)
All projects and laboratories will be submitted electronically through
webCT under the Submissions
menu. Zip up your entire project directory to submit as the source.
(Right click on the project folder and follow the SentTo link.)
Overview:
The goal of this laboratory is for you to get your account
set up and to understand how to run simple Java programs.http://www.cs.utsa.edu/~javalab/lab/accountlogin.html
It is important that you get all account problems resolved in
the first two weeks of class. You will have an account on the CS
network that works on the Windows, Sun and Linux (Unix) machines in the
Computer Science
Laboratories. We will mainly be using Windows machines for this course.
If your laboratory meets
in the Java teaching laboratory (SB 3.02.02), you will need to log in
to both your Windows and Unix
accounts to change your passwords. If your lab does not meet in
SB 3.02.02, you should go to SB 3.02.02 during open laboratory
hours (
http://www.cs.utsa.edu/~javalab/lab/schedule.html) and reset your
passwords. If you are unfamiliar with the system, please ask a tutor to
help. The tutors are available to give
you as much help as you need on the laboratories. Please ask for help
if you are having trouble.
Part I: Running a simple project
This laboratory is based on the Coin class. The Coin
class has a value and a name. You can find out the name or the value of
a Coin. You can
also find out whether or not the coin is equal. All of our classes will
also have a toString method
for debugging.
Create a new project called coinproject.
Your presenter will take you through the steps for creating a simple
JBuilder project called
coinproject.
- Select File -> New Project. Give the Name as coinproject
(all lower case).
If you are working in SB 3.02.02, the Directory should be
Z:\working\java\coinproject.
If your lab is being offered in one of the teaching
classrooms, use c:\cs1723\yourname\coinproject. Press Finish.
JBuilder will create an empty project.
- Create a Coin class by selecting File -> New
Class. Use Coin as the Class name.
Pay attention to upper and lower case when you type, as Java is
case-sensitive. JBuilder will create an empty class called Coin:
- Add code to CoinTester to do the following tests.
Create 2 objects of type Coin with different values, but the
same names. Output their values using toString.
Test to see whether they are equal.
- Create a Quarter class that extends Coin and
is specialized to represent
quarters. Write test code for it.
Part II: On your own
- Add the following code to CoinTester. In a loop which
is repeated 10 times, create a new Coin object and assign it
to the variable myCoin. Create each coin with name coin
and
value which is a random int value between 1 and 100. (Use the
Random class with the nextInt method.)
Print out each coin as it is created. After the loop print the maximum
coin value, the minimum coin value and the average coin value.
Do not use an array.
- Add the Dime, Nickel and Penny
classes to the coinproject. Add test
code to CoinTester to create and compare various coins.