Complete in Java
CardApp.java
public class CardApp {
private LinkedList list;
/**
* User interface prompts user, reads and writes files.
*/
public static void main(String[] args) {
}
/**
* Default constructor to initialize the deck
*/
public CardApp() {
}
/**
* Inserts a new Card into the deck
* @param card a playing Card
*/
public void addCard(Card card) {
}
/**
* Shuffles cards following this algorithm:
* First swaps first and last card
* Next, swaps every even card with the card 3
* nodes away from that card. Stops when it
* reaches the 3rd to last node
* Then, swaps ALL cards with the card that is
* 2 nodes away from it, starting at the 2nd card
* and stopping stopping at the 3rd to last node
*/
public void shuffle() {
}
/**
* Implements the bubble sort algorithm
* to sort cardList into sorted order, first by suit
* (alphabetical order)
* then by rank from 2 to A
*/
public void sort() {
}
/**
* Returns the deck of cards with each card separated
* by a blank space and a new line character at the end.
* @return The deck of cards as a string.
*/
@Override public String toString() {
return "";
}
}
Card.java
public class Card implements Comparable{
private String rank;
private String suit;
/**
* Constructor for the Card class
* @param rank the rank of card from 2 to A
* @param suit the suit of card C, D, H, or S
*/
public Card(String rank, String suit) {
}
/**
* Returns the card's rank
* @return rank a rank from 2 (low) to A (high)
*/
public String getRank() {
return "";
}
/**
* Returns the card's suit
* @return C, D, H, or S
*/
public String getSuit() {
return "";
}
/**
* Updates the card's rank
* @param rank a new rank
*/
public void setRank(String rank) {
}
/**
* Updates the card's suit
* @param suit the new suit
*/
public void setSuit(String suit) {
}
/**
* Concatenates rank and suit
* @return card rank and suit
*/
@Override public String toString() {
return "";
}
/**
* Overrides the equals method for Card
* Compares rank and suit and
* follows the equals formula given in
* Lesson 4 and also in Joshua Block's text
* @param obj another Object to compare for
* equality
* @return whether obj is a Card and, if so,
* of equal rank and suit
*/
@Override public boolean equals(Object obj) {
return false;
}
/**
* Orders two cards first by suit (alphabetically)
* Next by rank. "A" is considered the high card
* Order goes 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A
* @param card another Card to compare to this Card
* @return a negative number if this comes before c
* and a positive number if c comes before this
* and 0 if this and c are equal according to the above
* equals method
*/
@Override public int compareTo(Card card) {
return -1;
}
}
}
LinkedList.Java
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
/**
* Returns the value stored in the first node
* @precondition
* @return the value stored at node first
* @throws NoSuchElementException
*/
public T getFirst() throws NoSuchElementException {
return null;
}
/**
* Returns the value stored in the last node
* @precondition
* @return the value stored in the node last
* @throws NoSuchElementException
*/
public T getLast() throws NoSuchElementException {
return null;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
return null;
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return -1;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return false;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return false;
}
/**** MUTATORS ****/
/**
* Creates a new first element
* @param data the data to insert at the front of the LinkedList
* @postcondition
*/
public void addFirst(T data) {
return;
}
/**
* Creates a new last element
* @param data the data to insert at the end of the LinkedList
* @postcondition
*/
public void addLast(T data) {
return;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
return;
}
/**
* removes the element at the front of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeFirst() throws NoSuchElementException {
return;
}
/**
* removes the element at the end of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeLast() throws NoSuchElementException {
return;
}
/**
* removes the element referenced by the iterator
* @precondition
* @postcondition
* @throws NullPointerException
*/
public void removeIterator() throws NullPointerException {
}
/**
* places the iterator at the first node
* @postcondition
*/
public void positionIterator(){
}
/**
* Moves the iterator one node towards the last
* @precondition
* @postcondition
* @throws NullPointerException
*/
public void advanceIterator() throws NullPointerException {
}
/**
* Moves the iterator one node towards the first
* @precondition
* @postcondition
* @throws NullPointerException
*/
public void reverseIterator() throws NullPointerException {
}
/**** ADDITIONAL OPERATIONS ****/
/**
* Re-sets LinkedList to empty as if the
* default constructor had just been called
*/
public void clear() {
}
/**
* Converts the LinkedList to a String, with each value separated by a
* blank space. At the end of the String, place a new line character.
* @return the LinkedList as a String
*/
@Override
public String toString() {
return "n";
}
/**
* Determines whether the given Object is
* another LinkedList, containing
* the same data in the same order
* @param obj another Object
* @return whether there is equality
*/
@SuppressWarnings("unchecked") //good practice to remove warning here
@Override public boolean equals(Object obj) {
return false;
}
/**CHALLENGE METHODS*/
/**
* Moves all nodes in the list towards the end
* of the list the number of times specified
* Any node that falls off the end of the list as it
* moves forward will be placed the front of the list
* For example: [1, 2, 3, 4, 5], numMoves = 2 -> [4, 5, 1, 2 ,3]
* For example: [1, 2, 3, 4, 5], numMoves = 4 -> [2, 3, 4, 5, 1]
* For example: [1, 2, 3, 4, 5], numMoves = 7 -> [4, 5, 1, 2 ,3]
* @param numMoves the number of times to move each node.
* @precondition numMoves >= 0
* @postcondition iterator position unchanged (i.e. still referencing
* the same node in the list, regardless of new location of Node)
* @throws IllegalArgumentException when numMoves < 0
*/
public void spinList(int numMoves) throws IllegalArgumentException{
}
/**
* Splices together two LinkedLists to create a third List
* which contains alternating values from this list
* and the given parameter
* For example: [1,2,3] and [4,5,6] -> [1,4,2,5,3,6]
* For example: [1, 2, 3, 4] and [5, 6] -> [1, 5, 2, 6, 3, 4]
* For example: [1, 2] and [3, 4, 5, 6] -> [1, 3, 2, 4, 5, 6]
* @param list the second LinkedList
* @return a new LinkedList, which is the result of
* interlocking this and list
* @postcondition this and list are unchanged
*/
public LinkedList altLists(LinkedList list) {
return null;
}
}
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. How to implement the compareTo() method is also
covered in Lesson 4. 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: cardsl.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 i2// each pass
make fewer comparisons if A[j]>A[j+1]A[j]<>A[j+1]//swap for i=0 up to and including length -
2 for j=0 up to and including length - i2 //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 cards 2 . txt for example file formats.

Complete in JavaCardApp.javapublic class CardApp { private.pdf

  • 1.
    Complete in Java CardApp.java publicclass CardApp { private LinkedList list; /** * User interface prompts user, reads and writes files. */ public static void main(String[] args) { } /** * Default constructor to initialize the deck */ public CardApp() { } /** * Inserts a new Card into the deck * @param card a playing Card */ public void addCard(Card card) { } /** * Shuffles cards following this algorithm: * First swaps first and last card * Next, swaps every even card with the card 3 * nodes away from that card. Stops when it * reaches the 3rd to last node * Then, swaps ALL cards with the card that is * 2 nodes away from it, starting at the 2nd card * and stopping stopping at the 3rd to last node */ public void shuffle() { } /** * Implements the bubble sort algorithm
  • 2.
    * to sortcardList into sorted order, first by suit * (alphabetical order) * then by rank from 2 to A */ public void sort() { } /** * Returns the deck of cards with each card separated * by a blank space and a new line character at the end. * @return The deck of cards as a string. */ @Override public String toString() { return ""; } } Card.java public class Card implements Comparable{ private String rank; private String suit; /** * Constructor for the Card class * @param rank the rank of card from 2 to A * @param suit the suit of card C, D, H, or S */ public Card(String rank, String suit) { } /** * Returns the card's rank * @return rank a rank from 2 (low) to A (high) */ public String getRank() { return ""; } /** * Returns the card's suit
  • 3.
    * @return C,D, H, or S */ public String getSuit() { return ""; } /** * Updates the card's rank * @param rank a new rank */ public void setRank(String rank) { } /** * Updates the card's suit * @param suit the new suit */ public void setSuit(String suit) { } /** * Concatenates rank and suit * @return card rank and suit */ @Override public String toString() { return ""; } /** * Overrides the equals method for Card * Compares rank and suit and * follows the equals formula given in * Lesson 4 and also in Joshua Block's text * @param obj another Object to compare for * equality * @return whether obj is a Card and, if so, * of equal rank and suit */ @Override public boolean equals(Object obj) { return false;
  • 4.
    } /** * Orders twocards first by suit (alphabetically) * Next by rank. "A" is considered the high card * Order goes 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A * @param card another Card to compare to this Card * @return a negative number if this comes before c * and a positive number if c comes before this * and 0 if this and c are equal according to the above * equals method */ @Override public int compareTo(Card card) { return -1; } } } LinkedList.Java import java.util.NoSuchElementException; public class LinkedList { private class Node { private T data; private Node next; private Node prev; public Node(T data) { this.data = data; this.next = null; this.prev = null; } } private int length; private Node first; private Node last; private Node iterator;
  • 5.
    /**** CONSTRUCTORS ****/ /** *Instantiates a new LinkedList with default values * @postcondition */ public LinkedList() { } /** * Converts the given array into a LinkedList * @param array the array of values to insert into this LinkedList * @postcondition */ public LinkedList(T[] array) { } /** * Instantiates a new LinkedList by copying another List * @param original the LinkedList to copy * @postcondition a new List object, which is an identical, * but separate, copy of the LinkedList original */ public LinkedList(LinkedList original) { } /**** ACCESSORS ****/ /** * Returns the value stored in the first node * @precondition * @return the value stored at node first * @throws NoSuchElementException */ public T getFirst() throws NoSuchElementException { return null; } /** * Returns the value stored in the last node * @precondition * @return the value stored in the node last
  • 6.
    * @throws NoSuchElementException */ publicT getLast() throws NoSuchElementException { return null; } /** * Returns the data stored in the iterator node * @precondition * @return the data stored in the iterator node * @throw NullPointerException */ public T getIterator() throws NullPointerException { return null; } /** * Returns the current length of the LinkedList * @return the length of the LinkedList from 0 to n */ public int getLength() { return -1; } /** * Returns whether the LinkedList is currently empty * @return whether the LinkedList is empty */ public boolean isEmpty() { return false; } /** * Returns whether the iterator is offEnd, i.e. null * @return whether the iterator is null */ public boolean offEnd() { return false; } /**** MUTATORS ****/
  • 7.
    /** * Creates anew first element * @param data the data to insert at the front of the LinkedList * @postcondition */ public void addFirst(T data) { return; } /** * Creates a new last element * @param data the data to insert at the end of the LinkedList * @postcondition */ public void addLast(T data) { return; } /** * Inserts a new element after the iterator * @param data the data to insert * @precondition * @throws NullPointerException */ public void addIterator(T data) throws NullPointerException{ return; } /** * removes the element at the front of the LinkedList * @precondition * @postcondition * @throws NoSuchElementException */ public void removeFirst() throws NoSuchElementException { return; } /** * removes the element at the end of the LinkedList
  • 8.
    * @precondition * @postcondition *@throws NoSuchElementException */ public void removeLast() throws NoSuchElementException { return; } /** * removes the element referenced by the iterator * @precondition * @postcondition * @throws NullPointerException */ public void removeIterator() throws NullPointerException { } /** * places the iterator at the first node * @postcondition */ public void positionIterator(){ } /** * Moves the iterator one node towards the last * @precondition * @postcondition * @throws NullPointerException */ public void advanceIterator() throws NullPointerException { } /** * Moves the iterator one node towards the first * @precondition * @postcondition * @throws NullPointerException */ public void reverseIterator() throws NullPointerException {
  • 9.
    } /**** ADDITIONAL OPERATIONS****/ /** * Re-sets LinkedList to empty as if the * default constructor had just been called */ public void clear() { } /** * Converts the LinkedList to a String, with each value separated by a * blank space. At the end of the String, place a new line character. * @return the LinkedList as a String */ @Override public String toString() { return "n"; } /** * Determines whether the given Object is * another LinkedList, containing * the same data in the same order * @param obj another Object * @return whether there is equality */ @SuppressWarnings("unchecked") //good practice to remove warning here @Override public boolean equals(Object obj) { return false; } /**CHALLENGE METHODS*/ /** * Moves all nodes in the list towards the end * of the list the number of times specified * Any node that falls off the end of the list as it * moves forward will be placed the front of the list * For example: [1, 2, 3, 4, 5], numMoves = 2 -> [4, 5, 1, 2 ,3] * For example: [1, 2, 3, 4, 5], numMoves = 4 -> [2, 3, 4, 5, 1]
  • 10.
    * For example:[1, 2, 3, 4, 5], numMoves = 7 -> [4, 5, 1, 2 ,3] * @param numMoves the number of times to move each node. * @precondition numMoves >= 0 * @postcondition iterator position unchanged (i.e. still referencing * the same node in the list, regardless of new location of Node) * @throws IllegalArgumentException when numMoves < 0 */ public void spinList(int numMoves) throws IllegalArgumentException{ } /** * Splices together two LinkedLists to create a third List * which contains alternating values from this list * and the given parameter * For example: [1,2,3] and [4,5,6] -> [1,4,2,5,3,6] * For example: [1, 2, 3, 4] and [5, 6] -> [1, 5, 2, 6, 3, 4] * For example: [1, 2] and [3, 4, 5, 6] -> [1, 3, 2, 4, 5, 6] * @param list the second LinkedList * @return a new LinkedList, which is the result of * interlocking this and list * @postcondition this and list are unchanged */ public LinkedList altLists(LinkedList list) { return null; } } 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
  • 11.
    sure to followthe steps outlined in Lesson 4. How to implement the compareTo() method is also covered in Lesson 4. 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: cardsl.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 i2// each pass make fewer comparisons if A[j]>A[j+1]A[j]<>A[j+1]//swap for i=0 up to and including length - 2 for j=0 up to and including length - i2 //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 cards 2 . txt for example file formats.