Hi There!

I'm Dan Schlegel, an Associate Professor in the Computer Science Department at SUNY Oswego

Programming Challenge 3: Shapes World Problem Solving

Overview

Your task is to write four separate Java programs for this assignment, all in the context of the NPW. Special notes for these programs:

  1. All of the programs will make use of the shapes functionality of the NPW world, but not the painter functionality.
  2. Unlike most programs that you will write this semester, you are required to place all of your executable code for each program in this assignment within just one method – the main method. (There will be no infrastructure for painting in these programs, hence no paintTheImage or similar method.) This is not only because the solutions to the given problems will be relatively short, but also because we will want to reflect more upon the creation and use of objects in these programs than on the structure of the programs.
  3. The use of arithmetic operators to directly compute areas or perimeters of shapes, diagonals of squares or rectangles, diameters of circles, is strictly prohibited. Thus, you must create and use shapes in order to compute such values.
  4. It is required that you name each number that you use in the program, other that small integers whose meanings will be readily apparent to even the most casual of readers.

Why do it?

By completing this computational problem solving assignment you will:

  1. Demonstrate the ability to make use of the problem solving strategy of problem decomposition.
  2. Demonstrate the ability to make use of the problem solving strategy of imaginative construction.
  3. Gain considerable practice in the creation and use of “objects to think with”.
  4. Gain significant experience with infrastructural elements of the language, with types and variables and expressions, in particular.

The Entrance

Lab 4 should be viewed as an important element of preparation for this assignment, so you want to be sure to have completed that lab prior to starting this assignment. You should also study the functionality associated with simple shapes in Appendix 1 of your Laboratory Manual.

Problem 1: The Messy Desk

Consider a messy desk after a late night of studying for a CSC212 exam, covered in plates, cans, a lab manual, and some notebooks. The brown wooden desk measures 30in deep and 72in wide. On top of the desk are two notebooks, each of size 6x8in, and a lab manual of size 10×13.5in There are also two square white coasters upon which sit empty soda cans. The cans have a radius of 1.325in and perfectly inscribe the coasters. Finally there are six smallish 6in diameter plates which previously held snacks of strawberry cream pie (since 9/28 is National Strawberry Cream Pie Day) spread around the desk. None of the objects on the desk lie atop any others (except for the cans upon the coasters).

Write a program called WorkSpace in a package called shapes to display the area of the desk which is not obscured by any object and may still be used for studying. In doing so, you are required to write your program in a manner that is more or less consistent with the following guidelines:

  1. Introduce a variable for each of the given measurements, and bind these variables to the measurements. Be sure to choose meaningful variable names. And be sure to refer to the values by means of the variables in the rest of your program.
  2. Create six “objects to think with” from the NPW, one for the desk, one for a book, one for the lab manual, one for a plate, one for a can, and one for a coaster. Of course, you don’t merely want to create them, you want to introduce variables for each, and appropriately bind the variables to the objects. Constraint: Do not use an explicit constructor to construct the coaster. Rather, informally speaking, ask the can to produce the coaster.
  3. Introduce a variable and bind it to the collective area of the objects on the desk.
  4. Introduce a variable and bind it to the result – the area of the desk not obscured by the objects which sit on top of it.
  5. Display the result to the standard output stream, being sure to give it a label.

Problem 2: The L-Shaped Deck

You would like to build an L-shaped deck, as roughly illustrated below. You will build your deck out of standard 5.5″ wide pressure treated decking. You calculated that you would need 15 twelve-foot boards and 19 eight foot boards. You will lay the boards with some gap in between each one. You would now like to calculate how much total area exists between the boards for drainage.

Write a Java program called DrainageArea in the shapes package which computes the total area left for drainage after nailing down the deck boards. In doing so:

  1. Name the values that serve to define the particular problem instance (those related to board size and deck size in this case).
  2. Model objects that can be used to solve the problem in a fairly natural way (two rectangular sections of the deck, and the two sizes of board, in this case).
  3. Strive to present a simple expression of a solution which is grounded in sound problem solving strategies (problem decomposition, in this case).
  4. Clearly, meaningfully, label the program output.

Problem 3: Colorful Tablecloth

Write a Java program called BlackSpace in the shapes package to compute the area of the black space in the below image of a tablecloth.

The side length of the tablecloth is 800mm. The edge of the blue circle is exactly 40mm from the midpoints of the sides of the black square. The interior green square is inscribed in the blue circle. The edge of the interior circle is exactly 30mm from the midpoint of the sides of the green square.

In writing this program, you are required to proceed in a manner that is more or less consistent with the following guidelines:

  1. Name the values that serve to define the particular problem instance (edge length and distances from corner/circle to midpoint in this case).
  2. Make use of the problem solving strategy of imaginative construction by mentally overlaying some number of circles on the image that can be exploited in the service of solving this problem. In fact, you should really draw them on the image provided.
  3. Model objects that can be used to solve the problem in a fairly natural way – the tablecloth, the green diamond, the blue circle, and the interior black circle. In doing so, bring to bear computational manifestations of your imaginative constructions.
  4. Strive to present a simple expression of the solution which is grounded in the problem solving strategy of problem decomposition.
  5. Clearly, meaningfully, label the program output.

Problem 4: The Shipping Container

You’re interested in the longest object you can shove in a shipping container diagonally from the bottom in one corner to the top in another corner. Write a Java program called ShippingContainer in the shapes package to compute the distance from one corner of a rectangular shipping container on the floor (bottom) to its far corner on the ceiling (top). By rectangular shipping container I simply mean a container with rectangular walls, floor, and ceiling. Use a prompt and scanner to ask the user for three integer dimensions for the container – a width, length, and a height. Do this in a manner that is more or less consistent with the following guidelines:

  1. Draw a nice diagram of the shipping container.
  2. Do your best to add a sketch of a “curtain” to the container which divides the container diagonally. Refer to this curtain as the “key” to solving this problem.
  3. Introduce a variable for each dimension of the container, bound to values read from the user via the standard input stream.
  4. Think about this: How can the key be used to help solve the problem?
  5. Think about this: What are the dimensions of the key?
  6. Think about this: How can you create the key?
  7. Introduce a variable called face and bind it to a rectangle that can be used to get the nonobvious dimension of the key.
  8. Introduce a variable called key and bind it to a rectangle that represents the key.
  9. Introduce a variable called distance and bind it to the distance of interest, the distance between two far corners of the container.
  10. Display the result, being sure to label it.

Due Date and Reminders

  1. Due date: Tuesday, October 11, 2022
  2. Once you are ready, you must demo your programs for one of the TAs.
  3. You must post your work, a source program and a standard output stream demo for each problem, to your Web Work Site. You will not receive any credit from the TAs until your work is posted on your Web Site!