Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. public class figury
  2. {
  3. public enum czworokat
  4. {
  5. KWADRAT(1,1,1,1,1),
  6. PROSTOKAT(1,1,1,1,1),
  7. ROMB(1,1,1,1,1);
  8.  
  9.  
  10. private Double bok1;
  11. private Double bok2;
  12. private Double bok3;
  13. private Double bok4;
  14. private Double kat;
  15.  
  16.  
  17. czworokat(double a,double b,double c,double d, double k)
  18. {
  19. this.bok1 = a;
  20. this.bok2 = b;
  21. this.bok3 = c;
  22. this.bok4 = d;
  23. this.kat = k;
  24. }
  25. public void zmienwartosc(double a,double b,double c,double d, double k)
  26. {
  27. this.bok1 = a;
  28. this.bok2 = b;
  29. this.bok3 = c;
  30. this.bok4 = d;
  31. this.kat = k;
  32. }
  33. public double ObliczPole()
  34. {
  35. switch (this)
  36. {
  37. case KWADRAT:
  38. return 0;
  39. case PROSTOKAT:
  40. return 1;
  41. case ROMB:
  42. return 2;
  43. default:
  44. return 3;
  45. }
  46. }
  47. }
  48.  
  49. public enum jeden
  50. {
  51. OKRAG(1),
  52. SZESCIOKAT(1),
  53. PIECIOKAT(1);
  54.  
  55. private Double bok1;
  56.  
  57. jeden(double a)
  58. {
  59. this.bok1 = a;
  60. }
  61.  
  62. public void zmienwartosc(double a)
  63. {
  64. this.bok1 = a;
  65. }
  66.  
  67. public double ObliczPole()
  68. {
  69. switch (this)
  70. {
  71. case OKRAG:
  72. return 0;
  73. case SZESCIOKAT:
  74. return 1;
  75. case PIECIOKAT:
  76. return 2;
  77. default:
  78. return 3;
  79. }
  80. }
  81. }
  82.  
  83. public static void main(String[] args)
  84. {
  85. try
  86. {
  87. int r=args[0].length();
  88. }
  89. catch (ArrayIndexOutOfBoundsException e)
  90. {
  91. System.out.println("Podaj paramety");
  92. return;
  93. }
  94. int index = 1;
  95. int length = args[0].length();
  96. figury tab[] = new figury[length];
  97. for(int l = 0; l < length;l++)
  98. {
  99. char temporary = args[0].charAt(l);
  100. if((temporary!='c') && (temporary!='o') && (temporary!='p') && (temporary!='s'))
  101. {
  102. return;
  103. }
  104. if(temporary=='o')
  105. {
  106. tab[l]=figury.jeden.OKRAG;
  107. tab[l].zmienwartosc(Double.parseDouble(args[index]));
  108. index++;
  109. } else if (temporary == 'c')
  110. {
  111. if(Double.parseDouble(args[index])<0 || Double.parseDouble(args[index+1])<0 || Double.parseDouble(args[index+2])<0 || Double.parseDouble(args[index+3])<0 || Double.parseDouble(args[index+4])<0)
  112. {
  113. System.out.println("bledne paramety");
  114. return;
  115. }
  116. if(Double.parseDouble(args[index+4])==90)
  117. {
  118. if(Double.parseDouble(args[index])==Double.parseDouble(args[index+1]) && Double.parseDouble(args[index])==Double.parseDouble(args[index+2]) && Double.parseDouble(args[index])==Double.parseDouble(args[index+3]))
  119. {
  120. tab[l]=figury.czworokat.KWADRAT;
  121. tab[l].zmienwartosc(Double.parseDouble(args[index]),Double.parseDouble(args[index+1]),Double.parseDouble(args[index+2]),Double.parseDouble(args[index+3]),Double.parseDouble(args[index+4]));
  122. index=index+5;
  123. }
  124. if(Double.parseDouble(args[index])==Double.parseDouble(args[index+1]) &&Double.parseDouble(args[index+2])==Double.parseDouble(args[index+3])&&Double.parseDouble(args[index+1]) != Double.parseDouble(args[index+2]))
  125. {
  126. tab[l]=figury.czworokat.PROSTOKAT;
  127. tab[l].zmienwartosc(Double.parseDouble(args[index]),Double.parseDouble(args[index+1]),Double.parseDouble(args[index+2]),Double.parseDouble(args[index+3]),Double.parseDouble(args[index+4]));
  128. index=index+5;
  129. }
  130. else
  131. {
  132. tab[l]=figury.czworokat.ROMB;
  133. tab[l].zmienwartosc(Double.parseDouble(args[index]),Double.parseDouble(args[index+1]),Double.parseDouble(args[index+2]),Double.parseDouble(args[index+3]),Double.parseDouble(args[index+4])); }
  134. index=index+5;
  135. }
  136. else if (temporary == 'p')
  137. {
  138. tab[l]=figury.jeden.PIECIOKAT;
  139. tab[l].zmienwartosc(Double.parseDouble(args[index]));
  140. index++;
  141. }
  142. else {
  143. tab[l]=figury.czworokat.SZESCIOKAT;
  144. tab[l].zmienwartosc(Double.parseDouble(args[index]));
  145. index++;
  146. }
  147. }
  148. for(int j = 0;j < tab.length; j++)
  149. {
  150. try
  151. {
  152. System.out.println((tab[j]).ObliczPole());
  153. }
  154. catch(NullPointerException e)
  155. {
  156. System.out.println("Brak Figury " +(j+1));
  157. }
  158. try
  159. {
  160. System.out.println((tab[j]).ObliczPole());
  161. }
  162. catch(NullPointerException e)
  163. {
  164. System.out.println("Brak Figury " +(j+1));
  165. }
  166. }
  167. }
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement