COLLEGE OF ENGINEERING AND APPLIED SCIENCES
DEPARTMENT OF COMPUTER SCIENCE
Spring 2019 – CSI213 Data Structures
Project 3 The project description starts on page 5.The following shows requirements with examples.
1. All projects are individual projects unless it is notified otherwise. If one of the following is true, no credits will be given:
2. The project is late.
3. The design is missing.
4. Wrong files are submitted or part of the source codes is submitted.
5. The project doesn’t compile.
6. The comments are not completely written in Javadoc format.
7. The project is a copy and modification of another student’s project. (Both will receive 0.)
8. The project is copied from Internet or other resources.
Note: Students must turn in their original work. Any copied work from others and/or Internet such as chegg.com will not be credited. Any cheating violation will be reported to the college. Students can help by sharing ideas, but not by allowing others to copy their work.
2. All projects must be submitted via Blackboard. No late projects will be accepted. Documents to be submitted:
3. UML class diagram(s)
4. Java source file(s)
5. Supporting files if any (For example, files containing all testing data)
3. Software Development Project Rubric
All projects will be evaluated based upon the following software development activities.
Analysis:
• Does the software meet the exact specification / customer requirements?
• Does the software solve the exact problem?
Design:
• Is the design efficient?
Code:
• Are there errors?
• Are code conventions followed?
• Does the software use the minimum computer resource (computer memory and processing time)?
• Is the software reusable?
• Are comments completely written in Javadoc format?
a. Class comments must be included in Javadoc format before a class header.
b. Method comments must be included in Javadoc format before a method header.
c. More inline comments must be included in either single line format or block format inside each method body.
d. All comments must be completed in correct format such as tags, indentation etc.
Debug/Testing:
• Are there bugs in the software?
Documentation:
• Complete all documentations that are required.
4. Complete a project following steps of a software development cycle. (These steps are not pure linear but overlapped).
Analysis-design-code-test/debug-documentation.
1. Read project description to understand all specifications(Analysis).
2. Create a design (an algorithm for method or a UML class diagram for a class) (Design)
3. Create a Java program that is a translation of the design. (Code/Implementation)
4. Test and debug, and (test/debug)
5. Complete all required documentation. (Documentation)
The following shows a sample design. The corresponding source code with Javadoc comments are included on next page.

Class comments must be written in Javadoc format before the class header. A description of the class, author information and version information are required.

import java.util.Random;
/**
* Representing a dog with a name.
* @author Qi Wang
Comments for fields are required.

* @version 1.0
*/
Method comments must be written in Javadoc format before the method header. the first word must be a capitalized verb in the third person. Use punctuation marks properly.

open {

public class Dog{

/**
* The name of this dog

*/
private String name;
/**
* Constructs a newly created Dog object that represents a dog with an empty name.
*/
public Dog(){
A description of the method, comments on parameters if any, and comments on the return type if any are required.
A Javadoc comment for a formal parameter consists of three parts: – parameter tag, – a name of the formal parameter in the design , (The name must be consistent in the comments and the header.) – and a phrase explaining what this parameter specifies.
A Javadoc comment for return type consists of two parts: – return tag, – and a phrase explaining what this returned value specifies



open {

this(“”);
}

/**
* Constructs a newly created Dog object with a name.
* @param name The name of this dog
*/

public Dog(String name){
this.name = name;
}
/**
* Returns the name of this dog.
* @return The name of this dog
*/
public String getName(){
return this.name;
}
/**
* Changes the name of this dog.
* @param name The name of this dog
*/
public void setName(String name){
this.name = name;
}
/**
* Returns a string representation of this dog. The returned string contains the type of
* this dog and the name of this dog.
* @return A string representation of this dog
*/
public String toString(){
return this.getClass().getSimpleName() + “: ” + this.name;
}
/**
* Indicates if this dog is “equal to” some other object. If the other object is a dog,
* this dog is equal to the other dog if they have the same names. If the other object is * not a dog, this dog is not equal to the other object.
* @param obj A reference to some other object
* @return A boolean value specifying if this dog is equal to some other object
*/
public boolean equals(Object obj){
More inline comments can be included in single line or block comments format in a method.

//The specific object isn’t a dog.
if(!(obj instanceof Dog)){
return false;
}
//The specific object is a dog.
Dog other = (Dog)obj;
return this.name.equalsIgnoreCase(other.name);
}
}
5. Project description starts on next page.
Project 3 The 24-point card game
The 24-point card game is to pick any 4 cards from 52 cards, as shown in the figure below. Note that the Jokers are excluded. Each card represents a number. An Ace, King, Queen, and Jack represent 1, 13, 12, and 11, respectively. You can click the Refresh button to get four new cards.

Specification:
Enter an expression that uses the four numbers from the four selected cards. Each number must be used once and only once. You can use the operators (addition, subtraction, multiplication, and division) and parentheses in the expression. The expression must evaluate to 24. After entering the expression, click Verify button to check whether the numbers in the expression is correct. Display the verification in a message window (see figures below).
Assume that images are stored in files named 1.png, 2.png, … , 52.png, in the order of spades, hearts, diamonds, and clubs. So, the first 13 images are for spades 1, 2, 3… 13.
Assume that no spaces are entered before the first token, in between tokens, and after the last tokens.
Assume that only numbers can be entered as operands.
Numbers match and the result is 24.


Numbers don’t match.


Numbers don’t match.


More example,
If 2,3,4,5 are selected and displayed, user can try one of the following expressions to win.
2*((3+4)+5)
2*(3+(4+5))
2*((3+5)+4)
2*(3+(5+4))
2*((4+3)+5)
Design:
The following is the design diagram. Part of the design has been implemented. Please download the provided source codes, and complete the rest of the project.
This part needs to be designed
and implemented.


• GUI( Provided):
A graphical user interface is required. Use Swing components/containers. Proper events must be handled. It is recommended that a listener is implemented in the most reusable format. Here is the containment hierarchy:
◦ The frame contains a panel (JPanel).
◦ The panel contains all components in proper layouts.
▪ A card can be made using a label with an image icon.
▪ To store images, create folder image in the project folder, create a subfolder card, and store all images in folder card. Note: This is required so that we can run your project without errors.
◦ A driver program creates a frame (JFrame) in main.

• Other classes( To be completed):
(No static methods) To evaluate an user-entered infix expression, the infix expression MUST be converted to postfix expression first, and then the postfix expression is evaluated if numbers are correct. Define Class Expression including the following methods (no static methods). Other methods such as constructors and helper methods should be included in class Expression.
◦ infixToPostfix: Converts this infix expression to a postfix expression, returns a postfix expression as a list of tokens. The algorithm is discussed in class. (No static methods)
public ArrayList
• evaluate: Converts this infix expression to postfix, evaluates the postfix expression, and returns the result. (No static methods)
public int evaluate(){…}
The algorithm (infix to postfix) is listed below.
As long as there are more tokens, get the next token.
If the token is an operand, append it to the postfix string.
If the token is “(“, push it onto the stack.
If the token is an operator, (order operators by precedence)
if the stack is empty, push the operator onto the stack.
if the stack is not empty, pop operators of greater or equal precedence from the stack and append them to postfix string, stop when you encounter “)” or an operator of lower precedence or
when the stack is empty. And then, push the new operator onto the stack.
When you encounter a “)”, pop operators off the stack and append them to the end of the postfix string
until you encounter matching “(“.
When you reach the end of the infix string, append the remaining content of the stack to the postfix
String.
◦ Supporting methods.
Both algorithms must use a stack to store objects/tokens. Define interface GenericStackInterface, and implement it using an array list. It should have the following operations:
◦ Construct an empty stack (GenericStack(){…} ).
◦ Return the number of objects of this stack( getSize() {… }).
◦ Return a reference to the top element of this stack( peek() {…}).
◦ Add an object to the top of this stack( push(E o) {…}).
◦ Remove from the top of this stack( pop() {…}).
◦ Indicate if this stack is empty( isEmpty() {…}).
public class GenericStack
private java.util.ArrayList
…
}
Note: you may have used JCF Stack for lab 08. For this project, you have to design your own ADT Stack, and implement it using an array list. The rest of the lab 08, Expression class, should be reused here.
Code/Test/Debug:
Test the entire program completely.