For each of the following problems, write up your answers in a plain text (ASCII) file with at most 80 characters per line. Do not use Word (.doc or docx) or Rich Text Format (.rtf). At the top of the file put your name, andrew id, and time you spent to complete both the problems and programming parts. Put this file in the project folder Homework5 you will create in Part II of this assignment.
System.out.println(s1.equals(s2));
System.out.println(s1.equals(s2));
int sum = 0;
for (int i = 1; i <= n; i+=2)
for (int j = 1; j <= n; j+=3)
sum += (i+j);
int sum = 0;
for (int i = 1; i <= 5; i++)
for (int j = 1; j <= n; j++)
sum += (i+j);
int sum = 0;
for (int i = 1; i <= m; i*=2)
for (int j = 1; j <= n; j++)
sum += (i+j);
int sum1 = 0;
for (int i = 1; i <= n; i++)
sum1 += i;
int sum2 = 0;
for (int j = 1; j <= n*n; j++)
sum2 += j;
public static boolean hasAdjacentDuplicates(int[] a) {
for (int i = 0; i < a.length-1; i++)
if (a[i] == a[i+1])
return true;
return false;
}
public static boolean sumInArray(int[] a, int sum) {
//finds sum of all pairs in the array
for (int i = 1; i < a.length; i++)
for (int j = 0; j < i; j++)
if (a[i] + a[j] == sum)
return true;
return false;
}
Card images from http://www.jfitz.com/cards/
In this assignment, you will complete a program to play the game Aces Up.
The goal is to discard as many cards from four piles as possible, leaving only Aces at the end.
A standard 52-card deck is shuffled and the four cards are dealt face-up to create four one-card piles. On each turn, the player can discard a card, move a card or deal four cards.
DISCARD: The top card on a pile can be discarded if there is another face-up card of the same suit that has a higher rank. (Ranks, from low to high, are 2,3,4,5,6,7,8,9,10,J,Q,K,A.) Whenever a card is discarded, the player earns points based on the rank of the card. Number cards are worth their value in points (e.g. a 9 of Hearts is worth 9 points). Jacks are worth 11 points, Queens are worth 12 points, andn Kings are worth 13 points. Aces are not worth any points since they cannot be discarded in this game.
MOVE: The top card on a pile can be moved to any empty pile.
DEAL 4: If a player chooses to deal four more cards from the deck, either by choice or because no cards can be discarded or moved, one card is placed face-up on the top of each pile (including any empty piles). Note that at any time, you can only see the top card on each non-empty pile.
The game ends when all cards have been discarded except the Aces or when no further play is possible.
Download a copy of the AcesUp.zip project file.
Complete the supplied Java program to play a correct game of Aces Up.
The file contains four classes:
In the GameController class, you must use an ArrayList to store a standard deck of 52 playing cards. Use generics for this list with a type of PlayingCard as its base type. Use ArrayLists for each of the four piles of cards and for the discard pile as well. You can shuffle the deck of cards by using the Collections.shuffle method. Its parameter should be a reference to the array list that holds your deck of cards. When you move a card from one list to another, do this in the most efficient manner possible. You may add additional private helper methods as you wish to simplify and organize your program code.
Implementation Note: The GUI has a button for DISCARD and MOVE for each pile and a button to DEAL 4 more cards. If any of these operations are invalid for the current state of the game, nothing should change in the game. Clicking NEW GAME always starts a new game.
DO NOT CHANGE ANY CODE ALREADY GIVEN TO YOU. YOUR ADDITIONAL CODE SHOULD WORK WITH THE CODE PROVIDED TO YOU.
In your code, you must print the current cards in the deck and the four piles to the console window after each play is made. This will be helpful to you and to the TA for testing purposes.
The project you downloaded contains a folder named images that contains pictures of all of the playing cards used in the game. If you use Eclipse to run this project, the folder is in its correct place (the top level of the project). If you use the command-line to compile and run the program, move this folder to the src folder where the Java source code is.
Write comments to match the Javadoc comments given above (as best as you can). Add additional comments in your methods to explain your code where necessary. Use appropriate variable names for self-documentation and indent properly.
When you have completed this assignment and tested your code
thoroughly, create a .zip (archive or compress) file of your Homework3
folder. Autolab only accepts .zip files. (To create a .zip file,
right-click (or
Make sure to keep a copy of your work just in case!