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 Currency.java, Quarter.java, Dime.java, Nickel.java and Penny.java (10 pts)
• Source code for CurrencyTester.java (10 pts)
All projects and laboratories have to be Eclipse projects that 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 Send To 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. See http://www.cs.utsa.edu/~javalab/lab/accountLogin.html for information on how to set up your account. It is important that you get all account problems resolved in the first week 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. You will need to log in to both your Windows and Unix accounts to change your passwords if you are new to the system. You can also 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
Refer to http://www.cs.utsa.edu/~javalab/lab/eclipse/getstartedeclipse.html for an introduction on how to get started with Eclipse.
When you start Eclipse it will ask you to select a workspace. This is the directory in which all your Eclipse projects will be located. (Theoretically you can switch between different workspaces, but for now let's assume you only have one workspace.) We recommend that you use a directory such as Z:\working\cs2123 as your workspace directory. This laboratory is based on the Currency class. The Currency class has a value, a name, and a two-letter country code. You can find out the name, the value, and the country code. You can also find out whether or not a Currency object is equal to another object. Currency are equal if they are currency with the same name, value, and a country code. (US is the country code for the United States.) All of our classes will also have a toString method for debugging.
Create a new project called currencyproject.
• Open Eclipse and select your workspace directory (such as Z:\working\cs2123\recitations).
• Create a new Eclipse project by selecting File -> New -> Java Project. Give the Name as currencyproject (all lower case). Press Finish.
• Create a Currency class by selecting File -> New -> Class. Use Currency as the Class name and type in currency as the package name. Pay attention to upper and lower case when you type, as Java is case-sensitive. Eclipse will create an empty class called Currency. Implement the functionality of Currency.
• Create a CurrencyTester class which has a main method. (You can select a checkbox that does that for you during the class creation process.)
• Make sure that the main method of CurrencyTester begins with a statement to output the message "This program was written by ... ".
• Add code to CurrencyTester to create a Currency object and to test the methods to get the name and value.
• Create 2 objects of type Currency with different values, but the same names. Output their values using toString. Test to see whether they are equal.
• Also test two different currency objects for equality.
• Create Currency objects with 0 and negative values.
• Create a Quarter class that extends Currency and is specialized to represent quarters. Quarters are US currency. Note: If you have the Currency class (not Currency.java) selected in Eclipse's package explorer and then add a new class, then currency.Currency is automatically selected as the super class. Write test code for Quarter. Subclasses of Currency represent specific denomiations. They should have two constructors: one which is the same as the superclass and one which has no parameters.
Part II: On your own
• Add the following code to CurrencyTester. In a loop which is repeated 10 times, create a new Currency object and assign it to the variable myCurrency. Create each currency object with name theCurrency and value which is a random int value between 1 and 100. Use US as the country code. (Use the Random class with the nextInt method.) Print out each currency object as it is created. After the loop print the maximum currency value, the minimum currency value and the average currency value. Do not use an array.
• Add the Dime, Nickel and Penny classes to the currencyproject. Add test code to CurrencyTester to create and compare various currency.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment