CSCI 1933 Project 1 Due Date: February 15th, 2021 1 Introduction Welcome to the first CSCI 1933 project! All students are expected to understand the rules listed below. While some rules may seem unforgiving, all guidelines are made to help the TAs grade efficiently and fairly. As a result, we will generally not make exceptions. Rules listed in the syllabus also apply but may not be listed here. 1.1 Submission Project 1 is due on February 15th, 2020 at 11:55pm CST on Canvas. Submit a zip or tar archive on Canvas containing all your .java files and your README. You are allowed to change or modify your submission, so submit early and often, and verify that all your .java files are in the submission. Failure to submit the correct files will result in a score of zero for all missing parts. Late submissions will be penalized in accordance with the syllabus. Make sure to include a README.txt in your submission that contains the following information: • Group members’ names and x500s • Contributions of each partner (if working with a partner) • How to compile and run your program • Any assumptions • Additional features that you implemented (if applicable) • Any known bugs or defects in the program • Any outside sources (aside from course resources) consulted for ideas used in the project, in the format: – idea1: source – idea2: source – idea3: source There is a five-point reduction if no README is included in your submission. 1.2 Working with a partner As discussed in lecture, you may work with one partner to complete this assignment (max team size = 2). If you choose to work as a team, please only turn in one copy of your assignment. Include both of your names and x500s in a comment at the top of each file you submit. In doing 1 CSCI 1933 PROJECT 1 1. INTRODUCTION so, you are attesting to the fact that both of you have contributed substantially to completion of the project and that both of you understand all code that has been implemented. 1.3 Identification Include your name and x500 in a comment in all files you submit, even when not working with a partner. Example: // Written by Christopher Dovolis, dovol002 1.4 Questions Questions related to the project can be discussed on Piazza or on Discord in abstract. Such questions might relate to programming in Java, understanding the writeup and topics covered in lectures and labs. Do not post any code or solutions, and do not e-mail the TAs with your questions when they can be asked on Piazza or Discord. 1.5 Grading Grading will be done by the TAs, so please address grading problems to the TA who graded your project privately. 1.6 Code You must use the exact class and method signatures we ask for, as we use a program to evaluate your code. Code that doesn’t compile will receive a significant penalty. Code should be able to run on the CSE Labs computers. 1.7 Project Overview Project 1 will involve implementing several shape classes in Java and using a drawing class we have implemented for you to create some graphics, including a fractal based on your shapes. Classes you need to create (more information in Section 2): • Circle.java • Rectangle.java • Triangle.java Classes you need to edit (more information in Section 3): • FractalDrawer.java Classes given to you (no need to edit): 2 CSCI 1933 PROJECT 1 2. SHAPE CLASSES (57 POINTS) • Canvas.java 2 Shape Classes (57 points) You should design classes for three different shapes (triangle, square, and circle) with the specifi- cations listed below. These classes are to be used by the main program (the class with the “main” method), and passed to the Canvas class for drawing. Thus, they must use standard class names and method names in order to work correctly. We will leave class attributes up to you. Looking at the values that can be set is a good place to start. 2.1 Circle Class Methods • Constructor Input: x position (double), y position (double), radius (double); Output: object of type Circle • calculatePerimeter Input: none Output: perimeter of the circle (type double) • calculateArea Input: none Output: area of the circle (type double) • setColor Input: color of the shape (type Color) Output: none (void) • setPos Input: x, y position of the center (both doubles) Output: none (void) • setRadius Input: radius (double) Output: none (void) • getColor Input: none Output: color of the shape (type Color) • getXPos Input: none 3 CSCI 1933 PROJECT 1 2. SHAPE CLASSES (57 POINTS) Output: x position of the center (double) • getYPos Input: none Output: y position of the center (double) • getRadius Input: none Output: radius (double) 2.2 Triangle Class Methods Hint: You can assume the triangles we want to draw are isosceles triangles. • Constructor Input: x position of bottom left corner (double), y position of bottom left corner (double), width (double), height (double) Output: object of type Triangle • calculatePerimeter Input: none Output: perimeter of the triangle (type double) • calculateArea Input: none Output: area of the triangle (double) • setColor Input: color of the shape (type Color) Output: none • setPos Input: x, y position of bottom left corner (both doubles) Output: none • setHeight Input: height (double) Output: none • setWidth Input: width (double) Output: none • getColor Input: none Output: color of the shape (type Color) 4 CSCI 1933 PROJECT 1 2. SHAPE CLASSES (57 POINTS) • getXPos Input: none Output: x position of the bottom left corner (double) • getYPos Input: none Output: y position of the bottom left corner (double) • getHeight Input: none Output: height (double) • getWidth Input: none Output: width (double) 2.3 Rectangle Class Methods • Constructor Input: x position of bottom left corner (double), y position of bottom left corner (double), width (double), height (double) Output: object of type Rectangle • calculatePerimeter Input: none Output: perimeter of the rectangle (type double) • calculateArea Input: none Output: area of the rectangle (double) • setColor Input: color of the shape (type Color) Output: none • setPos Input: x, y position of bottom left corner (both doubles) Output: none • setHeight Input: height (double) Output: none • setWidth Input: width (double) Output: none • getColor Input: none Output: color of the shape (type Color) 5 CSCI 1933 PROJECT 1 2. SHAPE CLASSES (57 POINTS) • getXPos Input: none Output: x position of the bottom left corner (double) • getYPos Input: none Output: y position of the bottom left corner (double) • getHeight Input: none Output: height (double) • getWidth Input: none Output: width (double) 6 CSCI 1933 PROJECT 1 3. FRACTAL DRAWER CLASS (38 POINTS) 3 Fractal Drawer Class (38 points) For this part of the project, you will write a Java program that uses your shape classes to draw a fractal. Fractals are geometric patterns that repeat on themselves at smaller and smaller scales. They have been studied for centuries because of their interesting mathematical properties and often appear in natural objects (e.g. snow flakes, plants). You can read more about fractals and their history here. Consider the example on the next page, which illustrates the process of constructing a fractal composed of triangles at several steps in the process. Notice that at each step, triangles of increasingly smaller sizes are drawn at the three points of each existing triangle. More examples of fractals can be found in Section 5. To help you with the drawing, we’ve already implemented a Canvas class that supports all of the drawing capability you need. You should look at the code if you’re interested, but all you’ll need to know is how you can interact with Canvas objects. Here are the method specifications of the Canvas class: • Canvas() (default constructor): creates drawing of default size • Canvas(int height, int width): creates drawing of specified width and height • void drawShape(Circle circleObj) • void drawShape(Rectangle rectangleObj) • void drawShape(Triangle triangleObj) 7 CSCI 1933 PROJECT 1 4. GRADING INFORMATION Each of the drawing methods will draw the shape you pass it in the specified location and in the specified color. Here’s an example of how you might use the Canvas class to draw a single blue circle: Canvas drawing = new Canvas(800,800); Circle myCircle = new Circle(0,0,100); myCircle.setColor(Color.BLUE); drawing.drawShape(myCircle); You will be responsible for filling in the FractalDrawer class. For full credit, your program should have the following features: • ask the user for input (choices: “circle”, “triangle”, or “rectangle”) and use the corresponding shape as the base shape of your fractal • draw a pattern that repeats on itself at least 7 times and uses a new color in each repetition (feel free to be creative - you can cycle colors or choose colors at random, as long as overlapping shapes are distinct from one another) • draw at least four shapes per layer for rectangles and circles and at least three per layer for triangles (e.g. draw the new shapes on all three points or sides of a triangle, or on four opposite sides of a circle - again, feel free to be creative) • compute the total area of all shapes that form your fractal and print the result to the screen after your program is finished drawing Note that to receive full credit, your program will need to be able to draw a fractal for all three possible inputs (circle, triangle, or rectangle). We suggest that the most convenient implementation is to simply implement three different methods, one that draws a circle fractal, one that draws and triangle fractal, and one that draws a rectangle fractal. If nothing appears on the canvas when you run your program, try resizing the canvas window. 4 Grading Information Your program will be graded according to the following score breakdown: • Style: 5 • Shape Classes: 57 • Fractal Drawer Class: 38 8 CSCI 1933 PROJECT 1 5. FRACTAL EXAMPLES 5 Fractal Examples Here are some examples of fractals for all three shapes, if you want some inspiration. Your fractal patterns do not have to match these; feel free to come up with your own patterns, as long as they meet the basic requirements listed in section 3! 9 CSCI 1933 PROJECT 1 5. FRACTAL EXAMPLES 10
欢迎咨询51作业君