Plain text version | Style: Default, Black and White, Bath

University of Bath Logo
Dr Marina De Vos
Department of Computer Science
Tuesday, 20-Nov-2018 19:20:33 GMT

Programming I (CM10134 - CM50147): Lab 8

You will need to show all your code for the following exercises. It is still a good idea to read through the chapters in BlueJ and try out some of the exercises in there. However, these will no longer be checked.

  • Continuation of Shapes hierarchy
    Note: This should run from the command line.
    1. Add a 'number of sides’ field to your Shape, Triangle and Rectangle classes, and include the necessary accessor methods. Explain why these three classes only have been chosen to contain this additional coding?
    2. Update your toString methods so they also print the number of sides of each shape created.
    3. Add a print statement to the constructor of your shape class that prints out the details of the shape objects as they are created. What do you notice at runtime? Why does this occur?
    4. What happens if you remove the accessor method for number of sides from the shape class (the toString method of the shape class should still call this method as the subclasses still have this method). Explain what happens and why.
    5. Remove the number of sides accessor methods from each of the subclasses and make sure that the toString method in each class calls the variable for number of sides as defined in the Shape cass. What one thing can you change to make this compile? Explain.

  • LAN simulation
    Note: This should run from the command line.
    1. Here is some of the code for the Node, Workstation and Printserver classes of the LAN Simulation discussed in Lecture 8. Please complete the simulation as explained on the last three slides of the lecture handout.
    2. Create a Workstation "Bill Gates", PrintServer("Apple"), Nodes "A","B", "C" and a Fileserver "silicon". Connect together in a LAN. A send the following Packets on the LAN:
      • Destination: "Silicon" Content "windows"
      • Destination: "Apple" Content "Mac"
      • Destination: "A" Content "B"
      • Destination: "D" Content "wrong"
    3. Extend your simulation with two Subclasses of Packet: AscciPacket and Postscript Packet. When creating an AscciPacket the contents will be altered by adding the string length and "ascii" to the front of the string (e.g. "contents" becomes ascci8contents). For postscriptPackets we alter the content by adding '@@' after each character.
    4. Expand your simulation futher with an asciiPrintserver and a postscriptServer. An ascciPrintserver should only be capable of handling ascciPackets. The postscriptPrintserver can handle both. Make sure that both printers display the original contents of your package.
    5. Write a driver program demonstrating the full functionality of your code.