CS 261 Lab D - Bead Necklaces

Due Wed Feb 12 at 9:00am

Overview

In this assignment, you will practice using the "node and reference" structure of a LinkedList to model a necklace made up of beads of different sizes and colors. You will write code to model and display this necklace as a kind of linked list of beads (kept in the proper order). For this program, you will need to create a Necklace class that is a linked list of Beads. Your necklace will need to keep Beads organized in order (following the palette's rainbow, with larger beads coming first). You should be able to add and remove Beads from the necklace while maintaining the order. An example screenshot is below:

This lab will be completed in pairs. Review the pair programming guidelines if you don't remember them!

Objectives

Necessary Files

You will need to download the copy of the zipped source files. and import them into Eclipse. These files include a NecklaceFrame.java class that will be used to display your necklace (though you will need to modify this class to draw the necklace), a Palette.java class to produce and display a pleasing set of possible colors for your beads, and a Tester.java that you can use to make sure your implementation works.

Details

  1. Read through the provided classes and make sure you're familiar with them. Note that they won't compile without the Bead and Necklace classes you need to create; you should make skeletons of these classes (with empty methods) so that everything can compile.
  2. You will need to make the following classes:
    • Bead This class represents a single bead a bead has a color and a size. You can provide a random color for a Bead using the Palette's static getRandomColor() method, and you should give Beads a random size between 10 and 30 (pixels). You will want accessors for each of these attributes (but probably don't need mutators). A Bead will also need a "hook" that another bead can be hung on (e.g., a pointer to the next bead in the necklace). Feel free to make the hook public for ease of coding.
      • Since you are going to need to keep your Beads in order, you are going to need some way to determine who comes first. The easiest way to do this is to have your Bead class implement Comparable<Bead> and write an appropriate compareTo() method. Should be sorted by color (you can use the Palette's getIndex(Color) method to order the colors), followed by size (with larger beads being first).
    • Necklace This is your primary class; a Necklace is in a way a singularly linked list of Beads. Thus your necklace should contain a pointer to the first bead (the head), as well as a size variable. Your necklace will need to support the following methods:
      • void addBead(Bead) which adds a bead to the necklace, placing the bead in the necklace following the appropriate order.
      • Bead removeBead(Color) removes a bead of the given color from the necklace. This can just be the first bead of that color (or the last bead of that color if you're feeling clever).
      • Bead getBead(int) which returns the bead at the appropriate index (useful for iterating and drawing the list).
      • int size() which deserves no further explanation.
      You are welcome to use the code that we wrote in class as a reference for this lab, though since we're not making a generic list some of the methods will differ. Be sure to think about the efficiency of your algorithms!
    • NecklaceFrame This class is provided for you, but you will need to complete the paintComponent(Graphics) method of the inner NecklacePanel class. There is a TODO comment and a large space where your code should be. Your code should iterate through the Necklace and draw each Bead on the panel. Remember to draw the hook (the connector) after each bead!
  3. You will also likely want to make your own NecklaceTester class (in addition to the provided class) in order to test bits of functionality as you add it. You can also modify or comment the provided Tester class, but that may be more effort than it's worth (the Tester also has a habit of not shutting down immediately, which can be irksome).
  4. Keep algorithmic efficiency in mind! We will be looking for efficiency in your code!
  5. Make sure to document all your classes. You do not need to write full Javadoc comments, but you should have at least a comment on each method explaining what it does, and plenty of inline comments explaining your process.
  6. Check and double-check that your classes work flawlessly before submitting them to the submission folder. Also be sure that your names are on the top of the file!
  7. Fill out the lab partner evaluation survey after you turn in your work!

Submitting

Submit the following files to the LabD submission folder on hedwig: Bead.java, Necklace.java, NecklaceFrame.java. Make sure you upload your work to the correct folder! The lab is due at the start of class on the day after the lab.

Remember to fill out your lab partner evaluation!

Extensions

Try to make the bead prettier. Can you draw specular highlights on them? Give them a "shape" so we can have square beads, circular beads, polygon beads? Or even load an image to represent the bead?

Grading

This assignment will be graded based on approximately the following criteria: