CS 1713/CS 1711 Lecture Case Studies

Case Study 1: Creating and running a simple Java program

Description: This program outputs a message to the screen and exits.

Objectives:

Project: Source:

Case Study 2: Using keyboard input to calculate information about a rectangle

Description: This program prompts for your name and then says hello to you.

Objectives:

Project:

Source:

Case Study 3: Developing a simple class that represents a rectangle

Description: The Rectangle class represents a single rectangle and knows its length, width, area and perimeter. Some of this information it will store as attributes, the remainder it will calculate when asked. The RectangleTester program has a main method to create (instantiate) several Rectangle objects and call methods. It is used for testing and debugging. These classes are developed incrementally during the lecture case study to show how to develop incrementally.

Objectives:

Project:

Source:

Case Study 4: Developing and enhancing a class representing a counter

Description: A counter has-a count that can be incremented and decremented. The count can be set to zero. The value of the count can be displayed. Initially the value of the count is zero.

An enhanced version of the counter can be initialized or reset to any value. It is also possible to increment or decrement the counter by any value.

Objectives:

Source:

Additional example:

This case study also included the Sheep class which uses a static variable count to keep track of how many Sheep objects have been created. The following Sheep class has two counters, a static one to keep track of the number of Sheep objects that are created and a non-static one that keeps track of the number of times a particular Sheep says Baa!.

Case Study 5: Developing and testing the Account class

Description: An account at a local bank keeps the name of the person with the account, the account number (a string of characters), the beginning balance for the month, the current balance, the amount of all deposits for the month, and the amount of all withdrawals for the month. The person (through the bank) can make deposits to and make withdrawals from the account. The bank (client) will need to print all the information about the account as well as print the individual pieces of information about the account. At the end of each month the bank (client) will need to initialize the deposits and withdrawals to zero. Design an Account class for this specification.

Objectives:

Source: Source:

Case Study 6: Tracing flow of control in programs

Description: This case study develops three classes that illustrate flow of control for the three types of Java loop control structures: for, while and do-while.

Objectives:

Source: Source:

Case Study 7: Passing objects as parameters - the RationalNumber class

Description: A rational number has a numerator and denominator. Two rational numbers can be added, subtracted, multiplied or divided to produce a new rational number. A rational number can also produce its reciprocal. Rational numbers can be tested for equality. Rational numbers are stored in reduced form (i.e., common factors from numerator and denominator are removed).

Objectives:

Source:

Case Study 8: Developing a utility class with static methods - the WordUtility class

Description Develop a WordUtility class that contains static methods to perform the following useful functions on strings:

Objectives:

Source:

Case Study 9: Arrays as parameters - the ArrayUtility class

Description: Implement an ArrayUtility class, which is patterned after the Math class, containing static methods that perform various operations on arrays:
   public static void printForwards(int [] array); // outputs array
   public static void printBackwards(int [] array); // outputs array in reverse order
   public static int getSum(int [] array); // returns sum of array values
   public static double getAverage(int [] array); // returns average of array values
   public static int getMax(int [] array); // returns minimum value in array
   public static int getMin(int [] array); // returns maximum value in array
   public static int [] reverse(int [] array); //returns new array with elements reversed
   public static int [] clone(int [] array); // returns a new array with copy of array
   public static int find(int [] array, int target); // returns index of target in array 
                                                     // or -1 if not there
Objectives:

Source:

Case Study 10: Arrays of objects in classes - the ClassList class implemented with an array

Description: The ClassList class holds information about students in a course. ClassList has the title of the course, the discipline, the course number, the name of the instructor, and the semester in which the course is offered. ClassList also contains a list of students enrolled in the course and their grades. In addition to the usual accessors and the toString method, ClassList has methods to add or remove a student from the course, to change the grade of a student, and to find the grade of a student given the student ID.

Objectives:

Source:

Case Study 11: Using a Java Collection in a class - the ClassList class implemented with an ArrayList

Description: Reimplement the ClassList class using an ArrayList instead of an array.

Objectives:

Source:

Case Study 12: Using a 2D array in a class - the TicTacToe class

Description: Tic-tac-toe is a game played on a board (usually 3 x 3) by two players represented by 'X' and 'O'. The players alternate turns with 'X' always starting. The player whose turn it is, writes his/her symbol in an unoccupied square of the board. A player wins if a row, column, or major diagonal is fully occupied by the player's symbol. If all of the squares are filled without a winner, the game is a draw.

Develop a TicTacToe class that keeps track of the playing of a tic tac toe game. (The game will not limit itself to a 3x3 boardsize, but will choose this size as the default.) The TicTacToe class keeps track of the board size, the state of the board, and the number of moves made so far. If the game is in process, TicTacToe keeps track of which player goes next. If the game has finished, TicTacToe has the winner ('X', 'O', or 'D'). TicTaxToe has the usual acceessor and toString methods. Finally, the TicTacToe class has a method:
   public boolean move (int x, int y)
which makes the move specified by (x, y). If the specified move is valid (in range and the square is not already occupied), the method writes the symbol of the player whose turn is next into the square (x, y) and returns true. If the move was invalid, the method returns false and makes no changes in the state. (Of course, some other attributes will need to be updated when a move is made.)

Objectives:

Source:

Case Study 13: Abstract classes and inheritance - the Shape class

Description: The is-a relationship holds between two concepts when the first is a specialized instance of the second. That is, for all practical purposes the behavior and data associated with the more specific idea form a subset of the behavior and data associated with the more abstract idea. The Shape class holds the attributes that are common to all shapes, in this case a name and an area. However, the specific details of how to calculate the area is left to the subclasses. Hence, Shape is an abstract class.

Objectives:

Source:

Case Study 14: Searching and sorting arrays of Comparable and int

Description: Searching means to find the position of a specified value in an array. Sorting is the process of rearranging a collection of items so that they appear in ascending or descending order. This case study develops two searching algorithms (linear and binary) as well as two sorting algorithms (selection and insertion) for arrays of int and arrays of Comparable.

Objectives:

Source:

Case Study 15: Tic Tac Toe Design

Description: There are many ways to do the design. The solution presented here uses interfaces in which the mthods all no return value.

Objectives:

Source:

Case Study 16: Creating simple applets

Description: An applet is a Java program that is meant to be embedded on a web page. When the applet is activated (by clicking on its representation), the applet code is downloaded to the client's machine and executed. This case study develops two simple applets and experiments with their execution.

Objectives:

Source:

Case Study 17: Graphics and GUIs in Java

Description: A GUI or graphical user interface is a graphical component designed to interact with a user. You access most applications (JBuilder, your browser, your word processor, etc.) through a GUI. You start the application, a window comes up, and the application waits for you to do something. Generally you click on a button or pull down menu and select a menu item to get things started. After the application performs the command, it waits for another. Applications designed around a GUI are event-driven. This case study gives examples of different kinds of GUIs.

Objectives:

Source:

Case Study 18: Tic Tac Toe GUI

Description: This case study develops a Tic Tac Toe game based on Case Study 15. The only new class is UserGUI. The GameDriver was modified to use this class. All of the others are classes are identical to the ones in Case Study 15.

Objectives:

Source: