Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.Comparator;
  4. import java.util.Scanner;
  5.  
  6. public class Part2 {
  7.  
  8.  
  9.  
  10.  
  11.  
  12. public enum mod_ranks{
  13. TRIAL_MODERATOR("Trial Mod",2,"pink"), GLOBAL_MODERATOR("Global mod",4,"bright pink"),SUPER_MODERATOR("Super Mod",1,"blue"),ADMINISTRATOR("Admin",1,"red");
  14.  
  15. String color, title;
  16. int population;
  17.  
  18. public String getTitle(){
  19. return title;
  20. }
  21.  
  22. mod_ranks(String title, int population, String color){
  23. this.title =title;
  24. this.population = population;
  25. this.color = color;
  26. }
  27.  
  28. @Override
  29. public String toString(){
  30. return title + " rank" + "," + population + " people " + color + " color";
  31. }
  32.  
  33. }
  34.  
  35.  
  36. public static void printRank(){
  37.  
  38. Scanner s = new Scanner(System.in);
  39. System.out.println("Write a moderator title");
  40.  
  41. String input = s.nextLine();
  42. mod_ranks rank = null;
  43.  
  44. for(mod_ranks m: mod_ranks.values()){
  45. if(m.getTitle().contains(input)){
  46. rank = m;
  47. }
  48. }
  49.  
  50. if(rank!=null){
  51. System.out.println(rank);
  52. }else{
  53. System.out.println("That rank does not exist");
  54. }
  55.  
  56. s.close();
  57. }
  58.  
  59. public static class Result implements Comparable<Result> {
  60. int result;
  61. public Result(int r){
  62. result = r;
  63. }
  64.  
  65. public String toString(){
  66. return ""+result;
  67. }
  68.  
  69. public int getInt() {
  70. return result;
  71. }
  72.  
  73. @Override
  74. public int compareTo(Result result) {
  75. if(result.getInt()==this.result){
  76. return 0;
  77. }else if(result.getInt()>this.result){
  78. return -1;
  79. }else{
  80. return 1;
  81. }
  82. }
  83. }
  84.  
  85. public static abstract class Operation{
  86. private int p1,p2;
  87. private Result result;
  88. abstract void performEquation();
  89. abstract Result getResult();
  90.  
  91. public Operation(int p1, int p2){
  92. this.p1 = p1;
  93. this.p2 = p2;
  94. }
  95.  
  96. public Operation(Result r, int p2){
  97. this.p1 = r.getInt();
  98. this.p2 = p2;
  99. }
  100.  
  101. }
  102.  
  103. public static class Minus extends Operation{
  104.  
  105. public Minus(int p1,int p2){
  106. super(p1,p2);
  107. }
  108.  
  109. public Minus(Result r, int p2){
  110. super(r,p2);
  111. }
  112.  
  113. @Override
  114. void performEquation() {
  115. super.result = new Result(super.p1-super.p2);
  116. }
  117.  
  118. @Override
  119. Result getResult() {
  120. return super.result;
  121. }
  122. }
  123.  
  124. public static class Divide extends Operation{
  125.  
  126. public Divide(int p1,int p2){
  127. super(p1,p2);
  128. }
  129.  
  130. public Divide(Result r, int p2){
  131. super(r,p2);
  132. }
  133.  
  134. @Override
  135. void performEquation() {
  136. super.result = new Result(super.p1/super.p2);
  137. }
  138.  
  139. @Override
  140. Result getResult() {
  141. return super.result;
  142. }
  143.  
  144. }
  145.  
  146. public static class Multiply extends Operation{
  147.  
  148. public Multiply (int p1,int p2){
  149. super(p1,p2);
  150. }
  151.  
  152. public Multiply(Result r, int p2){
  153. super(r,p2);
  154. }
  155.  
  156. @Override
  157. void performEquation() {
  158. super.result = new Result(super.p1*super.p2);
  159. }
  160.  
  161. @Override
  162. Result getResult() {
  163. return super.result;
  164. }
  165. }
  166.  
  167. public static class Plus extends Operation{
  168.  
  169. public Plus (int p1,int p2){
  170. super(p1,p2);
  171. }
  172.  
  173. public Plus(Result r, int p2){
  174. super(r,p2);
  175. }
  176.  
  177. @Override
  178. void performEquation() {
  179. super.result = new Result(super.p1+super.p2);
  180. }
  181.  
  182. @Override
  183. Result getResult() {
  184. return super.result;
  185. }
  186. }
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193. public static void main(String[] args){
  194. printRank();
  195.  
  196. ArrayList<Result> results = new ArrayList<>();
  197.  
  198. results.add(new Result(5));
  199. results.add(new Result(4));
  200. results.add(new Result(9));
  201.  
  202. Object[] arr = results.toArray();
  203. Arrays.sort(arr);
  204.  
  205. System.out.println(Arrays.toString(arr));
  206. }
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement