-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStructure.java
More file actions
62 lines (56 loc) · 1.44 KB
/
Structure.java
File metadata and controls
62 lines (56 loc) · 1.44 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
/**
* Class represent for Structure
*/
abstract public class Structure {
// Name of Structure
protected String name = null;
/**
* Default constructor
*/
public Structure() {}
/**
* check a name is valid or not
* @param name the name
* @return true or false
*/
public boolean checkValid(String name){
if (name == null){
System.out.println(name+" is an invalid name");
return false;
}
int x;
for (int i=0; i<name.length(); i++){
x = (int) name.charAt(i);
if ((x>=48 && x<=57) || (x>=65 && x<=90) || (x>=97 && x<=122)) continue;
System.out.println(name+" is an invalid name");
return false;
}
x = (int) name.charAt(0);
if (x>=48 && x<=57) {
System.out.println(name+" is an invalid name");
return false;
}
return true;
}
/**
* set name for Structure
* @param name of Structure
* @return setting-name ability
*/
public boolean setName(String name) {
if (!checkValid(name)) return false;
this.name = name;
return true;
}
/**
* return name of Structure
* @return the name
*/
public String getName() {
return name;
}
@Override
public int hashCode(){
return name.hashCode();
}
}