Create a Symbol class: --class Symbol represents symbols Symbols, for this proje
ID: 3890511 • Letter: C
Question
Create a Symbol class:
--class Symbol represents symbols
Symbols, for this project, are defined as a string of characters that do NOT include blanks, numeric, and special characters. For example, “JLabel(“Color Example”, SwingConstants.CENTER);” contains five symbols, “JLabel”, “Color”, “Example”, “SwingConstants”, and “CENTER”. All special characters should be ignored.
------------------------------------------------------------------------------------------------------------------------
UML for Symbol class
Class Symbol
INSTANCE DATA FIELDS
-strToken : String
METHODS
+Symbol(String sym)
It should throw an IllegalArgumentException with an appropriate message if an illegal symbol is attempted.
+clone()
The clone() method should create a clone, a “deep copy”, of Symbol.
+equals(Symbol sym)
Class Symbol
INSTANCE DATA FIELDS
-strToken : String
METHODS
+Symbol(String sym)
It should throw an IllegalArgumentException with an appropriate message if an illegal symbol is attempted.
+clone()
The clone() method should create a clone, a “deep copy”, of Symbol.
+equals(Symbol sym)
Explanation / Answer
Symbol.java
public class Symbol {
private String strToken;
public Symbol(String sym) {
this.strToken = sym;
}
public Object clone() throws CloneNotSupportedException {
return this.clone();
}
public String getStrToken() {
return strToken;
}
public boolean equals(Symbol sym) {
if(sym.getStrToken().equals(strToken)) {
return true;
}
return false;
}
}