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 maple desk measures 32in deep and 60in wide. On top of the desk are two notebooks, each of size 6x9in, and a lab manual of size 10×13.5in There are also three square white coasters upon which sit empty Mountain Dew cans. The cans have a diameter of 2.6in and perfectly inscribe the coasters. Finally there are four smallish 6.5in diameter plates which previously held snacks of peanut butter toast (since 3/1 is National Peanut Butter Lover’s 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: Domino White Space

A standard domino is a rectangle which measures 2 1/2″ long, and 1 1/4″ wide. Each pip (dot) on a domino has diameter of 1/4″. A standard set of dominos has 28 pieces, each with a varying number of pips, ranging from none at all to 12 as in the below image.

Write a Java program called DominoWhiteSpace in the shapes package which computes the total area in an entire set of dominos not covered by one of the pips. In doing so:

  1. Name the values that serve to define the particular problem instance (those related to domino size and pip size in this case).
  2. Model objects that can be used to solve the problem in a fairly natural way.
  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 Tapestry

Write a Java program called GreenSpace in the shapes package to compute the area of the green space in the below image of a tapestry.

The side length of the tapestry is 750mm. The edge of the blue circle is exactly 35mm 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 40mm 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 tapestry, 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, March 21, 2023
  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 may not demo until your work is posted on your Web Site!