You set up a concession stand on a beach which goes all around an island. Two ot
ID: 3635953 • Letter: Y
Question
You set up a concession stand on a beach which goes all around an island. Two other people set up their own competing concession stands. There are twelve places to set up around the island like the numbers on a clock. Anyone making a purchase goes to the nearest concession stand.In this kind of a situation, you're likely to make more money if you manage to be farther away from the other two vendors. But you can't change your position during the day. Also, when you decide where to set up your stand, you don't know where the other two vendors are planning to set up their stands.
How much you earn during a day depends on the distances between you and the other two vendors. So, to simulate the action, you use some rules:
If all the concession stands are located at different spots, then your earning for the day is your distance to the person clockwise you plus the distance to the person counterclockwise you, measured in spots.
For example, if Alice sets up at 3 o’clock location, Bob sets up at the 10 o’clock location, and Carol sets up at 6 o’clock, then first we arrange them clockwise from 1 o’clock (Alice, Carol, then Bob): there are 3 spots clockwise between Alice and Carol, 4 spots clockwise between Carol and Bob, and 5 spots clockwise between Bob and Alice. Therefore, Alice gets $8, Bob gets $9, and Carol gets $7.
If all the concession stands are located at the same spot, everybody gets $8.
If exactly two concession stands are located at the same spot, the two collected stands get $6 each and the loner gets $12.
The total amount earned by all three vendors is $24, no matter how the three vendors position themselves.
When you simulate this action, you set up stands several days in a row. Each concession stand moves from one day to the next. So every night you pick a location around the island where you'll post your concession stand the next day. This goes on for d number of days and at the end, you tally up your earnings.
I'm looking for help how to approach this project. I'm not really sure where to start. My professor said we needed to use recursion to simulate the scenario. I'm not looking for a coded answer just some adive on how to organize this in clases and how to approach the simulation problem. Thanks.
Explanation / Answer
Well when you said classes, I thought that you may be using java. Not that I'll post any code by heres the gist of what I think you should do, well there's a few wasy of approaching this, but here's one: Stand class: -In this class you'll have variables that will hold the info of the current location and total earnings -The class will have a double array of "d" elements, which will be specified during object instantiation (in the constructor) -The double array will hold the value of earnings each day -A method that will update total earnings as each day progresses. -And of course getter and setter methods, the basic ones as well as having the ability to return the earnings for one specific day (or over a span of days) In the setter method where the earnings for one day is assigned, it should also call the update total earnings method Your main class: -an array of "stands" (the class defined above) -An int variable day counter -A method that will take each "location" value for each "stand" in the array and compare (for each person). This way, you can check through the rules, and if the rules are followed, then you can do your distance subtraction to find the earnings. Otherwise, if lets say your location comparison returns two or more on the same location, then earnings for that day will be assigned as specified in the rules -Keep a loop to run the above method for each day specified (by user input) the number of days "d" -A method that will loop through each element in the array and print out the total earnings -A main method that will run, and because it seems the location for each day is not hardcoded, have user input the info as each day progresses (or all at once). The example I gave you is the non-recursive way. You can modify this "semi pseudocode" to implement the recursive way. Instead of looping for each day, remove the each day earnings total, and call calculate method and return the total for that day + a call to its self with new locations, for example: if your function is calculate(int locA, int locB, int locC){ //blah blah blah, code to calculate days earnings for each person //Ask for new locations newLocA, newLocB, newLocC return(answer + calculate(newLocA, newLocB, newLocC)) } Hope that helps!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.