Search

Solution Cart

Remove item Thumbnail image Product Price Quantity Subtotal
× Large Integers Part #1 Largelnteger Class An array can be used to store large integers, one digit at a time. For example, the integer 1234 could be stored in the array num by setting num[0] to 1, num[1] to 2, num[2] to 3, num[3] to 4. However, for this class implementation, you might find it more useful to store the digits backward; that is, place 4 in num[0], 3 in num[1], 2 in num[2], and 1 in num[3]. For the sake of simplicity, we will be storing and manipulating only with positive large integers. Implement a class named Largelnteger that stores a large integer as an array of its digits. Class must extend HasState class (provided). This is needed to make sure clone() method is written correctly. Class must have the following: - Fields - Constant arraySize must be set to 23 - Partially filled array of integers of length 23 - int digitCount keeps the number of digits in large integer, e.t. how many elements of the partially filled array are used to store the number - No-argument constructor that stores number 0 in the array. Sets digitCount to 1 - Constructor that takes a string as a parameter. The constructor parses the given string and converts it into Large Integer by storing digits in the partially filled array. - Create a new custom Exception class called LargelntegerNumberFormatException. The constructor throws exceptions of this type when - string is too long to be stored as a 23-digit number or - when string is empty or - when the string contains non-digits and thus cannot be converted into a number. - Constructor that takes a number of type long as a parameter and builds an object from it by storing digits in an array. - This constructor also throws a custom LargelntegerNumberFormatException when a parameter passed to the constructor is a negative number. - getDigitCount() accessor to the digit count variable. - toString() method that converts an array into a string of numbers in the correct order. Number 12345 is converted into a string "12345" - add(Largelnteger) method that returns the sum of this integer and the one passed as a parameter. The method adds two large integers by implementing the usual "paper and pencil" addition algorithm. This is when the backward storage arrangement of those numbers in arrays will pay off. Carry-over will be easier to do when the integer is stored backward. - Create another custom Exception class called LargelntegerOverflowException. If the resulting number is more than 23 digits long, the add() method throws a LargelntegerOverflowException type exception. - Implement clone() method. - Make your class implement Relatable interface. Code of the interface is provided. Implement all three methods of the Relatable interface. Part #2 Polymorphic Class This class exists only to house one static method called isSorted(). The method must take an array of objects of type Relatable and check if the array is sorted with the help of methods of Relatable interface. The method returns true if the array is sorted and false if it is not. The whole purpose of this exercise is to illustrate the concept of polymorphism. The purpose of this class is to house three static methods. 1. Method void writeLargelntegerArray(Largelnteger[], String) takes an array of Large Integers and a name of a file as parameters. The method writes the contents of the given array into the given binary file (in binary mode). The method throws IOExceptions. The IOExceptions may originate in the methods but must not be handled. Instead, they must be propagated to the calling code. - Make sure to add implements Serializable to the Largelnteger class header. Binary IO will fail to work without that. 2. Method Largelnteger[] readLargelntegerArray(String) method reads the contents of a binary file with the given name as an array of objects of type Largelnteger. Assume you do not know the amount of data in the file. Read data one Largelnteger object at a time and store the objects in ArrayList first. After the end of the file has been reached, convert the ArrayList into a regular array of objects that can be returned from the method. - Please study EOFDemo.java code example to learn how to use exceptions when checking for the end of the file while reading from a binary file. - This method also throws IOExceptions. The IOExceptions may originate in the methods but must not be handled. Instead, they must be propagated to the calling code. 3. Method Largelnteger addLargelntegersFromFile(String) takes a text file name as a parameter. It reads an arbitrary number of strings of text from the file, converting them into Largelntegers as it reads. The Large Integers are added one by one to the running total with the help of add() method. The sum of all the Large Integers stored in the file as strings is then returned from the method. - The structure of the file may be imperfect. Some strings may contain corrupted data and will fail to be converted into Largelnteger. This must not interrupt the process of reading from the file. The corrupted string must be skipped over, and the next string must be read and converted. Use a try/catch block to catch and ignore LargelntegerNumberFormatException. - The sum of all numbers stored in the file may become too big to be stored in a Large Integer. In that case, a LargeIntegerOverflowException exception will be thrown by the add() method. If this happens, catch the exception and return a null value from the method. - This method also throws IOExceptions. The IOExceptions may originate in the methods but must not be handled. Instead, they must be propagated to the calling code. Large Integers Part #1 Largelnteger Class An array can be used to store large integers, one digit… $20.00
$20.00
× Title: Card Game Simulation using Stack and Deck Description: Create a program that simulates a simple card game using a stack and a deck of cards. The objective of the game is to implement basic card manipulation operations using stacks and to showcase the fundamental principles of a deck-based game. Suggested list of data structures: 1. Use a struct or class to store data about each card: struct Card { string suit; string rank; } 2. Use the following arrays or an alternative data structure for each of the following: a. Deck: An array to store the initially created deck of cards Card deck[52] b. Suits: An array to store the list of suits e.g., string suits[] = {"Hearts", "Diamonds", "Clubs", "Spades"} c. Ranks: An array to store the following ranks: string ranks[] = {"2", "3", "4", "5", "6", "7", "8","9","10","Jack","Queen","King", "Ace"} d. A stack to store the cards to be dealt. Struct cardsStack {} e. An array named hand that tracks 5 cards (handSize) given to the player. 3. You may also need to declare the following integer values: a. numberOfCards = 52 b. numberOfRanks = 13 c. numberOfSuits = 4 d. handSize = 5 Include the following functions: 1. Create an array of type Card, which holds a deck of standard playing cards (52 cards: 4 suits - hearts, diamonds, clubs, spades; each suit with cards 2 through 10, Jack, Queen, King, Ace). 2. Shuffle: randomly shuffle the deck of cards. 3. Store the cards in a stack using push. 4. DealCards: pop 5 cards from the deck of cards into an array of cards (hand) e.g., Hand[handSize] 5. Create a function to evaluate the user's hand by adding the corresponding values: The total value for a hand of 5 cards is between 11 and 69. 6. Generate a random number between 11 and 69 to represent the value of 5 cards played by the computer. 7. Compare the randomly generated value that represents the computer's score to the total value of cards held in the player's hand. The higher score wins. Output: 1. Print the deck of cards before shuffling 2. Print the deck of cards after shuffling 3. Print the player's hand and the randomly generated score for the computer 4. Evaluate and print the winner. Title Card Game Simulation using Stack and Deck Description Create a program that simulates a $5.00
$5.00

Cart totals

Subtotal $25.00
Total $25.00

You may be interested in…

Free Worldwide shipping

On all orders above $50

Easy 30 days returns

30 days money back guarantee

International Warranty

Offered in the country of usage

100% Secure Checkout

PayPal / MasterCard / Visa