-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriangle.java
More file actions
127 lines (110 loc) · 3.82 KB
/
Triangle.java
File metadata and controls
127 lines (110 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import java.util.Scanner;
/**
* COMP90041, Sem1, 2023: Assignment 2
* @author: Jule Valendo Halim
* @studentID: 1425567
* @universityEmail : julevalendoh@student.unimelb.edu.au
*/
public class Triangle {
//instance variables
private int sideLength;
private char printingChar;
private int rotationDegree;
//default constructor
public Triangle() {
setSideLength(5);
setPrintingChar('*');
setRotationDegree(0);
}
//constructor
public Triangle(int sideLength, char printingChar) {
setSideLength(sideLength);
setPrintingChar(printingChar);
setRotationDegree(0);
}
//copy constructor
public Triangle(Triangle triangle) {
setPrintingChar(triangle.printingChar);
setSideLength(triangle.sideLength);
setRotationDegree(triangle.rotationDegree);
}
//public methods
//accessors
//get side length
public int getSideLength() {
return sideLength;
}
//get printing char
public char getPrintingChar() {
return printingChar;
}
//get rotation degree
public int getRotationDegree() {
return rotationDegree;
}
//mutators
//change side length
public void setSideLength(int sideLength) {
this.sideLength = sideLength;
}
//change printing char
public void setPrintingChar(char printingChar) {
this.printingChar = printingChar;
}
//change rotation degree
public void setRotationDegree(int rotationDegree) {
this.rotationDegree = rotationDegree;
}
//other public methods
//zooming in
public void setSideZoomOut(Triangle triangle) {
triangle.setSideLength(triangle.getSideLength() - 1);
}
//zooming out
public void setSideZoomIn(Triangle triangle) {
triangle.setSideLength(triangle.getSideLength() + 1);
}
//iterate over drawing canvas array
public void triangleToArray(Triangle triangle, char[][] canvasArray, int x, int y) {
//no rotation printing to canvas
if (triangle.getRotationDegree() == 0) {
int n = 0;
for (int i = y; i < y + triangle.getSideLength(); i++) {
for (int j = x; j < x + triangle.getSideLength() - n; j++) {
canvasArray[i][j] = triangle.getPrintingChar();
}
n++;
}
}
//array print orientation where rotation for 1 right rotation or 3 left rotations
if (triangle.getRotationDegree() == 3 || triangle.getRotationDegree() == -1) {
int n = 0;
for (int i = y; i < y + triangle.getSideLength(); i++) {
for (int j = x + n; j < x + triangle.getSideLength(); j++) {
canvasArray[i][j] = triangle.getPrintingChar();
}
n++;
}
}
//array print orientation where rotation for 2 right rotations or 2 left rotations
if (triangle.getRotationDegree() == 2 || triangle.getRotationDegree() == -2) {
int n = triangle.getSideLength() - 1;
for (int i = y; i < y + triangle.getSideLength(); i++) {
for (int j = x + n; j < x + triangle.getSideLength(); j++) {
canvasArray[i][j] = triangle.getPrintingChar();
}
n--;
}
}
//array print orientation where rotation for 3 right rotations or 1 left rotation
if (triangle.getRotationDegree() == 1 || triangle.getRotationDegree() == -3) {
int n = triangle.getSideLength() - 1;
for (int i = y; i < y + triangle.getSideLength(); i++) {
for (int j = x; j < x + triangle.getSideLength() - n; j++) {
canvasArray[i][j] = triangle.getPrintingChar();
}
n--;
}
}
}
}