1 / 44

Scale Mutator Program

Scale Mutator Program. Array Manipulation. FunNotesSHELL.java. Each scale is an array of integers Representing pitch for each note in the scale Write methods to mutate the scales into a more interesting order: Reversed Scrambled (randomized) Shuffled Sorted

ballentine
Télécharger la présentation

Scale Mutator Program

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Scale Mutator Program Array Manipulation

  2. FunNotesSHELL.java • Each scale is an array of integers • Representing pitch for each note in the scale • Write methods to mutate the scales into a more interesting order: • Reversed • Scrambled (randomized) • Shuffled • Sorted • Sequenced (as sets of triads)

  3. Methods to Write • void swap(int[] list, int a, int b) • void selSort(int[] list) selSort describes a Selection Sort. Look them up in the book. We will dig into the details later.

  4. int[] scramble(int[]list) • Given an array of ints called list, return a new array of the same size and data but with the order of the data randomized. • Easy ideas?

  5. int[] scramble(int[]list) • Given an array of ints called list, return a new array of the same size and data but with the order of the data randomized. • Easy ideas? • You have a swap method that will swap the values at two indexes. • Pick two random indexes from the array and swap them. Repeat 10,000 times.

  6. int[] scramble(int[]list) • Given an array of ints called list, return a new array of the same size and data but with the order of the data randomized. • Another idea: • Pick a random element from list that is not -1 • Store that element in the next available index of an answer array • Replace the element in list with -1 • Repeat until the answer array is full

  7. int[] scramble(int[]list) list r ansi

  8. int[] scramble(int[]list) list r ansi

  9. int[] scramble(int[]list) list r ansi

  10. int[] scramble(int[]list) list r ansi

  11. int[] scramble(int[]list) list r ansi

  12. int[] scramble(int[]list) list r ansi

  13. int[] scramble(int[]list) list r ansi

  14. int[] scramble(int[]list) list r ansi

  15. int[] scramble(int[]list) list r ansi

  16. int[] reverse(int[]list) • Given an array of ints called list, return a new array of the same size and data but with the order of the data reversed. • Easy ideas?

  17. int[] reverse(int[]list) • Given an array of ints called list, return a new array of the same size and data but with the order of the data reversed. • Easy ideas? • Traverse through list from the last index to the first, copying each element into increasing indexes of the return array.

  18. int[] makePalindrome(int[]list) • Given an array of ints called list, return a new array almost twice the size with all of the elements in order followed by all the elements in reverse order. • The last element of list should not appear twice. int [] list = {1,2,3,4}; int [] list2 = makePalindrome(list); //list2 should contain 1,2,3,4,3,2,1 Easy ideas?

  19. int[] makePalindrome(int[]list) • Given an array of ints called list, return a new array almost twice the size with all of the elements in order followed by all the elements in reverse order. • The last element of list should not appear twice. int [] list = {1,2,3,4}; int [] list2 = makePalindrome(list); //list2 should contain 1,2,3,4,3,2,1 Easy ideas? You already have a reverse method. Why not use it?

  20. int[] shuffle(int[]list) • Given an array of ints called list, return a new array of the same size, in the order of 1stelem, last element, 2nd element, 2nd to last element, 3rd element, 3rd to last element, etc. int [] list = {1,2,3,4,5,6,7,8}; int [] list2 = shuffle(list); //list2 should contain 1,8,2,7,3,6,4,5 Easy ideas?

  21. int[] shuffle(int[]list) list a b ansi

  22. int[] shuffle(int[]list) list a b ansi

  23. int[] shuffle(int[]list) list a b ansi

  24. int[] shuffle(int[]list) list a b ansi

  25. int[] shuffle(int[]list) list a b ansi

  26. int[] shuffle(int[]list) list a b ansi

  27. int[] shuffle(int[]list) list a b ansi

  28. int[] shuffle(int[]list) list a b ansi

  29. int[] shuffle(int[]list) list a b ansi

  30. int[] shuffle(int[]list) list a b ansi

  31. int[] shuffle(int[]list) list a b ansi

  32. int[] shuffle(int[]list) list a b ansi

  33. int[] shuffle(int[]list) list a b ansi

  34. int[] shuffle(int[]list) list ab ansi

  35. int[] shuffle(int[]list) list ab ansi

  36. int[] shuffle(int[]a, int[]b) • Given 2 arrays of ints called a and b, return a new array of all the combined elements of a and b, in the order of 1stelem from a, 1st element from b, 2nd element from a , 2nd element from b, 3rd element from a, 3rd element from b, etc. int [] list1 = {1,2,3,4}; int [] list2 = {5,6,7,8}; int [] list3 = shuffle(list1, list2); //list2 should contain 1,5,2,6,3,7,4,8

  37. int[] mixWithNote(int[] list, int note) • Given an array of ints called list, and a single value called note, return a new array of all the elements of list alternating with note: 1stelem from list, note, 2nd element from list, note, 3rd element from list , note, etc. int [] list1 = {1,2,3,4}; int [] list2 = mixWithNote(list1, 9); //list2 should contain 1,9,2,9,3,9,4,9

  38. int[] triads(int[] list) • Given an array of ints called list, return a new array of all the elements of list in groups of 3 consecutive elements: 1stelem from list, 2nd element from list, 3rd element from list , 2nd element from list, 3rd element from list, 4th element from list, 3rd element from list, 4th element from list, 5th element from list, etc. int [] list1 = {1,2,3,4,5,6}; int [] list2 = triads(list1); //list2 should contain 1,2,3,2,3,4,3,4,5,4,5,6 Given list1 is size n, how big should list2 be?

  39. int [] list1 = {1,2,3};//size int [] list2 = triads(list1); //1,2,3: size 3 int [] list1 = {1,2,3,4};//size 4 int [] list2 = triads(list1); //1,2,3,2,3,4: size 6 int [] list1 = {1,2,3,4,5};//size 5 int [] list2 = triads(list1); //1,2,3,2,3,4,3,4,5: size 9 int [] list1 = {1,2,3,4,5,6}; //size 6 int [] list2 = triads(list1);//1,2,3,2,3,4,3,4,5,4,5,6: size 12

  40. int[] triads(int[]list) list a ansi

  41. int[] triads(int[]list) list a ansi

  42. int[] triads(int[]list) list a ansi

  43. int[] triads(int[]list) list a ansi

  44. int[] triads(int[]list) list a ansi

More Related