Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4 . 1 Applied Lab: Card Applications In this lab, we will write an application to store a deck of cards in a linked list,

4.1 Applied Lab: Card Applications
In this lab, we will write an application to store a deck of cards in a linked list, and then write methods to sort and shuffle the deck.
Step 1: Copy your LinkedList
Copy your completed LinkedList class from Lab 4 into the LinkedList.java file below.
Step 2: Implement the methods of the Card class
Complete all methods of the Card class as described by the Javadoc comments. The class contains both a suit and a rank. A suit is one of the categories into which the cards of a deck are divided. The rank is the relative importance of the card within its suit.
Note that the Card constructor must convert any rank and suit letters to uppercase.
For the equals() method, be sure to follow the steps outlined in Lesson 4. If you did not learn how to implement the compareTo() method in your prior course, read the tutorial here.
Note that you are not allowed to add any additional methods or member variables to this class or you will not receive credit for this assignment.
Step 3: Implement the methods of the CardApp class
Complete all methods of the CardApp class in the CardApp.java file as described by the Javadoc comments.
You may add as many methods as you would like to this file, but are not allowed to add any additional member variables.
The CardApp program must prompt for and allow the user to enter the name of any input file as shown in the Example output below.
Enter the name of a file containing a deck of cards: cards1.txt
Please open shuffled.txt and sorted.txt.
Goodbye!
Implement the shuffle() method as specified in the comments for shuffle(). After you have shuffled the deck of cards, write the result into a file named shuffled.txt.
Implement the sort() method using bubble sort from Lesson 4. First sort by suit in alphabetical order and then by rank from 2 to A. The pseudocode for bubble sort is as follows:
for i =0 up to and including length -2
for j =0 up to and including length - i -2//each pass make fewer comparisons
if A[j]> A[j+1]
A[j]<---> A[j+1]//swap
After you have sorted the deck of cards, write the result to a file named sorted.txt.
The CardApp.java file also contains the main() method of the application. Use Develop mode to test your CardApp code along with your Card and LinkedList code.
All input and output files must contain a list of cards, with each card stored on its own line. See the example files cards1.txt and cards2.txt for example file formats.
Simple Shuffle Example: The below example is intended to help you verify that you understand how to shuffle the cards
Before shuffling:
2H 3H 4H 5H 6H 7H 8H 9H 10H JH
First and last swapped:
JH 3H 4H 5H 6H 7H 8H 9H 10H 2H
Swapped 3H and 6H
JH 6H 4H 5H 3H 7H 8H 9H 10H 2H
Swapped 5H and 8H
JH 6H 4H 8H 3H 7H 5H 9H 10H 2H
Swapped 7H and 10H
JH 6H 4H 8H 3H 10H 5H 9H 7H 2H
***End first set of swaps***
JH 6H 4H 8H 3H 10H 5H 9H 7H 2H
Swapped 6H and 8H
JH 8H 4H 6H 3H 10H 5H 9H 7H 2H
Swapped 4H and 3H
JH 8H 3H 6H 4H 10H 5H 9H 7H 2H
Swapped 6H and 10H
JH 8H 3H 10H 4H 6H 5H 9H 7H 2H
Swapped 4H and 5H
JH 8H 3H 10H 5H 6H 4H 9H 7H 2H
Swapped 6H and 9H
JH 8H 3H 10H 5H 9H 4H 6H 7H 2H
Swapped 4H and 7H
JH 8H 3H 10H 5H 9H 7H 6H 4H 2H
Swapped 6H and 2H
JH 8H 3H 10H 5H 9H 7H 2H 4H 6H
***End second set of swaps***
After shuffling:
JH 8H 3H 10H 5H 9H 7H 2H 4H 6H
Bubble Sort Tutorial Video
Here is a Bubble Sort video tutorial from my CIS 36B course.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

Define Management or What is Management?

Answered: 1 week ago

Question

What do you understand by MBO?

Answered: 1 week ago

Question

=+3. What are the components of a social media communication audit?

Answered: 1 week ago