Java - Data structures and algorithms
import java.util.*;
public class MatchingGame
{
private ArrayList<Integer>
theNumbers;
final int MAX_NUMBER_OF_SHUFFLES = 5;
final int MIN_NUMBER = 10;
final int MAX_NUMBER = 99;
public MatchingGame(int numberAmount)
{
this.theNumbers = new
ArrayList<>();
initializeList(numberAmount);
}
/**
* Initialize the list with the count of
random 2 digit numbers.
*
*/
private void initializeList(int
numberAmount)
{
Random generator = new
Random();
ListIterator<Integer> iter =
this.theNumbers.listIterator();
// STEP 1
// generate the numbers
and add them to theNumbers using iterator
while
(iter.hasNext())
{
}
}
/**
* See whether two numbers are
removable.
* @param first the first 2 digit integer
value
* @param second the second 2 digit integer
value
* @return true if the first and second
match
*/
private boolean removablePair(Integer first,
Integer second)
{
// STEP3
// implement this
method
return false;
}
/**
* Implements one pass when called by play
method
* Scans over the list and removes any
pairs of values that are removable.
* @return true if any pair of integers was
removed
*/
private boolean scanAndRemovePairs()
{
boolean removedAPair =
false;
ListIterator<Integer> scan =
this.theNumbers.listIterator();
Integer first =
null;
Integer second =
null;
// STEP4
// implement the
method
// this method calls
helper method removablePair to see if there is a match
return
removedAPair;
}
private void displayTheNumbers()
{
// STEP2
// using an instance of
Iterator display the content of theNumbers
// notify the user if
the list is empty
}
public void play()
{
int pass = 0;
int numberOfShuffles =
0;
boolean repeat;
System.out.println("Starting with: ");
displayTheNumbers();
do
{
repeat = false;
while (scanAndRemovePairs())
{
pass++;
System.out.println("The list after pass #" + pass);
displayTheNumbers();
}
System.out.println("No more pairs to remove.");
// do we have at least 3 numbers in the list?
if (this.theNumbers.size() > 2)
{
if (numberOfShuffles < MAX_NUMBER_OF_SHUFFLES)
{
numberOfShuffles++;
System.out.println("Shuffling the numbers.");
Collections.shuffle(this.theNumbers);
System.out.println("The list after shuffling #" +
numberOfShuffles);
displayTheNumbers();
repeat = true;
}
}
}while(repeat);
if
(this.theNumbers.isEmpty())
{
System.out.println("\n*** Winner!!! ***");
}
else
{
System.out.println("\n*** Better luck next time! ***");
}
}
public static void main(String[] args)
{
final int
MIN_NUMBER_OF_ELEMENTS = 10;
Scanner scan = new
Scanner(System.in);
int numberAmount;
do
{
System.out.println("How many numbers (no less than " +
MIN_NUMBER_OF_ELEMENTS + ")?");
numberAmount = scan.nextInt();
}while(numberAmount <
MIN_NUMBER_OF_ELEMENTS);
MatchingGame game =
new MatchingGame(numberAmount);
game.play();
}
}
Java - Data structures and algorithms VI. Matching Game Consider a matching game in which you...
c++ PROGRAM DESCRIPTION: In this assignment, you will be creating a memory matching game in C++. In this game, the user will need to match up the pairs symbols A,B,C,D,E on a 4x4 array. For example, the array could be initialized like the following: In this case, X represents an empty slot. The goal is for the user to match the A to the A, the B to the B, etc, until all pairs are matched up to win the...
Project 2 – Memory Match Game Purpose This Windows Classic Desktop application plays a simple matching game. The game simulates a card game where the cards a placed face down and the player flips over pairs of cards in an attempt to find matching cards. Program Procedure Display a 4x4 grid of “face down” cards. Assign the letters A through H randomly to the cards in pairs. Allow the user to click on a card to “flip” it over and...
Problem #1: Consider the below matrix A, which you can copy and paste directly into Matlab. The matrix contains 3 columns. The first column consists of Test #1 marks, the second column is Test # 2 marks, and the third column is final exam marks for a large linear algebra course. Each row represents a particular student.A = [36 45 75 81 59 73 77 73 73 65 72 78 65 55 83 73 57 78 84 31 60 83...
java In this project you will implement a trivia game. It will ask random trivia questions, evaluate their answers and keep score. The project will also have an administrative module that will allow for managing the question bank. Question bank management will include adding new questions, deleting questions and displaying all of the questions, answers and point values. 2. The project can be a GUI or a menu based command line program. 3. Project details 1. Create a class to...
Written in Java Your job is to produce a program that sorts a list of numbers in ascending order. Your program will need to read-in, from a file, a list of integers – at which point you should allow the user an option to choose to sort the numbers in ascending order via one of the three Sorting algorithms that we have explored. Your program should use the concept of Polymorphism to provide this sorting feature. As output, you will...
Need help with a number guessing game in java 1) You should store prior guessses in a linked list, and the nodes in the list must follow the order of prior guesses. For example, if the prior guesses are 1000, 2111, 3222 in that order, the nodes must follow the same order 2) You should store the candidate numbers also in a linked list, and the nodes must follow the order of numbers (i.e. from the smallest to the largest)....
Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...
(2 bookmarks) In JAVA You have been asked to write a program that can manage candidates for an upcoming election. This program needs to allow the user to enter candidates and then record votes as they come in and then calculate results and determine the winner. This program will have three classes: Candidate, Results and ElectionApp Candidate Class: This class records the information for each candidate that is running for office. Instance variables: first name last name office they are...
2 A Game of UNO You are to develop an interactive game of UNO between a number of players. The gameplay for UNO is described at https://www.unorules.com/. Your program should operate as follows. 2.1 Setup 1. UNO cards are represented as variables of the following type: typedef struct card_s { char suit[7]; int value; char action[15]; struct card_s *pt; } card; You are allowed to add attributes to this definition, but not to remove any. You can represent colors by...
Write a Java program, In this project, you are going to build a max-heap using array representation. In particular, your program should: • Implement two methods of building a max-heap. o Using sequential insertions (its time complexity: ?(?????), by successively applying the regular add method). o Using the optimal method (its time complexity: ?(?), the “smart” way we learned in class). For both methods, your implementations need to keep track of how many swaps (swapping parent and child) are required...