SE1021
Software Development II

This is an old version of this course, from Spring 2017. A newer version is available here.

I will provide a hard-copy of the Lab Checklist

In this class, you will write a program for managing the parts needed to assemble a machine. Your program will provide a complete bill of materials including both the weight and cost for each part.

To facilitate a wide variety of parts, your program should make use of a generic "Part" interface. This interface will allow generic information about a part to be accessed:

  • The part's name
  • The total cost of the part
  • The total weight of the part
  • The bill of materials for a part

There are a few kinds of parts that the system supports: (1) Nuts (2) Bolts (3) SheetMetal (4) Duplicate parts and (5) Assemblies of parts. Nuts, bolts, and sheet-metal are basic parts. Duplicate parts and assemblies are built out of other pre-existing parts.

Lab 2 Milestone

The provided MachineDriver.java program includes an option fan which uses only the Duplicate and SheetMetal classes.

Write the Part interface, and the Duplicate and SheetMetal classes that implement this interface.

It is not necessary for the Lab 2 milestone for the Duplicate class to print out the bill of materials for any sub-Part. Simply printing the bill of materials for the dupicate alone is sufficient for the Lab 2 Milestone, as in the example output for the fan option below.

See the details for the Part and Duplicate classes below.

Details of main assignment

A class diagram for the program is shown in the figure below:

Implement all of the classes shown in the diagram above based on the discussion that follows. The arrows with black diamonds simply indicate that one class has a reference to another, as is already shown in the member variables of the class diagrams for Assembly and Duplicate Part.

A nut costs $0.50 * size, where size is the inner diameter of the nut in inches. A nut weights 0.01 lbs * size 2.

A bolt costs $1 * diameter * length, where diameter is the diameter of the threads in inches and length is the overall length of the bolt in inches. A bolt weighs 0.05 lbs * diameter2 * length.

Sheet metal costs $0.50 * thickenss * width * length, where each of the dimensions is measured in inches. Sheet metal weighs 0.1 lbs * thickness * width * length.

Bolts, nuts, and sheet-metal do not do anything when printBillOfMaterials is called.

A duplicate part represents count identical parts. Its cost and weight are both count times the cost and weight of the single part. However, if there are at least 5 identical parts, there is a 5% discount off the cost of the duplicate parts, and if there are at least 10 identical parts, there is instead a 10% discount off the cost of the duplicate parts. The duplicate part stores a single reference to another object describing just one of the identical parts.

When a duplicate part's printBillOfMaterials is called, it first prints the duplicate part's name on a title line. Then it prints the name, cost, and weight of the individual part, along with the number of copies of that part. It prints the total cost and weight for the duplicate part. (In the final version, it also prints out the full bill of materials for each sub-part.)

For example, the fan option in the program MachineDriver.java is a duplicate part consisting of five identical blades. When the printBillOfMaterials is called on the dupicate part, it prints:

Building a fan
==========================
5 8.0x6.0x0.0625 sheets
==========================
Duplicate part: 8.0x6.0x0.0625 sheet
Copies: 5
Individual cost: $1.50
Individual weight: 0.3 lbs

Total cost: $7.12
Total weight: 1.5 lbs

An assembly consists of multiple different parts. Both the cost and weight of the assembly are determined by adding the cost and weight of each part in the assembly. However, the assembly has an additional construction cost which is $0.25 per sub-part in the assembly. The Assembly maintains a List of all the parts that are stored in it.

A duplicate part or an assembly may be a sub-part of another part. For example, in cube option in the program MachineDriver.java, the cube consists of two parts: a set of metal sheets and several sets of nut-bolt pairs. The sheet-metal is actually a duplicate part, consisting of six identical pieces of sheet metal. The sets of nut-bolt pairs are also a duplicate part, consisting of 36 identical nut-bolt pairs. Each nut-bolt pair is an assembly, consisting of both a nut and a bolt. This hierarchy of parts is illustrated in the diagram below.

When a duplicate part or assembly prints the bill of materials, it first prints a summary of each part (including name, cost, and weight for each part), then prints the full bill of materials for each part.

For example, the bill of materials for the cube in MachineDriver.java should be printed something like this:

==========================
Cube
==========================
Part: 36 Nut-Bolt Pairs
Cost: $36.45
Weight: 0.247 lbs

Part: 6 12.0x12.0x0.25 sheets
Cost: $102.60
Weight: 21.6 lbs

Total cost: $139.55
Total weight: 21.848 lbs

==========================
36 Nut-Bolt Pairs
==========================
Duplicate part: Nut-Bolt Pair
Copies: 36
Individual cost: $1.12
Individual weight: 0.007 lbs

Total cost: $36.45
Total weight: 0.247 lbs

==========================
Nut-Bolt Pair
==========================
Part: 0.25x2.0 bolt
Cost: $0.50
Weight: 0.006 lbs

Part: 0.25 inch nut
Cost: $0.12
Weight: 0.001 lbs

Total cost: $1.12
Total weight: 0.007 lbs

==========================
6 12.0x12.0x0.25 sheets
==========================
Duplicate part: 12.0x12.0x0.25 sheet
Copies: 6
Individual cost: $18.00
Individual weight: 3.6 lbs

Total cost: $102.60
Total weight: 21.6 lbs

As shown in the example above, format numeric values cleanly. In particular, dollar amounts should always include two places after the decimal.

You may add new options to the example program, but do not edit the options provided in the example. Let the single printBillOfMaterials call print everything.

Appendix: Shovel option

As a final example, the shovel option in the example program produces an assembly consisting of three different parts.

==========================
Shovel
==========================
Part: 30.0x3.0x0.125 sheet
Cost: $5.62
Weight: 1.125 lbs

Part: 10.0x8.0x0.25 sheet
Cost: $10.00
Weight: 2 lbs

Part: 0.125x0.5 bolt
Cost: $0.06
Weight: 0 lbs

Total cost: $16.44
Total weight: 3.125 lbs

Submitting the Lab

Make sure that

  • all of the example code in MachineDriver.java is uncommmented and remove the TODO printouts. Don't make any changes to the provided code except to uncomment the methods and remove the "TODO" printouts.
  • your code compiles and works correctly.
  • your code is in a package with your username. For example, if your name is Phileas Fogg, your username might be foggp.

Go to the esubmit site to submit your lab. Go to the Lab2 upload assignment. Upload MachineDriver.java as the main class. Upload all of the other assignments as additinal Java files:

You may find that your output is slightly different from the output used by the webpage:

In this case, it makes more sense to use the singular ("Duplicate part:") since we are giving the name of one part, not all of them together. So we would want to edit our code and resubmit the lab. However, there may be other errors that don't make a difference. (For example, I wouldn't resubmit the code just because I had a different number of === signs.) If you are comfortable with the differences between the output, you do not need to resubmit your code.

If your code does not compile, or does not run at all on the website, please resubmit your code. These problems may indicate a serious problem with your submission. I may ask you to resubmit it anyway when I start grading, which could make your lab quite late. For example, if you see the message:

... this indicates that you have not uploaded any java files. (This could happen if you uploaded them in a zip file, for example.) Submit the files again, uploading all the java files one by one. Upload your main file first, as illustrated in the first screenshot above.

As a second example of case where you should always resubmit, if you see the message:

... this indicates that the main file you uploaded does not include a main function. Be sure to upload MachineDriver.java as the main class when you resubmit the lab. Don't make any changes to the provided code except to uncomment the methods and remove the "TODO" printouts.

In general, if you see this message:

... it means you should resubmit your files to ensure that you get credit for submitting the lab.