Step 1
Write a method that accepts a file name (String), an object name (String) and an Obj3D. If the Obj3D is a Sphere, Box, Cone or Cylinder
write out the commands from project 6 that will generate this object. For example
Obj3D aBox=new BoxObj();
aBox.setColor(Color.RED);
aBox.setScale(1,3,2);
aBox.setLocation(2,1,1);
aBox.rotX(90);
writeObj("myObjFile.txt", "redBox",aBox);
Might write the following to the file "myObjFile.txt"
box redBox
move redBox 2 1 1
scale redBox 1 3 2
rotx redBox 90
roty redBox 0
rotz redBox 0
You only need to account for the color, scale, location and rotation angles of the object. Any object other than a sphere, box, cone or cylinder should throw an exception and not write out anything.
Step 2
Add the command file to the command line code from project 6. This command will ask the user for a file name and will read commands from the file instead of from System.in. After reading all of the commands from the file and executing them as you did in project 6, you should again begin reading commands from the user through System.in. See the hints for how to ask the user for a file name. This should only read from .txt files. You can create .txt files either using the method from step 1 or using NotePad (in the Accessories folder for Starting programs).
Step 3
Add the command write objectName to the command line code from project 6. This will pop up a file dialog and ask the user where they want to write to. The named object will then be written out to the specified file (see helpful code below).
|