Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Yarmouk University

Faculty of Information Technology and Computer Science


Department of Computer Sciences
Fall Semester 2021/2022
CS 310 Advanced Programming (Programming in Java)
Instructor: Dr. Noor Aldeen Alawad, Email: nooraldeen@yu.edu.jo
19/12/2021 Midnight is the deadline of this assignment

General Guidelines When Writing Programs:


- Include the following comments at the top of your source codes
// -----------------------------------------------------
// Assignment (include number)
// Question: (include question/part number)
// Written by: (include your name and student ID)
// -----------------------------------------------------
- In a comment, give a general explanation of what your program does. As the programming
questions get more complex, the explanations will get lengthier.
- Include comments in your program describing the main steps in your program.
- Display a welcome message which includes your name.
- Display clear prompts for users when you are expecting the user to enter data from the
keyboard.
- All output should be displayed with clear messages and in an easy to read format.
- End your program with a closing message so that the user knows that the program has
terminated.
Part 1: Memory matching game
A common memory matching game played by young children is to start with a deck of cards that
contain identical pairs. For example, given six cards in the deck, two might be labeled 1, two
labeled 2, and two labeled 3. The cards are shuffled and placed face down on the table. A player
then selects two cards that are face down, turns them face up, and if the cards match, they are left
face up. If the two cards do not match, they are returned to their original face down position. The
game continues until all cards are face up.
Write a program that plays the memory matching game. Use 16 cards that are laid out in a 4 × 4
square and are labeled with pairs of numbers from 1 to 8. Your program should allow the player
to specify the cards that he or she would like to select through a coordinate system.
For example, in the following layout,

all of the face down cards are indicated by *. The pairs of 8 that are face up are at coordinates
(1,1) and (2,3). To hide the cards that have been temporarily placed face up, output a large
number of newlines to force the old board off the screen.
Hint: Use a 2D array for the arrangement of cards and another 2D array that indicates if a card is
face up or face down. Or, a more elegant solution is to create a single 2D array where each
element is an object that stores both the card’s value and face. Write a function that “shuffles” the
cards in the array by repeatedly selecting two cards at random and swapping them.
Part2: Delete repetitions in an array

Write a static method called deleteRepeats that has a partially filled array of characters as a
formal parameter and that deletes all repeated letters from the array. Because a partially filled
array requires two arguments, the method should actually have two formal parameters: an array
parameter and a formal parameter of type int that gives the number of array positions used. When
a letter is deleted, the remaining letters are moved one position to fill in the gap. This creates
empty positions at the end of the array so that less of the array is used. Because the formal
parameter is a partially filled array, a second formal parameter of type int should tell how many
array positions are filled. This second formal parameter cannot be changed by a Java method, so
have the method return the new value for this parameter.

For example, consider the following code:


char a[10];
a[0] = 'a';
a[1] = 'b';
a[2] = 'a';
a[3] = 'c';
int size = 4;
size = deleteRepeats(a, size);

After this code is executed, the value of a[0] is 'a' , the value of a[1] is 'b' , the value of a[2] is 'c' ,
and the value of size is 3 . (The value of a[3] is no longer of any concern, because the partially
filled array no longer uses this indexed variable.) You may assume that the partially filled array
contains only lowercase letters. Write a suitable test program for your method.

Submitting Assignment 1
- Zip together the source codes
- Naming convention for zip file: Create one zip file, containing all source files for your
assignment using the following naming convention:
The zip file should be called a#_studentID, where # is the number of the assignment
studentID is your student ID(s) number. For example, for the first assignment, student
2017901001 would submit a zip file named a1_2017901001.zip.
- Submit your zip file at: the course moodle (Yarmouk E-learning site) as Programming
Assignment and submission #1. Assignments submitted to the wrong directory would be
discarded and no replacement submission will be allowed.

Evaluation Criteria for Assignment 1 (10 points)


Comments/description of variables/description 1 point
of the steps in code/purpose of program
Indentation and readability of program 1 point
Format/clarity/completeness/accuracy of 3 points
output
Proper use of required Java 5 points
concepts/correctness of program

You might also like