Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. public String print(char poly) {
  2. Point couple = new Point();int count=0;
  3. String sol=new String();int n=0;
  4. if(poly=='A'){
  5. n = A.size();}
  6. else if(poly=='B'){
  7. n = B.size();}
  8. else if(poly=='C'){
  9. n = C.size();}
  10. else if(poly=='R'){
  11. n = R.size();}
  12. else
  13. {
  14. throw new RuntimeException ("You entered a wrong letter");
  15. }
  16. if(n==0)
  17. {
  18. String ans=new String();
  19. ans="(0,0)";
  20. return ans;
  21. }
  22. Point[] ans=new Point[n];
  23. if (poly == 'A') {
  24. for(int i=0;i<ans.length;i++){
  25. ans[i]=(Point)A.get(i);
  26. }
  27. }
  28. else if(poly=='B'){
  29. for(int i=0;i<ans.length;i++){
  30. ans[i]=(Point)B.get(i);
  31. }
  32. }
  33. else if(poly=='C'){
  34. for(int i=0;i<ans.length;i++){
  35. ans[i]=(Point)C.get(i);
  36. }
  37. }
  38. else if(poly=='R'){
  39. for(int i=0;i<ans.length;i++){
  40. ans[i]=(Point)R.get(i);
  41. }
  42. }
  43. for(int i=0;i<ans.length;i++){
  44. for(int j=i+1;j<ans.length;j++){
  45. if(ans[i].getY()<ans[j].getY()){
  46. Point test=new Point();
  47. test=ans[i];
  48. ans[i]=ans[j];
  49. ans[j]=test;
  50. }
  51. }
  52. }
  53. for(int i=0;i<ans.length;i++) {
  54. if(ans[i].x==0)
  55. continue;
  56. if(ans.length==1){
  57. if(ans[i].y==0){
  58. sol+=ans[i].x;
  59. }else{
  60. if(ans[i].x==1){
  61. if(ans[i].y==1){
  62. sol+="x";
  63. }else{
  64. sol+="x^";
  65. sol+=ans[i].y;
  66. }
  67. }else{
  68. if (ans[i].x == -1) sol += "-";
  69. else {
  70. sol += ans[i].x;
  71. sol += "x";
  72. }
  73. }
  74. return sol;
  75. }
  76. if(count==0){
  77. if(ans[i].y==0){
  78. sol+=ans[i].x;
  79. }else{
  80. if(ans[i].x==1){
  81. if(ans[i].y==1){
  82. sol+="x";
  83. }else{
  84. sol+="x^";
  85. sol+=ans[i].y;
  86. }
  87. }else {
  88. if (ans[i].y == 1) {
  89. if (ans[i].x == -1) sol += "-";
  90. else {
  91. sol += ans[i].x;
  92. sol += "x";
  93. }
  94. } else {
  95. if (ans[i].x == -1) {
  96. sol += "-";
  97. sol += "x^";
  98. sol += ans[i].y;
  99. } else {
  100. sol += ans[i].x;
  101. sol += "x^";
  102. sol += ans[i].y;
  103. }
  104. }
  105. }
  106. }
  107. }
  108. else{
  109. if (ans[i].y == 0){
  110. if (ans[i].x > 0){
  111. sol+="+";
  112. sol+=ans[i].x;
  113. }
  114. else{
  115. sol+=ans[i].x;}
  116. }
  117. else {
  118. if (ans[i].x > 0) {
  119. sol+="+";
  120. if(ans[i].x!=1)
  121. sol+=ans[i].x;
  122. if(ans[i].y==1)sol+="x";
  123. else {sol+="x^";
  124. sol+=ans[i].y;}
  125. } else {
  126. if(ans[i].x==-1)sol+="-";
  127. else sol+=ans[i].x;
  128. if(ans[i].y==1)sol+="x";
  129. else {sol+="x^";
  130. sol+=ans[i].y;}
  131. }
  132. }
  133. }
  134. count++;
  135.  
  136. }
  137. return sol;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement