Browse Source

quiz corrected.

Jennifer Tinkler 6 years ago
parent
commit
c452ddba25

BIN
.DS_Store View File


+ 221
- 0
FirstLab-Shapes/Canvas.java View File

@@ -0,0 +1,221 @@
1
+import javax.swing.*;
2
+import java.awt.*;
3
+import java.util.List;
4
+import java.util.*;
5
+
6
+/**
7
+ * Canvas is a class to allow for simple graphical drawing on a canvas.
8
+ * This is a modification of the general purpose Canvas, specially made for
9
+ * the BlueJ "shapes" example. 
10
+ *
11
+ * @author: Bruce Quig
12
+ * @author: Michael Kölling (mik)
13
+ *
14
+ * @version: 1.6 (shapes)
15
+ */
16
+public class Canvas
17
+{
18
+    // Note: The implementation of this class (specifically the handling of
19
+    // shape identity and colors) is slightly more complex than necessary. This
20
+    // is done on purpose to keep the interface and instance fields of the
21
+    // shape objects in this project clean and simple for educational purposes.
22
+
23
+    private static Canvas canvasSingleton;
24
+
25
+    /**
26
+     * Factory method to get the canvas singleton object.
27
+     */
28
+    public static Canvas getCanvas()
29
+    {
30
+        if(canvasSingleton == null) {
31
+            canvasSingleton = new Canvas("BlueJ Shapes Demo", 300, 300, 
32
+                    Color.white);
33
+        }
34
+        canvasSingleton.setVisible(true);
35
+        return canvasSingleton;
36
+    }
37
+
38
+    //  ----- instance part -----
39
+
40
+    private JFrame frame;
41
+    private CanvasPane canvas;
42
+    private Graphics2D graphic;
43
+    private Color backgroundColour;
44
+    private Image canvasImage;
45
+    private List<Object> objects;
46
+    private HashMap<Object, ShapeDescription> shapes;
47
+    
48
+    /**
49
+     * Create a Canvas.
50
+     * @param title  title to appear in Canvas Frame
51
+     * @param width  the desired width for the canvas
52
+     * @param height  the desired height for the canvas
53
+     * @param bgClour  the desired background colour of the canvas
54
+     */
55
+    private Canvas(String title, int width, int height, Color bgColour)
56
+    {
57
+        frame = new JFrame();
58
+        canvas = new CanvasPane();
59
+        frame.setContentPane(canvas);
60
+        frame.setTitle(title);
61
+        canvas.setPreferredSize(new Dimension(width, height));
62
+        backgroundColour = bgColour;
63
+        frame.pack();
64
+        objects = new ArrayList<Object>();
65
+        shapes = new HashMap<Object, ShapeDescription>();
66
+    }
67
+
68
+    /**
69
+     * Set the canvas visibility and brings canvas to the front of screen
70
+     * when made visible. This method can also be used to bring an already
71
+     * visible canvas to the front of other windows.
72
+     * @param visible  boolean value representing the desired visibility of
73
+     * the canvas (true or false) 
74
+     */
75
+    public void setVisible(boolean visible)
76
+    {
77
+        if(graphic == null) {
78
+            // first time: instantiate the offscreen image and fill it with
79
+            // the background colour
80
+            Dimension size = canvas.getSize();
81
+            canvasImage = canvas.createImage(size.width, size.height);
82
+            graphic = (Graphics2D)canvasImage.getGraphics();
83
+            graphic.setColor(backgroundColour);
84
+            graphic.fillRect(0, 0, size.width, size.height);
85
+            graphic.setColor(Color.black);
86
+        }
87
+        frame.setVisible(visible);
88
+    }
89
+
90
+    /**
91
+     * Draw a given shape onto the canvas.
92
+     * @param  referenceObject  an object to define identity for this shape
93
+     * @param  color            the color of the shape
94
+     * @param  shape            the shape object to be drawn on the canvas
95
+     */
96
+     // Note: this is a slightly backwards way of maintaining the shape
97
+     // objects. It is carefully designed to keep the visible shape interfaces
98
+     // in this project clean and simple for educational purposes.
99
+    public void draw(Object referenceObject, String color, Shape shape)
100
+    {
101
+        objects.remove(referenceObject);   // just in case it was already there
102
+        objects.add(referenceObject);      // add at the end
103
+        shapes.put(referenceObject, new ShapeDescription(shape, color));
104
+        redraw();
105
+    }
106
+ 
107
+    /**
108
+     * Erase a given shape's from the screen.
109
+     * @param  referenceObject  the shape object to be erased 
110
+     */
111
+    public void erase(Object referenceObject)
112
+    {
113
+        objects.remove(referenceObject);   // just in case it was already there
114
+        shapes.remove(referenceObject);
115
+        redraw();
116
+    }
117
+
118
+    /**
119
+     * Set the foreground colour of the Canvas.
120
+     * @param  newColour   the new colour for the foreground of the Canvas 
121
+     */
122
+    public void setForegroundColor(String colorString)
123
+    {
124
+        if(colorString.equals("red"))
125
+            graphic.setColor(Color.red);
126
+        else if(colorString.equals("black"))
127
+            graphic.setColor(Color.black);
128
+        else if(colorString.equals("blue"))
129
+            graphic.setColor(Color.blue);
130
+        else if(colorString.equals("yellow"))
131
+            graphic.setColor(Color.yellow);
132
+        else if(colorString.equals("green"))
133
+            graphic.setColor(Color.green);
134
+        else if(colorString.equals("magenta"))
135
+            graphic.setColor(Color.magenta);
136
+        else if(colorString.equals("white"))
137
+            graphic.setColor(Color.white);
138
+        else
139
+            graphic.setColor(Color.black);
140
+    }
141
+
142
+    /**
143
+     * Wait for a specified number of milliseconds before finishing.
144
+     * This provides an easy way to specify a small delay which can be
145
+     * used when producing animations.
146
+     * @param  milliseconds  the number 
147
+     */
148
+    public void wait(int milliseconds)
149
+    {
150
+        try
151
+        {
152
+            Thread.sleep(milliseconds);
153
+        } 
154
+        catch (Exception e)
155
+        {
156
+            // ignoring exception at the moment
157
+        }
158
+    }
159
+
160
+    /**
161
+     * Redraw ell shapes currently on the Canvas.
162
+     */
163
+    private void redraw()
164
+    {
165
+        erase();
166
+        for(Iterator i=objects.iterator(); i.hasNext(); ) {
167
+            ((ShapeDescription)shapes.get(i.next())).draw(graphic);
168
+        }
169
+        canvas.repaint();
170
+    }
171
+       
172
+    /**
173
+     * Erase the whole canvas. (Does not repaint.)
174
+     */
175
+    private void erase()
176
+    {
177
+        Color original = graphic.getColor();
178
+        graphic.setColor(backgroundColour);
179
+        Dimension size = canvas.getSize();
180
+        graphic.fill(new Rectangle(0, 0, size.width, size.height));
181
+        graphic.setColor(original);
182
+    }
183
+
184
+
185
+    /************************************************************************
186
+     * Inner class CanvasPane - the actual canvas component contained in the
187
+     * Canvas frame. This is essentially a JPanel with added capability to
188
+     * refresh the image drawn on it.
189
+     */
190
+    private class CanvasPane extends JPanel
191
+    {
192
+        public void paint(Graphics g)
193
+        {
194
+            g.drawImage(canvasImage, 0, 0, null);
195
+        }
196
+    }
197
+    
198
+    /************************************************************************
199
+     * Inner class CanvasPane - the actual canvas component contained in the
200
+     * Canvas frame. This is essentially a JPanel with added capability to
201
+     * refresh the image drawn on it.
202
+     */
203
+    private class ShapeDescription
204
+    {
205
+        private Shape shape;
206
+        private String colorString;
207
+
208
+        public ShapeDescription(Shape shape, String color)
209
+        {
210
+            this.shape = shape;
211
+            colorString = color;
212
+        }
213
+
214
+        public void draw(Graphics2D graphic)
215
+        {
216
+            setForegroundColor(colorString);
217
+            graphic.fill(shape);
218
+        }
219
+    }
220
+
221
+}

+ 192
- 0
FirstLab-Shapes/Circle.java View File

@@ -0,0 +1,192 @@
1
+import java.awt.*;
2
+import java.awt.geom.*;
3
+
4
+/**
5
+ * A circle that can be manipulated and that draws itself on a canvas.
6
+ * 
7
+ * @author  Michael Kölling and David J. Barnes
8
+ * @version 1.0  (15 July 2000)
9
+ */
10
+
11
+public class Circle
12
+{
13
+    private int diameter;
14
+    private int xPosition;
15
+    private int yPosition;
16
+    private String color;
17
+    private boolean isVisible;
18
+
19
+    /**
20
+     * Create a new circle at default position with default color.
21
+     */
22
+    public Circle()
23
+    {
24
+        diameter = 30;
25
+        xPosition = 20;
26
+        yPosition = 60;
27
+        color = "blue";
28
+        isVisible = false;
29
+    }
30
+
31
+    /**
32
+     * Make this circle visible. If it was already visible, do nothing.
33
+     */
34
+    public void makeVisible()
35
+    {
36
+        isVisible = true;
37
+        draw();
38
+    }
39
+
40
+    /**
41
+     * Make this circle invisible. If it was already invisible, do nothing.
42
+     */
43
+    public void makeInvisible()
44
+    {
45
+        erase();
46
+        isVisible = false;
47
+    }
48
+
49
+    /**
50
+     * Move the circle a few pixels to the right.
51
+     */
52
+    public void moveRight()
53
+    {
54
+        moveHorizontal(20);
55
+    }
56
+
57
+    /**
58
+     * Move the circle a few pixels to the left.
59
+     */
60
+    public void moveLeft()
61
+    {
62
+        moveHorizontal(-20);
63
+    }
64
+
65
+    /**
66
+     * Move the circle a few pixels up.
67
+     */
68
+    public void moveUp()
69
+    {
70
+        moveVertical(-20);
71
+    }
72
+
73
+    /**
74
+     * Move the circle a few pixels down.
75
+     */
76
+    public void moveDown()
77
+    {
78
+        moveVertical(20);
79
+    }
80
+
81
+    /**
82
+     * Move the circle horizontally by 'distance' pixels.
83
+     */
84
+    public void moveHorizontal(int distance)
85
+    {
86
+        erase();
87
+        xPosition += distance;
88
+        draw();
89
+    }
90
+
91
+    /**
92
+     * Move the circle vertically by 'distance' pixels.
93
+     */
94
+    public void moveVertical(int distance)
95
+    {
96
+        erase();
97
+        yPosition += distance;
98
+        draw();
99
+    }
100
+
101
+    /**
102
+     * Slowly move the circle horizontally by 'distance' pixels.
103
+     */
104
+    public void slowMoveHorizontal(int distance)
105
+    {
106
+        int delta;
107
+
108
+        if(distance < 0) 
109
+        {
110
+            delta = -1;
111
+            distance = -distance;
112
+        }
113
+        else 
114
+        {
115
+            delta = 1;
116
+        }
117
+
118
+        for(int i = 0; i < distance; i++)
119
+        {
120
+            xPosition += delta;
121
+            draw();
122
+        }
123
+    }
124
+
125
+    /**
126
+     * Slowly move the circle vertically by 'distance' pixels.
127
+     */
128
+    public void slowMoveVertical(int distance)
129
+    {
130
+        int delta;
131
+
132
+        if(distance < 0) 
133
+        {
134
+            delta = -1;
135
+            distance = -distance;
136
+        }
137
+        else 
138
+        {
139
+            delta = 1;
140
+        }
141
+
142
+        for(int i = 0; i < distance; i++)
143
+        {
144
+            yPosition += delta;
145
+            draw();
146
+        }
147
+    }
148
+
149
+    /**
150
+     * Change the size to the new size (in pixels). Size must be >= 0.
151
+     */
152
+    public void changeSize(int newDiameter)
153
+    {
154
+        erase();
155
+        diameter = newDiameter;
156
+        draw();
157
+    }
158
+
159
+    /**
160
+     * Change the color. Valid colors are "red", "yellow", "blue", "green",
161
+     * "magenta" and "black".
162
+     */
163
+    public void changeColor(String newColor)
164
+    {
165
+        color = newColor;
166
+        draw();
167
+    }
168
+
169
+    /*
170
+     * Draw the circle with current specifications on screen.
171
+     */
172
+    private void draw()
173
+    {
174
+        if(isVisible) {
175
+            Canvas canvas = Canvas.getCanvas();
176
+            canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition, 
177
+                    diameter, diameter));
178
+            canvas.wait(10);
179
+        }
180
+    }
181
+
182
+    /*
183
+     * Erase the circle on screen.
184
+     */
185
+    private void erase()
186
+    {
187
+        if(isVisible) {
188
+            Canvas canvas = Canvas.getCanvas();
189
+            canvas.erase(this);
190
+        }
191
+    }
192
+}

+ 12
- 0
FirstLab-Shapes/PayDay/README.TXT View File

@@ -0,0 +1,12 @@
1
+------------------------------------------------------------------------
2
+This is the project README file. Here, you should describe your project.
3
+Tell the reader (someone who does not know anything about this project)
4
+all he/she needs to know. The comments should usually include at least:
5
+------------------------------------------------------------------------
6
+
7
+PROJECT TITLE:
8
+PURPOSE OF PROJECT:
9
+VERSION or DATE:
10
+HOW TO START THIS PROJECT:
11
+AUTHORS:
12
+USER INSTRUCTIONS:

+ 3
- 0
FirstLab-Shapes/PayDay/package.bluej View File

@@ -0,0 +1,3 @@
1
+#BlueJ package file
2
+#Fri Oct 19 10:11:52 EDT 2018
3
+project.charset=UTF-8

+ 12
- 0
FirstLab-Shapes/README.TXT View File

@@ -0,0 +1,12 @@
1
+------------------------------------------------------------------------
2
+This is the project README file. Here, you should describe your project.
3
+Tell the reader (someone who does not know anything about this project)
4
+all he/she needs to know. The comments should usually include at least:
5
+------------------------------------------------------------------------
6
+
7
+PROJECT TITLE:
8
+PURPOSE OF PROJECT:
9
+VERSION or DATE:
10
+HOW TO START THIS PROJECT:
11
+AUTHORS:
12
+USER INSTRUCTIONS:

+ 191
- 0
FirstLab-Shapes/Square.java View File

@@ -0,0 +1,191 @@
1
+import java.awt.*;
2
+
3
+/**
4
+ * A square that can be manipulated and that draws itself on a canvas.
5
+ * 
6
+ * @author  Michael Kölling and David J. Barnes
7
+ * @version 1.0  (15 July 2000)
8
+ */
9
+
10
+public class Square
11
+{
12
+    private int size;
13
+    private int xPosition;
14
+    private int yPosition;
15
+    private String color;
16
+    private boolean isVisible;
17
+
18
+    /**
19
+     * Create a new square at default position with default color.
20
+     */
21
+    public Square()
22
+    {
23
+        size = 30;
24
+        xPosition = 60;
25
+        yPosition = 50;
26
+        color = "red";
27
+        isVisible = false;
28
+    }
29
+
30
+    /**
31
+     * Make this square visible. If it was already visible, do nothing.
32
+     */
33
+    public void makeVisible()
34
+    {
35
+        isVisible = true;
36
+        draw();
37
+    }
38
+
39
+    /**
40
+     * Make this square invisible. If it was already invisible, do nothing.
41
+     */
42
+    public void makeInvisible()
43
+    {
44
+        erase();
45
+        isVisible = false;
46
+    }
47
+
48
+    /**
49
+     * Move the square a few pixels to the right.
50
+     */
51
+    public void moveRight()
52
+    {
53
+        moveHorizontal(20);
54
+    }
55
+
56
+    /**
57
+     * Move the square a few pixels to the left.
58
+     */
59
+    public void moveLeft()
60
+    {
61
+        moveHorizontal(-20);
62
+    }
63
+
64
+    /**
65
+     * Move the square a few pixels up.
66
+     */
67
+    public void moveUp()
68
+    {
69
+        moveVertical(-20);
70
+    }
71
+
72
+    /**
73
+     * Move the square a few pixels down.
74
+     */
75
+    public void moveDown()
76
+    {
77
+        moveVertical(20);
78
+    }
79
+
80
+    /**
81
+     * Move the square horizontally by 'distance' pixels.
82
+     */
83
+    public void moveHorizontal(int distance)
84
+    {
85
+        erase();
86
+        xPosition += distance;
87
+        draw();
88
+    }
89
+
90
+    /**
91
+     * Move the square vertically by 'distance' pixels.
92
+     */
93
+    public void moveVertical(int distance)
94
+    {
95
+        erase();
96
+        yPosition += distance;
97
+        draw();
98
+    }
99
+
100
+    /**
101
+     * Slowly move the square horizontally by 'distance' pixels.
102
+     */
103
+    public void slowMoveHorizontal(int distance)
104
+    {
105
+        int delta;
106
+
107
+        if(distance < 0) 
108
+        {
109
+            delta = -1;
110
+            distance = -distance;
111
+        }
112
+        else 
113
+        {
114
+            delta = 1;
115
+        }
116
+
117
+        for(int i = 0; i < distance; i++)
118
+        {
119
+            xPosition += delta;
120
+            draw();
121
+        }
122
+    }
123
+
124
+    /**
125
+     * Slowly move the square vertically by 'distance' pixels.
126
+     */
127
+    public void slowMoveVertical(int distance)
128
+    {
129
+        int delta;
130
+
131
+        if(distance < 0) 
132
+        {
133
+            delta = -1;
134
+            distance = -distance;
135
+        }
136
+        else 
137
+        {
138
+            delta = 1;
139
+        }
140
+
141
+        for(int i = 0; i < distance; i++)
142
+        {
143
+            yPosition += delta;
144
+            draw();
145
+        }
146
+    }
147
+
148
+    /**
149
+     * Change the size to the new size (in pixels). Size must be >= 0.
150
+     */
151
+    public void changeSize(int newSize)
152
+    {
153
+        erase();
154
+        size = newSize;
155
+        draw();
156
+    }
157
+
158
+    /**
159
+     * Change the color. Valid colors are "red", "yellow", "blue", "green",
160
+     * "magenta" and "black".
161
+     */
162
+    public void changeColor(String newColor)
163
+    {
164
+        color = newColor;
165
+        draw();
166
+    }
167
+
168
+    /*
169
+     * Draw the square with current specifications on screen.
170
+     */
171
+    private void draw()
172
+    {
173
+        if(isVisible) {
174
+            Canvas canvas = Canvas.getCanvas();
175
+            canvas.draw(this, color,
176
+                    new Rectangle(xPosition, yPosition, size, size));
177
+            canvas.wait(10);
178
+        }
179
+    }
180
+
181
+    /*
182
+     * Erase the square on screen.
183
+     */
184
+    private void erase()
185
+    {
186
+        if(isVisible) {
187
+            Canvas canvas = Canvas.getCanvas();
188
+            canvas.erase(this);
189
+        }
190
+    }
191
+}

+ 195
- 0
FirstLab-Shapes/Triangle.java View File

@@ -0,0 +1,195 @@
1
+import java.awt.*;
2
+
3
+/**
4
+ * A triangle that can be manipulated and that draws itself on a canvas.
5
+ * 
6
+ * @author  Michael Kölling and David J. Barnes
7
+ * @version 1.0  (15 July 2000)
8
+ */
9
+
10
+public class Triangle
11
+{
12
+    private int height;
13
+    private int width;
14
+    private int xPosition;
15
+    private int yPosition;
16
+    private String color;
17
+    private boolean isVisible;
18
+
19
+    /**
20
+     * Create a new triangle at default position with default color.
21
+     */
22
+    public Triangle()
23
+    {
24
+        height = 30;
25
+        width = 40;
26
+        xPosition = 50;
27
+        yPosition = 15;
28
+        color = "green";
29
+        isVisible = false;
30
+    }
31
+
32
+    /**
33
+     * Make this triangle visible. If it was already visible, do nothing.
34
+     */
35
+    public void makeVisible()
36
+    {
37
+        isVisible = true;
38
+        draw();
39
+    }
40
+
41
+    /**
42
+     * Make this triangle invisible. If it was already invisible, do nothing.
43
+     */
44
+    public void makeInvisible()
45
+    {
46
+        erase();
47
+        isVisible = false;
48
+    }
49
+
50
+    /**
51
+     * Move the triangle a few pixels to the right.
52
+     */
53
+    public void moveRight()
54
+    {
55
+        moveHorizontal(20);
56
+    }
57
+
58
+    /**
59
+     * Move the triangle a few pixels to the left.
60
+     */
61
+    public void moveLeft()
62
+    {
63
+        moveHorizontal(-20);
64
+    }
65
+
66
+    /**
67
+     * Move the triangle a few pixels up.
68
+     */
69
+    public void moveUp()
70
+    {
71
+        moveVertical(-20);
72
+    }
73
+
74
+    /**
75
+     * Move the triangle a few pixels down.
76
+     */
77
+    public void moveDown()
78
+    {
79
+        moveVertical(20);
80
+    }
81
+
82
+    /**
83
+     * Move the triangle horizontally by 'distance' pixels.
84
+     */
85
+    public void moveHorizontal(int distance)
86
+    {
87
+        erase();
88
+        xPosition += distance;
89
+        draw();
90
+    }
91
+
92
+    /**
93
+     * Move the triangle vertically by 'distance' pixels.
94
+     */
95
+    public void moveVertical(int distance)
96
+    {
97
+        erase();
98
+        yPosition += distance;
99
+        draw();
100
+    }
101
+
102
+    /**
103
+     * Slowly move the triangle horizontally by 'distance' pixels.
104
+     */
105
+    public void slowMoveHorizontal(int distance)
106
+    {
107
+        int delta;
108
+
109
+        if(distance < 0) 
110
+        {
111
+            delta = -1;
112
+            distance = -distance;
113
+        }
114
+        else 
115
+        {
116
+            delta = 1;
117
+        }
118
+
119
+        for(int i = 0; i < distance; i++)
120
+        {
121
+            xPosition += delta;
122
+            draw();
123
+        }
124
+    }
125
+
126
+    /**
127
+     * Slowly move the triangle vertically by 'distance' pixels.
128
+     */
129
+    public void slowMoveVertical(int distance)
130
+    {
131
+        int delta;
132
+
133
+        if(distance < 0) 
134
+        {
135
+            delta = -1;
136
+            distance = -distance;
137
+        }
138
+        else 
139
+        {
140
+            delta = 1;
141
+        }
142
+
143
+        for(int i = 0; i < distance; i++)
144
+        {
145
+            yPosition += delta;
146
+            draw();
147
+        }
148
+    }
149
+
150
+    /**
151
+     * Change the size to the new size (in pixels). Size must be >= 0.
152
+     */
153
+    public void changeSize(int newHeight, int newWidth)
154
+    {
155
+        erase();
156
+        height = newHeight;
157
+        width = newWidth;
158
+        draw();
159
+    }
160
+
161
+    /**
162
+     * Change the color. Valid colors are "red", "yellow", "blue", "green",
163
+     * "magenta" and "black".
164
+     */
165
+    public void changeColor(String newColor)
166
+    {
167
+        color = newColor;
168
+        draw();
169
+    }
170
+
171
+    /*
172
+     * Draw the triangle with current specifications on screen.
173
+     */
174
+    private void draw()
175
+    {
176
+        if(isVisible) {
177
+            Canvas canvas = Canvas.getCanvas();
178
+            int[] xpoints = { xPosition, xPosition + (width/2), xPosition - (width/2) };
179
+            int[] ypoints = { yPosition, yPosition + height, yPosition + height };
180
+            canvas.draw(this, color, new Polygon(xpoints, ypoints, 3));
181
+            canvas.wait(10);
182
+        }
183
+    }
184
+
185
+    /*
186
+     * Erase the triangle on screen.
187
+     */
188
+    private void erase()
189
+    {
190
+        if(isVisible) {
191
+            Canvas canvas = Canvas.getCanvas();
192
+            canvas.erase(this);
193
+        }
194
+    }
195
+}

+ 68
- 0
FirstLab-Shapes/package.bluej View File

@@ -0,0 +1,68 @@
1
+#BlueJ package file
2
+dependency1.from=Circle
3
+dependency1.to=Canvas
4
+dependency1.type=UsesDependency
5
+dependency2.from=Square
6
+dependency2.to=Canvas
7
+dependency2.type=UsesDependency
8
+dependency3.from=Triangle
9
+dependency3.to=Canvas
10
+dependency3.type=UsesDependency
11
+editor.fx.0.height=0
12
+editor.fx.0.width=0
13
+editor.fx.0.x=0
14
+editor.fx.0.y=0
15
+objectbench.height=88
16
+objectbench.width=776
17
+package.divider.horizontal=0.6
18
+package.divider.vertical=0.8496835443037974
19
+package.editor.height=530
20
+package.editor.width=674
21
+package.editor.x=216
22
+package.editor.y=460
23
+package.frame.height=690
24
+package.frame.width=800
25
+package.numDependencies=3
26
+package.numTargets=5
27
+package.showExtends=true
28
+package.showUses=true
29
+project.charset=UTF-8
30
+readme.height=58
31
+readme.name=@README
32
+readme.width=47
33
+readme.x=10
34
+readme.y=10
35
+target1.height=50
36
+target1.name=Circle
37
+target1.showInterface=false
38
+target1.type=ClassTarget
39
+target1.width=80
40
+target1.x=390
41
+target1.y=0
42
+target2.height=62
43
+target2.name=PayDay
44
+target2.type=PackageTarget
45
+target2.width=80
46
+target2.x=10
47
+target2.y=130
48
+target3.height=50
49
+target3.name=Canvas
50
+target3.showInterface=false
51
+target3.type=ClassTarget
52
+target3.width=80
53
+target3.x=70
54
+target3.y=10
55
+target4.height=50
56
+target4.name=Triangle
57
+target4.showInterface=false
58
+target4.type=ClassTarget
59
+target4.width=80
60
+target4.x=160
61
+target4.y=70
62
+target5.height=50
63
+target5.name=Square
64
+target5.showInterface=false
65
+target5.type=ClassTarget
66
+target5.width=80
67
+target5.x=70
68
+target5.y=70

+ 37
- 3
LoopFun.java View File

@@ -8,7 +8,13 @@ public class LoopFun
8 8
        * @return the factorial of the number
9 9
        */
10 10
       public int factorial(int number){
11
-          return -1;
11
+         int factorial = 1; 
12
+         
13
+        for ( int i = 1; i <= number; i++) {
14
+            
15
+             factorial = i * factorial;
16
+            
17
+            } return factorial;
12 18
       }
13 19
 
14 20
       /**
@@ -18,8 +24,19 @@ public class LoopFun
18 24
        * @param phrase
19 25
        * @return Upper case string of the first letter of each word
20 26
        */
27
+      //get first letter of each word in string
28
+      //turn letter into upper case
29
+      //returen acronym
21 30
       public String acronym(String phrase) {
22
-          return null;
31
+          StringBuilder acronym = new StringBuilder();
32
+          acronym.append(phrase.charAt(0));
33
+          
34
+          for (int i = 0; i < phrase.length(); i++) {
35
+              if(Character.isWhitespace(phrase.charAt(i))) {
36
+                  acronym.append(phrase.charAt(i + 1));
37
+                }
38
+            }
39
+          return acronym.toString().toUpperCase();
23 40
       }
24 41
 
25 42
       /**
@@ -35,6 +52,23 @@ public class LoopFun
35 52
        * @return the encrypted string by shifting each character by three character
36 53
        */
37 54
       public String encrypt(String word) {
38
-          return null;
55
+          String alpha = "abcdefghijklmnopqrstuvwxyz";
56
+          
57
+          StringBuilder encryptedWord = new StringBuilder();
58
+          
59
+          for (int  i= 0; i < word.length(); i++) {
60
+              char letter = word.charAt(i);
61
+              int index = 0;
62
+              
63
+              if (alpha.indexOf(letter + 3) == -1) {
64
+                  index = ((alpha.indexOf(letter) -26) + 3);
65
+                  
66
+                }else {
67
+                    index = alpha.indexOf(letter + 3);
68
+                }
69
+              encryptedWord.append(alpha.charAt(index));
70
+            }
71
+          
72
+          return encryptedWord.toString();
39 73
       }
40 74
 }

+ 5
- 4
MathUtilities.java View File

@@ -12,7 +12,8 @@ public class MathUtilities{
12 12
    * @param num2 second number
13 13
    * @return the sum of the two numbers
14 14
    */
15
-  
15
+  //add number one and two together
16
+  // return the sum
16 17
   
17 18
   public int add(int num1, int num2){
18 19
       
@@ -40,7 +41,7 @@ public class MathUtilities{
40 41
    */
41 42
   public double half(int number) {
42 43
       //if either number is a double the int will be converted into a double
43
-     d = (number/2); 
44
+ double d = (number/2.00); 
44 45
       
45 46
       return d;
46 47
   }
@@ -56,8 +57,8 @@ public class MathUtilities{
56 57
       
57 58
           
58 59
           
59
-      if ( number % 2 == 0); return false;
60
-      
60
+      if (number % 2 == 0){ return false;
61
+        }
61 62
      else return true;
62 63
     
63 64
   }

+ 24
- 15
StringUtilities.java View File

@@ -4,28 +4,37 @@ public class StringUtilities {
4 4
    public Character getMiddleCharacter(String word){
5 5
        //get the middle of the string
6 6
        
7
-        if (str.length() <= 2) {
8
-            
9
-         return str;
10
-      }
11
-      int beginIndex = (str.length() - 1) / 2;
12
-      
13
-      int endIndex = beginIndex + 2 - (str.length() % 2);
14
-      
15
-      return str.substring(beginIndex, endIndex);
16
-   }
7
+     
8
+        
9
+           return word.charAt(word.length()/2); 
10
+        
17 11
        
18
- 
12
+      
19 13
       
20 14
  }
21 15
    
22
-   public String removeCharacter(String value, char charToRemove){
16
+    
17
+ 
18
+    public String removeCharacter(String value, char charToRemove){
23 19
        
20
+    String r = "";
21
+    
22
+    for (int i = 0; i < value.length(); i++) {
23
+        
24
+      if (value.charAt(i) != charToRemove)
25
+        r += value.charAt(i);
26
+    }
27
+    return r;
24 28
        
25
-     return null;  
29
+       
30
+ 
26 31
    }
27 32
    
28
-   public String getLastWord(String value) {
29
-       return null;
33
+
34
+    public String getLastWord(String value) {
35
+       String lastWord = value.substring(value.lastIndexOf(" ") + 1);
36
+       return lastWord; 
30 37
    }
38
+   
31 39
 }
40
+

+ 12
- 12
package.bluej View File

@@ -1,25 +1,25 @@
1 1
 #BlueJ package file
2
-dependency1.from=StringUtilitiesTest
3
-dependency1.to=StringUtilities
2
+dependency1.from=LoopFunTest
3
+dependency1.to=LoopFun
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=LoopFunTest
6
-dependency2.to=LoopFun
5
+dependency2.from=MathUtilitiesTest
6
+dependency2.to=MathUtilities
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=MathUtilitiesTest
9
-dependency3.to=MathUtilities
8
+dependency3.from=StringUtilitiesTest
9
+dependency3.to=StringUtilities
10 10
 dependency3.type=UsesDependency
11
-editor.fx.0.height=722
12
-editor.fx.0.width=876
13
-editor.fx.0.x=-293
14
-editor.fx.0.y=-996
11
+editor.fx.0.height=418
12
+editor.fx.0.width=800
13
+editor.fx.0.x=480
14
+editor.fx.0.y=365
15 15
 objectbench.height=163
16 16
 objectbench.width=669
17 17
 package.divider.horizontal=0.6
18 18
 package.divider.vertical=0.7635605006954103
19 19
 package.editor.height=542
20 20
 package.editor.width=567
21
-package.editor.x=593
22
-package.editor.y=-1057
21
+package.editor.x=587
22
+package.editor.y=23
23 23
 package.frame.height=777
24 24
 package.frame.width=693
25 25
 package.numDependencies=3