Back to Challenge Set 14

Code Challenge: Copy Machine

Difficulty  

divider

The Brief

What they asked for
My game keeps the top five scores in an array. Before each
round I want a backup, so if the round goes wrong I can put
the old scores back. Make the backup, change two scores the
way a round would, and show me both lists so I can see the
backup really is separate.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • Start with the scores in an array: 120, 95, 80, 60, 45. Change the first to 999 and the last to 0 after the backup is made.
  • Activity 1.23 told you how this goes wrong. int[] backup = scores; makes a second name for the same array, and its fix copied three elements by hand. That fix only worked for exactly three.
  • Your backup must work for an array of any length. new int[...] makes an empty array of the right size, and a loop fills it.
  • Show both lists after the change. If the backup shows 999, it is not a backup.

Sample Output

Sample Output
Scores: 999 95 80 60 0
Backup: 120 95 80 60 45

Verified in a real run. With int[] backup = scores; instead, both lines show 999 95 80 60 0.


Submit

Your requirements list and your program file, named cc-copy-machine.

Commence Challenge