Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.Scanner;
  4. import java.util.ArrayList;
  5.  
  6. public class CharacterSorter {
  7. public static ArrayList<Character> characterList = new ArrayList<Character>();
  8.  
  9. public static void main(String[] args){
  10.  
  11. System.out.println("Welcome to Character Sorter Program");
  12. System.out.println("Please input a string to be sorted");
  13.  
  14. Scanner scanner = new Scanner(System.in);
  15. String character = scanner.nextLine();
  16.  
  17. boolean exit = false;
  18. while (!exit) {
  19. System.out.println("Please select the option you would like to see");
  20. System.out.println("");
  21. System.out.println("1. Display character frequencies alphabetically");
  22. System.out.println("2. Display sorted frequencies");
  23. System.out.println("3. Show types of character frequencies");
  24. System.out.println("4. Exit");
  25.  
  26. int select = scanner.nextInt();
  27. if (select > 4 && select < 0){
  28. System.out.println("Error, bad input, please enter a number 1-4");
  29. }
  30. if (select == 1){
  31. alphabeticalSort();
  32. }
  33. if (select == 2){
  34. frequencySort();
  35. }
  36. if (select == 3){
  37. charTypes();
  38. }
  39. if (select == 4){
  40. System.out.println("Character Sorter Exited Successfully");
  41. exit = true;
  42. }
  43. }
  44. }
  45. public static void alphabeticalSort(String string) {
  46. for(Character c: string.toCharArray()){
  47. characterList.add(c);
  48. }
  49. Collections.sort(characterList);
  50. characterList.forEach(c->System.out.print(c));
  51. }
  52.  
  53. // characterList.add(character);
  54. public static void frequencySort(){
  55.  
  56. }
  57. public static void charTypes(){
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement