The purpose of the following example is to get you acquainted with the Vector class in Java. We're going to create a program that simulates a deck of cards. The constraints are; you may only use Vectors and arrays. As you may know, Vectors only accept objects so your cards should be objects. The initial portion of the program display the cards and their suites in order (i.e. Ace of Diamonds, King of Diamonds, Queen of Diamonds ... 2 of Diamonds ... Ace of Hearts, King of Hearts ... ). You are to create your own shuffle algorithm; do not use Collections.shuffle(). Here's what I came up with.
Wanted to show that certain data structures in Java can be created by you. In this example, we'll go ahead and create an ArrayList data structure that has some of the methods that the built in ArrayList class has. We'll create 2 constructors: The default constructor that creates an ArrayList with a default size of 10. Constructor that allows an initial size to be passed to the array. We'll also create a number of methods: void add(Object x); A method that allows you to place an Object at the end of the ArrayList. void add(int index, Object x); A method that allows you to place a value at a given location. Object get(int index): Allows you to retrieve a value of the arrayList array from a given location. int size(); Allows you to get the number of elements currently in the Arraylist. boolean isEmpty(); Tests to see if the Arraylist is empty. boolean isIn(Object x); A method that sees if a particular object exist in the arrayList. int ...
Comments
Post a Comment