-
Notifications
You must be signed in to change notification settings - Fork 0
/
Diamond.java
85 lines (84 loc) · 1.59 KB
/
Diamond.java
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
/*
* Created by Noah Shaw
*/
public class Diamond extends ShapeBasics implements DiamondInterface {
//Attributes
private int width;
//Constructors
public Diamond()
{
super();
this.width = 0;
}
public Diamond(int aWidth, int newOffset)
{
super(newOffset);
this.setWidth(aWidth);
}
//Accessors
public int getWidth()
{
return this.width;
}
//Mutators
public void setWidth(int width)
{
if(width%2 == 1)
{
this.width = width;
}
else
{
this.width = width + 1;
}
}
//Methods
public void drawHere() //Override
{
drawTopV();
drawBottomV();
}
private void drawTopV()
{
for(int i = 0; i < ((this.width + 1) / 2); i++)
{
for(int j = 0; j <= ((this.width - 1) + this.getOffset()); j++)
{
if(j == ((this.width - 1) / 2) + this.getOffset() + i || j == (((this.width - 1) / 2) + this.getOffset() - i))
{
System.out.print("*");
}
else
{
skipSpaces(1);
}
}
System.out.println();
}
}
private void drawBottomV()
{
for (int i = (((this.width - 1) / 2) - 1); i >= 0; i--)
{
for(int j = 0; j <= ((this.width -1 ) + this.getOffset()); j++)
{
if(j == ((this.width - 1) / 2) + this.getOffset() + i || j == (((this.width - 1) / 2) + this.getOffset() - i))
{
System.out.print("*");
}
else
{
skipSpaces(1);
}
}
System.out.println();
}
}
public static void skipSpaces(int aSpaces)
{
for(int i = 0; i < aSpaces; i++)
{
System.out.print(" ");
}
}
}