revise it to my own one.(I got a example)
revise it to my own one.(I got a example)
xxx.java
public class xxx {
public static void main(String[] args) {
TripleString t1 = new TripleString(); //default constuctor
TripleString t2 = new TripleString(“one”, “two”, “three”); //valid values in parameterizied constructor
TripleString t3 = new TripleString(null, “”, “xyz”); //invalid values for 2 parameters
TripleString t4 = new TripleString(null, null, null); //invalid parameters for all 3
System.out.println(“Displaying the 4 triple strings created using different constructors”);
System.out.println(“t1 using default constructor : \n” + t1);
System.out.println(“t2 with all valid values: \n” + t2);
System.out.println(“t3 with 2 parameters invalid: \n” + t3);
System.out.println(“t4 with all invalid parameters: \n” + t4);
//mutate all objects
System.out.println(“\nUsing mutators to change each of the objects”);
t1.setString1(“potato”);
t2.setString2(“four”);
t3.setString3(“chips”);
t4.setString1(“pen”);
System.out.println(“t1: ” + t1);
System.out.println(“t2: ” + t2);
System.out.println(“t3: ” + t3);
System.out.println(“t4: ” + t4);
System.out.println();
//explicit test
if(t3.setString1(“watermelon”))
System.out.println(“t3.setString1(\”watermelon\”) was succesful”);
else
System.out.println(“t3.setString1(\”watermelon\”) was NOT succesful”);
if(t3.setString3(“”))
System.out.println(“t3.setString1(\”\”) was succesful”);
else
System.out.println(“t3.setString1(\”\”) was NOT succesful”);
System.out.println(“t2.getString1() = ” + t2.getString1());
System.out.println(“t2.getString2() = ” + t2.getString2());
}
}
class TripleString
{
private String string1;
private String string2;
private String string3;
public static final int MIN_LEN = 1;
public static final int MAX_LEN = 50;
public static final String DEFAULT_STRING = ” (undefined) “;
public TripleString()
{
string1 = DEFAULT_STRING;
string2 = DEFAULT_STRING;
string3 = DEFAULT_STRING;
}
public TripleString(String s1, String s2, String s3)
{
if(!setString1(s1))
string1 = DEFAULT_STRING;
if(!setString2(s2))
string2 = DEFAULT_STRING;
if(!setString3(s3))
string3 = DEFAULT_STRING;
}
public boolean setString1(String s1) {
if(validString(s1))
{
this.string1 = s1;
return true;
}
else
return false;
}
public boolean setString2(String s2) {
if(validString(s2))
{
this.string2 = s2;
return true;
}
else
return false;
}
public boolean setString3(String s3) {
if(validString(s3))
{
this.string3 = s3;
return true;
}
else
return false;
}
public String getString1() {
return string1;
}
public String getString2() {
return string2;
}
public String getString3() {
return string3;
}
public String toString()
{
return “[ string1: ” + string1 + “, string2: ” + string2 + “, string3: ” +string3 + ” ]”;
}
private static boolean validString(String s)
{
if(s != null && s.length() >= MIN_LEN && s.length() <= MAX_LEN)
return true;
else
return false;
}
}
Top-quality papers guaranteed
100% original papers
We sell only unique pieces of writing completed according to your demands.
Confidential service
We use security encryption to keep your personal data protected.
Money-back guarantee
We can give your money back if something goes wrong with your order.
Enjoy the free features we offer to everyone
-
Title page
Get a free title page formatted according to the specifics of your particular style.
-
Custom formatting
Request us to use APA, MLA, Harvard, Chicago, or any other style for your essay.
-
Bibliography page
Don’t pay extra for a list of references that perfectly fits your academic needs.
-
24/7 support assistance
Ask us a question anytime you need to—we don’t charge extra for supporting you!
Calculate how much your essay costs
What we are popular for
- English 101
- History
- Business Studies
- Management
- Literature
- Composition
- Psychology
- Philosophy
- Marketing
- Economics