عرض كامل الموضوع : مطلوب تكملة لغة برمجة الجافا ادخل ضروري اليوم

فتى الاحلام
31-10-2008, 09:27 AM
In this assignment you are required to write a java program that takes as an input a twodimensional
array whose elements represent cells of certain colors. A cell could be one of two
different colors only: either green or white. The color “green” will be used to indicate an
abnormal cell, whereas “white” will indicate a normal cell. There should be more normal cells
than abnormal ones. The task of the program is to find the number of abnormal cells that are in
the same continuous area as a given cell (i.e cell whose coordinates will be specified). Your
program should implement a recursive method to achieve this task. This problem is similar to
the “blob” example we gave you in Lecture 3. Please note that along with this document, you
are provided with three files. That is, you will not have to build your program from scratch;
instead you will need to complete the given program.
Sample output:
The following is a sample output of what you are expected to achieve. Your program must
behave exactly the same.
(Run 1)


(Run 2)


As you can see from the above two runs, the user will be asked to specify the size of the twodimensional
array. So if the user inputs the value (5), then the array should be of the size [5][5].
The array will then be displayed showing the color of each cell (“g” for green and “w” for
white). The code for drawing the array is provided in one of the given files. However, before
you can display the array, of course you have to initialize its elements. The elements of the
array are instances of the class “Cell” which is included as one of the three files. This class must
have one data field only:
private String color;
It must also implement the interface “Interface1” which provides all the constants needed and
the signatures of the methods that must be implemented by the “Cell” class.
In order to get a better understanding of the assignment requirements, please explore the files
provided and read the comments which describe what each method and constant value is used
for. Please feel free to ask for clarifications.
1- You are not allowed to change anything in the interface “Interface1” such
as changing the name of a constant or adding more methods.
2- You are not allowed to create more files than what you are already
provided. So submit only three files.
3- This assignment is to be done individually. Copying the whole or part of
someone else’s code will be considered cheating and will receive an
academic penalty.
4- Write your name and student ID in all files at the top of each file.
5- Your work will be evaluated based on the following criteria:
a- Correctness. Your code compiles and runs without any problems and it
achieves the desired output.
b- Correct implementation of the recursive method countCells();
c- Correct implementation of all the methods declared in the interface
“Interface1”. The description of each of these methods is provided in
the code.
6- Overall style and comments. Your code should be easy to read and
understand and it should be well commented.
Make sure you test your program for all kinds of inputs. Testing usually
helps uncover many problems with your design.

وهذه الكودات تحتاج للتكمله
بليييييييييز ساعدوني

1-// mainClass.javaهذا اسم الملف

package assignment1;

import java.util.*;
public class mainClass {

public static void main(String []args){

//please implement the main method

}//end main

*The method countCells is a RECURSIVE method whose job is to find
*how many cells are in the same blob as a given cell (i.e cell with
*specified coordinates x and y). The variable int size represents the
*size of the two-dimensional array. This value would have been provided
*by the user at the beginning of the main method.
*Do NOT make any changes to the method declartion.
public static int countCells(Cell [][]cells,int x,int y,int size){

//please implement this method


* The method diplayArray is provided for you to call when you want to
* display your array on the screen. You should know how and when to
* to use this method in your program by looking at its declaration and
* the expected output.Do NOT make any changes to this method.
public static void displayArray(Cell [][]cells,int size){
for(int i=0;i<size;i++){
for(int j=0;j<size;j++){
for (int j=0;j<size;j++){
String color=cells[i][j].getColor();


for(int j=0;j<size;j++){
}//end displayArray()

}//end mainClass

//Cell.java هذا اسم الملف

package assignment1;
public class Cell implements Interface1{

private String color;
/*Please implement this class. Remember this class
* must implement all the methods declared in the interface
* Interface1.


package assignment1;
* Interface1 defines some constants and declares
* some methods that must be implemented by the
* class "Cell". The purpose of each method is
* described below. Note the statement that says
* public class Cell implements Interface1
public interface Interface1 {
final String normal="white";
final String abnormal="green";
final String temp="red";

* Method initializeColor will be used to initialize the color
* of each cell in the two-dimensional array.
* The cell can be one of two colors: "green" or "white". Whether
* a cell will be "white" or "green" should be decided randomly.
* Since the assignment specifies that there should be more normal
* (white) cells than abnormal (green) cells, you should devise an
* algorithm that assigns:
* white: 70% of the time
* green: 30% of the time
* (hint:you can use Math.random() for this purpose)
public void initializeColor();

* The method setColor is a typical setter method that
* sets the color of a given cell to a certain color.
* This method is needed especially to re-color a cell
* to a temporary color (i.e "red")
public void setColor(String color);

* The method getColor will return the color of the
* specified cell. This method is called to identify
* the color of the cell.
public String getColor();



ولكم جزيل الشكر والعرفان