Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class CharacterSet. The CharacterSet can hold a set of lowercase alphab

ID: 3620795 • Letter: C

Question

Create a class CharacterSet.
The CharacterSet can hold a set of lowercase alphabet characters. Define one or more instance variables to represent CharacterSet properties and hold character elements. CharacterSet contains the following methods:
a. One or more constructors.
b. Method void add(char ch)inserts a character to the set. If the character ch is uppercase letter, convert it to lowercase and add. If the character already exists in the set, ignore to add. If the character is not a letter, display an error message.
c. Method void delete(char ch) deletes a character from the set. If the character is not in the set, display an error message.
d. Method CharacterSet union(CharacterSet x) returns a third set that is the union of two sets.
Assuming that set1 = {a, b, d} and set2 = {b, c, y}, the union of set1 and set2 (set1 set1) should be {a,b,c,d,y}. Remember that the set does not have any duplicating elements.
e. Method CharacterSet intersection(CharacterSet x) creates a third set that is the intersection of two sets.
Assuming that set1 = {a, b, d} and set2 = {b, c, y}, the intersection of set1 and set2 (set1 set1) should be {b}
f. Method int cardinality() returns the number of characters in the set.
g. Method boolean equals(CharacterSet x) determines if the set is equal to x.
h. Method String toString() returns a string description of the set.
i. Method boolean isEmpty() returns true if the set is empty.
j. Method boolean isSubset(CharacterSet x) determines if the set is a subset of x.

then

Create a class named MyDate that contains year, month and date of int type. Provide one or more constructors, toString() method, accessors, and mutators.
2.2 Create a class named Person that contains two String data fields for last name and first name and one MyDate data field for birthdate. Provide one or more constructors, toString() method, accessors, and mutators.
2.3 Create a class named Student that extends Person class and contains two additional properties: int CIN and double GPA. Provide one or more constructors, toString() method, accessors and mutators for cin and GPA.
2.3 Create a class named Faculty that extends Person class and contains two additional properties: String department and String rank (“full time or “part time”). Provide one or more constructors, toString() method, accessors and mutators for department and rank .

Explanation / Answer

class Person

{

protected String firstName;

protected String lastName;

protected Date birthDate;

// constructor to initialize name, birth date

public Person( String first, String last, Date dateOfBirth)

{

firstName = first;

lastName = last;

birthDate = dateOfBirth;

} // end Employee constructor

//returns first name

public String getFirstName()

{

return firstName;

}

public String getLastName()

{

return lasttName;

}

// convert Employee to String format

public String toString()

{

return String.format( "%s, %s Birthday: %s",

lastName, firstName, birthDate );

} // end method toPersonString

class Student extends Person

{

private int CIN;

private double GPA;

// constructor

public Student( String first, String last,Date dt,int cin,double gp )

{

// explicit call to superclass CommissionEmployee constructor

super( first, last, dt);

setCIN(cin);

setGPA( gp);

} // end constructor

// set CIN

public void setCIN( int cn)

{

CIN=cn;

} // end method

// set GPA

public void setGpa( double gp )

{

GPA=gp;

} // end method

// return base salary

public int getCIN()

{

return CIN;

} // end method

// return base salary

public double getGPA()

{

return GPA;

} // end method getBaseSalary

//returns string of student

public String toString()

{

// not allowed: attempts to access private superclass members

return String.format(

"%s: %s %s %d: %f ",

"Person:", firstName, lastName,

"BirthDay",birthDate ,

"CIN:",CIN , "GPA",GPA);

} // end method toString

class Faculty extends Person

{

private String Department;

private String Rank;

// constructor

public Faculty( String first, String last,Date dt,String dpt,String rk )

{

// explicit call to superclass Person constructor

super( first, last, dt);

setDept(dpt);

setRank(rk);

} // end constructor

public void setDepartment(String rk)

{

Rank=rk;

}

public void setRank(String dept)

{

Department=dept;

}

public String getRank()

{ return Rank;}

public String getDept()

{

return Department;

}

public String toString()

{

return String.format(

"%s: %s %s %d: %f ",

"Person:", firstName, lastName,

"BirthDay",birthDate ,

"Department:",Department , "Rank:",Rank);

} // end method toString

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote