-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordNode.java
More file actions
164 lines (151 loc) · 4.8 KB
/
PasswordNode.java
File metadata and controls
164 lines (151 loc) · 4.8 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//////////////// FILE HEADER (INCLUDE IN EVERY FILE) //////////////////////////
//
// Title: P09 Password Cracking
// Course: CS 300 Spring 2023
//
// Author: Shourjo Aditya Chaudhuri
// Email: sachaudhuri@wisc.edu
// Lecturer: Hobbes LeGault
//
//////////////////// PAIR PROGRAMMERS COMPLETE THIS SECTION ///////////////////
//
// Partner Name: No Pair Programming in this project
// Partner Email: No Pair Programming in this project
// Partner Lecturer's Name: No Pair Programming in this project
//
// VERIFY THE FOLLOWING BY PLACING AN X NEXT TO EACH TRUE STATEMENT:
// ___ Write-up states that pair programming is allowed for this assignment.
// ___ We have both read and understand the course Pair Programming Policy.
// ___ We have registered our team prior to the team registration deadline.
//
///////////////////////// ALWAYS CREDIT OUTSIDE HELP //////////////////////////
//
// Persons: None
// Online Sources: None
//
///////////////////////////////////////////////////////////////////////////////
/**
* Class to represent a binary search tree (BST) node that contains only Password objects.
*
* @author Michelle & Shourjo Aditya Chaudhuri
*/
public class PasswordNode {
private Password password; // the password data this node stores
private PasswordNode left; // a reference to node that is the left child
private PasswordNode right; // a reference to the node that is the right child
/**
* 1-argument constructor that sets the only data of the node.
*
* @param password the password for this node to store
* @author Michelle
*/
public PasswordNode(Password password) {
this.password = password;
}
/**
* 3-argument constructor that sets all three data field
*
* @param password, password the password for this node to store
* @param left, the reference to the node that is the left child
* @param right, the reference to the node that is the right child
* @author Michelle
*/
public PasswordNode(Password password, PasswordNode left, PasswordNode right) {
this(password);
this.left = left;
this.right = right;
}
/**
* Setter for left data field
*
* @param left, the reference to the node to be the left child
* @author Michelle
*/
public void setLeft(PasswordNode left) {
this.left = left;
}
/**
* Setter for right data field
*
* @param right, the reference to the node to be the right child
* @author Michelle
*/
public void setRight(PasswordNode right) {
this.right = right;
}
/**
* Getter for left data field
*
* @return the reference to the node that is the left child
* @author Michelle
*/
public PasswordNode getLeft() {
return this.left;
}
/**
* Getter for right data field
*
* @return the reference to the node that is the right child
* @author Michelle
*/
public PasswordNode getRight() {
return this.right;
}
/**
* Getter for password data field
*
* @return the password object that this node stores
* @author Michelle
*/
public Password getPassword() {
return this.password;
}
/**
* Determines if the current node is a leaf node
*
* @return true if this node is a leaf, false otherwise
* @author Shourjo Aditya Chaudhuri
*/
public boolean isLeafNode() {
if (hasLeftChild() || hasRightChild()) {
return false; //if the current node has a left child or a right child: not a leaf
} else {
return true;
}
}
/**
* Determines if the current node has a right child
*
* @return true if this node has a right child, false otherwise
* @author Shourjo Aditya Chaudhuri
*/
public boolean hasRightChild() {
return this.right != null; //checks if the current node has a right child
}
/**
* Determines if the current node has a left child
*
* @return true if this node has a left child, false otherwise
* @author Shourjo Aditya Chaudhuri
*/
public boolean hasLeftChild() {
return this.left != null; ////checks if the current node has a left child
}
/**
* Determines how many children nodes this node has. RECALL: Nodes in a binary tree can have AT
* MOST 2 children
*
* @return The number of children this node has
* @author Shourjo Aditya Chaudhuri
*/
public int numberOfChildren() {
int children = 0;
if (hasRightChild()) {
children++; //adds the count the right children to children variable
}
if (hasLeftChild()) {
children++;//adds the count the left children to children variable
}
return children;
}
}