Week #9 Discussion Details

Project Assignment 10 - Extra Credit

Due to our other section of CIS 3022 not being able to cover all of the material on Project Assignment 10 by the end of lecture Wednesday, October 28, 2009, recursion and UML diagrams will not be tested on Exam II. Thus, Project Assignment 10 is now optional and will be an Extra Credit project assignment. I recommend preparing for the material on Exam II before working on this assignment. We will be picking up with the material related to this assignment after Exam II.

Collection: class HashSet

The class HashSet provides an object type that stores a collection of elements. The elements are stored in no specific order, compared to an array or ArrayList where the elements are stored in an indexed sequence. When two iterators of the HashSet are created, there is no guarantee the order of the elements of the set will be returned the same sequence. The object type of the elements is defined within the declaration of the collection. Review the Java API documentation of the class HashSet to see the structure of the class and the methods provided.

Modifier: static

When a property or method is static, there is only one instance of the property or method for all instances of the classification. When static, all references to a property see/access/modify the same property. When static, a method can only use static properties and any variables declared within the method itself, all references must be within a static context. A static property or method is also referred to as non-instance or class property or method. The property or method can be accessed by listing the name of the class followed by a period and the name of the desired property or method.

Examples of this are the usages of static within the class Math. The properties of the class Math, Math.PI and Math.E relate to the entire classification of mathematics and not a single instance. The same is true for the methods within the class Math, for example Math.abs(int a) and Math.sqrt(double a) also relate to the entire classification of mathematics and not a single instance.

A non-static property or method is also referred to as an instance property or method. Instance properties and methods must be accessed through an instance of the classification. Recall an instance of a classification is created by declaring a variable of the desired class type and then calling the class constructor to create a specific object instance. Until now, we have focused our attention on using only instance properties and methods.

Modifier: final

When a variable is declared to be final, the initial value assigned to it is the only value that can ever be assigned to the variable. It is the final value of the variable.

Control Structures: do while Loops

We have introduced the do while loop which assists our program in repeating the execution of a set of statements. Here is the general structure of the do while loop.

Exercises

Please note, it is likely you will not have the time to complete all of these exercises during your discussion. They are given to you so that you can review and practice using our recent topics. Use them as a study aid during the rest of the week to supplement the home work given in the project assignments.

  1. Create a HashSet that stores Integer values. Allow the user to add values to the HashSet. Also, allow the user to print all the values currently within the HashSet. Observe whether or not the values are printed in the order they were entered.
  2. Create a method that will copy the values from the HashSet of the previous question to an array.
  3. Here are .class files for: the class Number and the class RomanNumberalSymbol. These are solutions to the following problems. They provide a menu system allowing for you to test multiple options and see different results. Note, you will need both files downloaded into the same directory and they are .class files. As we have discussed, you can execute the program from the command prompt/terminal window by entering: java Number
  4. Create a method that will receive a int value and return a String composed of the String representations of each digit within the int. List the String values from left to right in the same order as the digits. For example, if 1234 is passed to the method, "one two three four" is returned by the method. Also, if 428 is passed to the method, "four two eight" is returned by the method.
  5. Create the class RomanNumeralSymbol. The class will represent Roman Numerals. A Roman Numeral is represented by a symbol: I, V, X, L, C, D, & M, and a corresponding decimal value. through 10. The corresponding value for each Roman Numeral Symbol is: I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000.
  6. Create a method that will convert an int value into its Roman Numeral equivalent. In your solution, only solve numbers up to the decimal value 4000. More history about and examples of Roman Numerals can be found here and here. Recall these definitions related to Roman Numerals.
<<<< Prev     Next >>>>