Advertisement
Guest User

Workshop

a guest
Apr 26th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3. public class LagerProgramm {
  4. public static void main(String[] args) {
  5. //This stuff will come out of the excel file afterwards
  6. Object[][] int_workshops = {
  7. { "Springen", 4, 8 }, // min=4, max=8
  8. { "Tanzen", 2, 10},
  9. { "Lesen", 2, 10},
  10. { "Klettern", 5, 10},
  11. { "Fussball", 2, 10},
  12. { "Theater", 2, 10},
  13. { "Schwingen", 2, 10}
  14. };
  15.  
  16. //This stuff will come out of the excel file afterwards, part=participant
  17. int[][] int_teilnehmer = {
  18. /* part1 */ { 0,1,2}, //prio1=worshop[0]="Springen", prio2="Tanzen", prio3="Lesen"
  19. /* part2 */ { 0,1,2},
  20. { 5,1,2}, //prio1="Theater", ...
  21. { 0,1,2},
  22. { 5,4,2},
  23. { 4,6,2},
  24. { 3,1,2},
  25. { 2,1,3},
  26. { 5,1,6},
  27. { 1,2,5},
  28. { 2,3,4},
  29. { 2,6,3},
  30. { 4,1,2},
  31. { 3,1,4},
  32. };
  33.  
  34. //make an Array of Workshops
  35. Workshop[] workshops = new Workshop[ int_workshops.length ];
  36. for(int i=0; i<workshops.length; i++){
  37. workshops[i] = new Workshop(i, (String)(int_workshops[i][0]),(int)(int_workshops[i][1]),(int)(int_workshops[i][2]) );
  38. }
  39.  
  40.  
  41. //make Array of pariticipants, teilnehmer=participant german/english nothing related to the programm
  42. Teilnehmer[] teilnehmer = new Teilnehmer[int_teilnehmer.length];
  43. for(int i=0; i<int_teilnehmer.length; i++){
  44. teilnehmer[i] = new Teilnehmer(i, int_teilnehmer[i]);
  45. }
  46.  
  47.  
  48. System.out.println(Arrays.toString(workshops));
  49. System.out.println(Arrays.toString(teilnehmer));
  50.  
  51. //testing if value of participants is enough to fill all workshops, if not fill the ones with the smallest min value with
  52. //the participants wich chose the same workshop twice or didnt chose at all or wrote a funny name on the paper for registration
  53.  
  54.  
  55.  
  56. System.out.println("Programmende");
  57. }
  58. }
  59.  
  60. class Teilnehmer{
  61. int tnr;
  62. int[] favs; //favorits
  63.  
  64. public Teilnehmer(int tnr, int[] favs){
  65. this.tnr=tnr;
  66. for(int i=0; i<favs.length; i++)
  67. for(int j=i+1; j<favs.length; j++)
  68. if( favs[i]==favs[j] )
  69. throw new IllegalArgumentException("Duplikate bei Favoriten: TN="+this.tnr+ " favs="+Arrays.toString(favs));
  70. this.favs = new int[favs.length];
  71. for (int i = 0; i < favs.length; i++) {
  72. this.favs[i] = favs[i];
  73. }
  74. }
  75.  
  76. public String toString(){
  77. return "TN: " + tnr + " Favoriten: " + Arrays.toString( favs );
  78. }
  79. }
  80.  
  81. class Workshop{
  82. int wnr;
  83. String name;
  84. int min;
  85. int max;
  86. public Workshop(int wnr, String name, int min, int max){
  87. this.wnr=wnr;
  88. this.name= (name==null||name.length()==0)?("WS"+wnr):name;
  89. if(min>max)
  90. throw new IllegalArgumentException("Workshop Nr=" + wnr + " min="+min+" max="+max);
  91. this.min=min;
  92. this.max=max;
  93. }
  94. public String toString(){
  95. return name + "(" + min + "-" + max + ")";
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement