943,769 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1275
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 28th, 2008
-1

help agaaaaain ???

Expand Post »
hello again every body ...


i tried 2solveit ,but there are some problem faced me .. and i'll insert what i did .>>>

This is the main class..the main problem in it how 2 print the array like the example which i show it 2 u ...


Java Syntax (Toggle Plain Text)
  1. import java.awt.DisplayMode;
  2. import java.util.Scanner;
  3.  
  4.  
  5.  
  6. public class mainClass {
  7.  
  8. private static String[][] Cell;
  9. final static String normal="white";
  10. final String abnormal="green";
  11. final static String temp="red";
  12.  
  13.  
  14. public static void main(String []args){
  15.  
  16. Scanner w = new Scanner(System.in);
  17. Cell c1 = new Cell();
  18. //please implement the main method
  19.  
  20. System.out.println("Please enter the size of the array: ");
  21. int size = w.nextInt();
  22.  
  23. displayArray();
  24.  
  25. c1.initializeColor(size);
  26.  
  27. System.out.print("Please enter the the cordinates to chek: ");
  28.  
  29. System.out.println("r: ");
  30. int x = w.nextInt();
  31.  
  32. System.out.println("c: ");
  33. int y = w.nextInt();
  34.  
  35. countCells( x, y);
  36.  
  37.  
  38.  
  39. }//end main
  40.  
  41.  
  42. /*
  43. *The method countCells is a RECURSIVE method whose job is to find
  44. *how many cells are in the same blob as a given cell (i.e cell with
  45. *specified coordinates x and y). The variable int size represents the
  46. *size of the two-dimensional array. This value would have been provided
  47. *by the user at the beginning of the main method.
  48. *Do NOT make any changes to the method declartion.
  49. */
  50.  
  51. public static int countCells( int x, int y){
  52. int count=0;
  53.  
  54. for(int x1=0; x1<Cell.length; x1++)
  55. for(int y1=0; y1<Cell.length; y1++){
  56. Cell[x][y]=normal;
  57. }
  58.  
  59. for(int x1=0; x1<Cell.length; x1++)
  60. for(int y1=0; y1<Cell.length; y1++){
  61. if(getblobsize(x,y, Cell) > 0)
  62. count++;
  63. }
  64. System.out.print("The number of blobs: " + count);
  65. return count;
  66.  
  67. }//countCells()
  68.  
  69.  
  70.  
  71.  
  72. private static int getblobsize(int r, int c, String Cell[][]) {
  73.  
  74. if(r<0 || r>=Cell.length || c<0 || c>=Cell.length){
  75. return 0;
  76. }
  77.  
  78. if(Cell[r][c] == temp || Cell[r][c] == normal){
  79. return 0;
  80. }
  81.  
  82. else{
  83. int time=1;
  84.  
  85. time += getblobsize( r - 1, c + 1, Cell);
  86. time += getblobsize( r, c + 1, Cell);
  87. time += getblobsize( r + 1, c + 1, Cell);
  88. time += getblobsize(r + 1, c, Cell);
  89. time += getblobsize( r + 1, c - 1, Cell);
  90. time += getblobsize( r, c - 1, Cell);
  91. time += getblobsize( r - 1, c - 1, Cell);
  92. time += getblobsize( r - 1, c, Cell);
  93. return time;
  94.  
  95. }
  96. }
  97.  
  98.  
  99.  
  100.  
  101. /*
  102. * The method diplayArray is provided for you to call when you want to
  103. * display your array on the screen. You should know how and when to
  104. * to use this method in your program by looking at its declaration and
  105. * the expected output.Do NOT make any changes to this method.
  106. */
  107.  
  108. public static void displayArray(Cell [][] ,int size){
  109. for(int i=0;i<size;i++){
  110. System.out.println();
  111. System.out.print("-");
  112. for(int j=0;j<size;j++){
  113. System.out.print("-+");
  114. }
  115. System.out.println();
  116. for (int j=0;j<size;j++){
  117. String color=cells[i][j].getColor();
  118. System.out.print("|"+color.charAt(0));
  119.  
  120. }
  121. System.out.print("|");
  122.  
  123. }//outer
  124. System.out.print("\n-");
  125. for(int j=0;j<size;j++){
  126. System.out.print("-+");
  127. }
  128. }//end displayArray()
  129.  
  130. }//end mainClass


This is the Cell class >>>>




Java Syntax (Toggle Plain Text)
  1. public class Cell implements Interface1{
  2.  
  3. private String color;
  4. final String normal="white";
  5. final String abnormal="green";
  6. final String temp="red";
  7. private int column;
  8. private int row;
  9.  
  10. /*Please implement this class. Remember this class
  11. * must implement all the methods declared in the interface
  12. * Interface1.
  13. */
  14.  
  15. /**
  16. * Method initializeColor will be used to initialize the color
  17. * of each cell in the two-dimensional array.
  18. * The cell can be one of two colors: "green" or "white". Whether
  19. * a cell will be "white" or "green" should be decided randomly.
  20. * Since the assignment specifies that there should be more normal
  21. * (white) cells than abnormal (green) cells, you should devise an
  22. * algorithm that assigns:
  23. * white: 70% of the time
  24. * green: 30% of the time
  25. * (hint:you can use Math.random() for this purpose)
  26. */
  27.  
  28. public void initializeColor(int size) {
  29. // TODO Auto-generated method stub
  30. Cell[][] Cell = new Cell[row][column];
  31. int d=(size*(70/100));
  32. int b=(size*(30/100));
  33. for (int size1 = 0; size1 < row; size1++){
  34. while(row <= d);{
  35. do([row] = setColor(normal);
  36. }
  37. }
  38. for (int size1 = 0; size1 < column; size1++) {
  39. while(column <= b);{
  40. do([column] = setColor(abnormal);
  41. }
  42. }
  43. }
  44.  
  45. public String getColor() {
  46. // TODO Auto-generated method stub
  47. return null;
  48. }
  49.  
  50. public void setColor(String color) {
  51. // TODO Auto-generated method stub
  52. this.normal;
  53. this.abnormal;
  54. }
  55.  
  56. public void initializeColor() {
  57. // TODO Auto-generated method stub
  58.  
  59. }
  60.  
  61.  
  62. }


And this is the interface <>>>>



Java Syntax (Toggle Plain Text)
  1. /**
  2. * Interface1 defines some constants and declares
  3. * some methods that must be implemented by the
  4. * class "Cell". The purpose of each method is
  5. * described below. Note the statement that says
  6. * public class Cell implements Interface1
  7. */
  8. public interface Interface1 {
  9. final String normal="white";
  10. final String abnormal="green";
  11. final String temp="red";
  12.  
  13. /**
  14. * Method initializeColor will be used to initialize the color
  15. * of each cell in the two-dimensional array.
  16. * The cell can be one of two colors: "green" or "white". Whether
  17. * a cell will be "white" or "green" should be decided randomly.
  18. * Since the assignment specifies that there should be more normal
  19. * (white) cells than abnormal (green) cells, you should devise an
  20. * algorithm that assigns:
  21. * white: 70% of the time
  22. * green: 30% of the time
  23. * (hint:you can use Math.random() for this purpose)
  24. */
  25. public void initializeColor();
  26.  
  27. /**
  28. * The method setColor is a typical setter method that
  29. * sets the color of a given cell to a certain color.
  30. * This method is needed especially to re-color a cell
  31. * to a temporary color (i.e "red")
  32. */
  33. public void setColor(String color);
  34.  
  35. /**
  36. * The method getColor will return the color of the
  37. * specified cell. This method is called to identify
  38. * the color of the cell.
  39. */
  40. public String getColor();
  41.  
  42. }




i need help ..
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
bahr_alhalak is offline Offline
53 posts
since Oct 2008
Oct 28th, 2008
0

Re: help agaaaaain ???

You are having problems calling displayArray from your main method?

I see you are creating one cell, how are you creating the rest?
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Oct 28th, 2008
0

Re: help agaaaaain ???

because we need only for one cell ..
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
bahr_alhalak is offline Offline
53 posts
since Oct 2008
Oct 28th, 2008
0

Re: help agaaaaain ???

Are you sure you are supposed to have an array of cells inside itself? or is that meant to be an int array?
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Oct 28th, 2008
0

Re: help agaaaaain ???

this is the file bellow .. download and explain what u understand my frind
Attached Files
File Type: pdf Assignment1.pdf (45.6 KB, 24 views)
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
bahr_alhalak is offline Offline
53 posts
since Oct 2008
Oct 28th, 2008
1

Re: help agaaaaain ???

In the instructions it states:

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 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;


Your cell implementation doesn't fit the instructions.

Take time and read before you start coding. This isn't the easiest problem in the world, nor hardest, but not one to go haphazardly into. Break it into steps. I see you are in Algorithms and Data Structures, and I'm sure they aren't teaching code first.
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Oct 28th, 2008
0

Re: help agaaaaain ???

my friend could u help me by give me the code of print array at least!!!
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
bahr_alhalak is offline Offline
53 posts
since Oct 2008
Oct 28th, 2008
0

Re: help agaaaaain ???

you already have to code to display the array

your comments for that method state
Do NOT make any changes to this method.

show me some effort that you can create an array on your own
if it doesn't work big deal, show us you have the effort for us to help
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Oct 28th, 2008
1

Re: help agaaaaain ???

this is the file bellow .. download and explain what u understand my frind
This (your existence on this site) must be some kind of a sociology experiment. If so, I guess the goal would be to figure out how much help you can receive from people while disregarding what they say, being annoying, and ignoring all of the rules for human social interaction.


Ask a specific question: this involves identifying some specific concept you do not fully understand and explaining what you do and don't understand about it, as well as your reasons (if any) for not understanding.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Oct 29th, 2008
1

Re: help agaaaaain ???

Quote originally posted by bahr_alhalak ...
i need help ..
yeah you do.. not necesarilly ours though.
if I read over this code you've posted, it seems that in the comments you can write flawless (or almost flawless) english, while in your posts, you only reach to the level of my 2-year old cousin's english, and he has never even heard english, let alone tried to speak/write it.

this gives me the idea that you did not write this code, this was given to you as your assignment, or as aid by someone who did you one huge favour.

stop trying to cheat your way through, and put some effort in it yourself.

Quote originally posted by dickersonka ...
you already have to code to display the array

your comments for that method state
Do NOT make any changes to this method.
this shows you haven't even read your assignment, so, why should we?
Reputation Points: 919
Solved Threads: 355
Nearly a Posting Maven
stultuske is offline Offline
2,487 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: list
Next Thread in Java Forum Timeline: GUI problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC