Hi There!

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

Assignment 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 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, covered in plates, cups, and books. The brown wooden desk measures 24 inches deep and 36 inches wide. On top of the desk is two books, of standard 8.5×11 inch size. There are also three square white coasters upon which sit dirty drinking glasses. The glasses have a radius of 1.35 inches, and perfectly inscribe the coasters. Finally there are three dinner plates, of radius 8 inches, scattered on the desk. None of the objects on the desk lie atop any others (except for the cups upon the coasters).

Write a program called WorkArea 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 five “objects to think with” from the NPW, one for the desk, one for a book, one for a plate, one for a glass, 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 glass 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 Standard Die

Write a Java program called WhiteArea in the shapes package to compute the white area of a standard white die with black dots given that the edge length of the die is 0.75 inches and the diameter of each dot is one-eighth the edge length. When you write your program, please keep in mind that a good programmer will generally:

  1. Name the values that serve to define the particular problem instance (edge length and dot diameter, in this case).
  2. Model objects that can be used to solve the problem in a fairly natural way – die face and die dot, 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: Yellow Space

Write a Java program called YellowSpace in the shapes package to compute the area of the yellow space in the below image.

The side length of the big gray square is 400mm. The corners of the larger yellow diamond are exactly 60mm from the midpoints of the sides of the big gray square. The corners of the smaller gray square are exactly 30mm from the midpoints of the sides of the larger yellow diamond. The corners of the small yellow diamond are exactly 15mm from the midpoints of the sides of the smaller gray 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 distance from corner 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 of provided.
  3. Model objects that can be used to solve the problem in a fairly natural way – the large gray square, the large yellow diamond, the small gray square, and the small yellow diamond. 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: Thursday October 3, 2019
  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!