This site requires JavaScript, please enable it in your browser!
Greenfoot back
Linniah
Linniah wrote ...

2015/6/9

HELP

Linniah Linniah

2015/6/9

#
Can someone help me w/ this question that my teacher gave me to solve?? I don't get the question!! Problem Description Those tiny music machines that play your digital music are really computers that keep track of and play music files. The CCC music player (C3MP) is currently in development and will be hitting the stores soon! In this problem, you have to simulate a C3MP. The C3MP music player will hold 5 songs in memory, whose titles will always be “A”, “B”, “C”, “D” and “E”. The C3MP also keeps track of a playlist, which is an ordering of all the songs. The C 3MP has 4 buttons that the user will press to rearrange the playlist and play the songs. Initially, the C3MP playist is “A, B, C, D, E”. The 4 control buttons do the following: • Button 1: move the first song of the playlist to the end of the playlist. For example: “A, B, C, D, E” will change to “B, C, D, E, A”. • Button 2: move the last song of the playlist to the start of the playlist. For example, “A, B, C, D, E” will change to “E, A, B, C, D”. • Button 3: swap the first two songs of the playlist. For example, “A, B, C, D, E” will change to “B, A, C, D, E”. • Button 4: stop rearranging songs and output the playlist. You need to write a program to simulate a CCC music player. Your program should repeatedly ask for two positive integers b and n. Here b represents the button number that the user wants to press, 1 ≤ b ≤ 4, and n represents the number of times that the user wants to press button b. You can assume that n always satisfies 1 ≤ n ≤ 10. The input will always finish with the pair of inputs (b = 4, n = 1) when this happens, you should print the order of songs in the current playlist and your program should end. You can assume that the user will only ever press button 4 once. Sample session (user input in italics) Explanation (initial playlist is “A, B, C, D, E”) Button number: 2 Number of presses: 1 (b = 2, n = 1 so “A, B, C, D, E” changed to “E, A, B, C, D”) Button number: 3 Number of presses: 1 (b = 3, n = 1, so “E, A, B, C, D” changed to “A, E, B, C, D”) Button number: 2 Number of presses: 3 (b = 2, n = 3, so “A, E, B, C, D” changed to “B, C, D, A, E”) Button number: 4 Number of presses: 1 (b = 4, n = 1) When this happens, you should output the playlist. Output for Sample Input Session B C D A E and here is what i've start it
static String playlist = "A B C D E"
public static String Shuffle(int b, int n)
{
       if(n==0)
        return "";
}
else 
  return 
and im stuck...pls help
davmac davmac

2015/6/9

#
I don't get the question!!
Which part don't you get? I'd start by thinking about the variables you need and their types. When the question says:
The C3MP music player will hold 5 songs in memory, whose titles will always be “A”, “B”, “C”, “D” and “E”. The C3MP also keeps track of a playlist, which is an ordering of all the songs.
... it is telling you what your program needs to keep track of. By my understanding, you don't need to have any actual songs (because your simulator is not required to actually play music) - you just need an ordered collection of 5 song names (which are strings). Think about what that means (in your current code, you've only got one string, which lists the song names in sequence. That could work, if you manipulate the string in order to change the track order; but there are easier and better ways to handle multiple data items in an ordered collection). Once you have declared your variables, go on with writing the code. I'd start with:
Your program should repeatedly ask for two positive integers b and n.
Once you can do that, work on the rest of the requirements.
plant plant

2015/6/10

#
Maybe look up how to make an array in greenfoot?
Linniah Linniah

2015/6/10

#
I'm currently in grade 11 so my teacher don't want 11s to use array that's for 12
danpost danpost

2015/6/11

#
Linniah wrote...
I'm currently in grade 11 so my teacher don't want 11s to use array that's for 12
A string is, in essense, also an array (an array of characters). So, I would guess you will have to use something like char type fields for the five "titles" and perform all the operations long-hand.
lordhershey lordhershey

2015/6/11

#
Since you cannot use array, I suspect you would have the string packed like this:
String Songs="ABCDE";
You can move the A to the End doing this:
Songs = Songs.substring(1) + Songs.substring(0, 1);
and you can Move the E to the front doing this
Songs = Songs.substring(Songs.length()-1) + Songs.substring(0,Songs.length()-1);
This will work for strings of length 1 and greater. Using this you can probably figure out how to do the swap on the front of the list.
You need to login to post a reply.