Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package ai3halko;
  7.  
  8. import java.util.Random;
  9.  
  10. /**
  11. *
  12. * @author johny
  13. */
  14. public class Osobnik {
  15. private char[] data = null;
  16. private int score = 0;
  17.  
  18. public Osobnik(int rozmiar) {
  19. this.data = new char[rozmiar];
  20. Random rng = new Random();
  21.  
  22. for(int i = 0; i < rozmiar; i++) {
  23. // data[i] = (char)(i + 65);
  24. // data[rozmiar - 1] = '.';
  25. // data[rozmiar - 2] = ' ';
  26. int rand = rng.nextInt(28);
  27. if(rand == 27)
  28. data[i] = '.';
  29. else if(rand == 26)
  30. data[i] = ' ';
  31. else
  32. data[i] = (char)(rand + 65);
  33. } //constructor
  34. }
  35. public char[] getData() {
  36. return this.data;
  37. }
  38.  
  39. public char getDataAt(int i) {
  40. return this.data[i];
  41. }
  42.  
  43. @Override
  44. public String toString() {
  45. String ret = new String(data);
  46. ret += " " + score;
  47. return ret;
  48. }
  49.  
  50. public void setData(char[] toSet) {
  51. this.data = toSet;
  52. }
  53. public void setDataAt(char toSet, int i) {
  54. this.data[i] = toSet;
  55. }
  56.  
  57. public int getScore() {
  58. return this.score;
  59. }
  60.  
  61. public void setScore(int score) {
  62. this.score = score;
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement