Advertisement
Guest User

Untitled

a guest
May 5th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. public class Train {
  2. private int number;
  3. private String type;
  4. private int wagons;
  5.  
  6. public int getNumber() {
  7. return number;
  8. }
  9.  
  10. public void setNumber(int number) {
  11. this.number = number;
  12. }
  13.  
  14. public String getType() {
  15. return type;
  16. }
  17.  
  18. public void setType(String type) {
  19. this.type = type;
  20. }
  21.  
  22. public int getWagons() {
  23. return wagons;
  24. }
  25.  
  26. public void setWagons(int wagons) {
  27. this.wagons = wagons;
  28. }
  29.  
  30. @Override
  31. public boolean equals(Object obj) {
  32. Train otherTrain = (Train) obj;
  33. boolean equal = false;
  34. if (otherTrain.getNumber() == this.getNumber()) {
  35. equal = true;
  36. }
  37. return equal;
  38. }
  39.  
  40. public class TrainsDAO {
  41. private Set<Train> trainSet = new HashSet<Train>();
  42.  
  43. public Set<Train> pupulateTheSet() {
  44. Random random = new Random();
  45.  
  46. for (int i = 1; i < 1000; i++) {
  47. Train train = new Train();
  48. train.setNumber(random.nextInt(10));
  49. train.setWagons(random.nextInt(30));
  50. train.setType("Inter-city");
  51. trainSet.add(train);
  52. }
  53. return trainSet;
  54. }
  55.  
  56. public static void main(String[] args) {
  57. TrainsDAO trainsDAO = new TrainsDAO();
  58. Set<Train> trains = trainsDAO.pupulateTheSet();
  59. for (Train train : trains) {
  60. System.out.println(train);
  61. }
  62. }
  63. }
  64.  
  65. public class TrainTest extends TestCase {
  66.  
  67. private TrainsDAO trainsDAO = new TrainsDAO();
  68. private Set<Train> trainSet = trainsDAO.pupulateTheSet();
  69. public TrainTest(String name) {
  70. super(name);
  71. }
  72.  
  73. @Override
  74. protected void setUp() throws Exception {
  75. super.setUp();
  76. }
  77.  
  78. @Test
  79. public void testIfThereAreEqualValuesInSet() {
  80. assertTrue(!duplicateFound());
  81. }
  82.  
  83. private boolean duplicateFound() {
  84. //check if there are duplicates in the set return true if there are no false otherwise
  85. return false;
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement