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

NEED HELP WITH TAPESTRY ASSIGNMENT:(CODE IN JAVA) Step 1: Creating a custom enti

ID: 3742131 • Letter: N

Question

NEED HELP WITH TAPESTRY ASSIGNMENT:(CODE IN JAVA)

Step 1: Creating a custom entity type for your application

First you will need a determine what kind of custom entity that you would like your Tapestry site to display information about. This could be something like a Movie, Student, Automobile, Bank Account, Book, or Sports Team. This entity will be represented by a simple Java class (the instructions will refer to this as the CustomEntity class, but you should use a more appropriate name that is descriptive of your custom entity) with fields for the various properties and getter and setter methods for each field. You may use the automatic code generation of features of the IDE to create those methods for you.

You should also include a default constructor method (it does not need to assign any particular values to the fields) but may want to include other constructor or factory methods to make generating instances of your custom entity easier. You should also add a field of type int (or long) that will represent the primary key for the object as though it were a record in a database. You will need to include a getter method for this field. A setter method may not be necessary, but you will need to ensure that you have a constructor method that can set the value of the field in that case.

Your custom entity should have the following characteristics:

1.At least six different attributes (i.e. six different data fields)

2. At least one attribute should be text

3. At least one attribute should be a number of some type

4. At least one attribute should be of type Date (use this exact type for the field)

5. At least one attribute should have a limited number of valid options (e.g. on a web form, you would select the value with a drop-down combo box.) for its values. You may create a custom enum type for this field, which can make this easier.

6. At least two attributes should have some validation criteria such as a valid range for a number, text that cannot be an empty String, or even more complex criteria such as one Date attribute occurring after another Date attribute.

Explanation / Answer

Please find the Custom Entity represented via Java class below:-

2. public enum Hobbies {

DRAWING, GAMING, PLANTATION, MUSIC, YOGA, CYCLING

}

1. Student.java

import java.sql.Date;

import java.util.regex.Pattern;

public class Student {

private int studentId;

private String firstName;

private String lastName;

private Date dob;

private String mobileNo;

private String emailAddress;

private Hobbies hobbies; // This will be used for drop-down

// Default Constructor

public Student(){

}

public Student(int studentId, String firstName, String lastName, Date dob, String mobileNo, String emailAddress, Hobbies hobbies) {

super();

this.studentId = studentId;

this.firstName = firstName;

this.lastName = lastName;

this.dob = dob;

this.mobileNo = mobileNo;

this.emailAddress = emailAddress;

this.hobbies = hobbies;

}

public int getStudentId() {

return studentId;

}

public void setStudentId(int studentId) {

this.studentId = studentId;

}

public String getFirstName() {

return firstName;

}

public void setFirstName(String firstName) {

this.firstName = firstName;

}

public String getLastName() {

return lastName;

}

public void setLastName(String lastName) {

this.lastName = lastName;

}

public Date getDob() {

return dob;

}

public void setDob(Date dob) {

this.dob = dob;

}

public String getMobileNo() {

return mobileNo;

}

public void setMobileNo(String mobileNo) {

this.mobileNo = mobileNo;

}

public String getEmailAddress() {

return emailAddress;

}

public void setEmailAddress(String emailAddress) {

this.emailAddress = emailAddress;

}

public Hobbies getHobbies() {

return hobbies;

}

public void setHobbies(Hobbies hobbies) {

this.hobbies = hobbies;

}

// validate the email address is in correct format

public boolean isEmailAddressValid(){

String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\."+

"[a-zA-Z0-9_+&*-]+)*@" +

"(?:[a-zA-Z0-9-]+\.)+[a-z" +

"A-Z]{2,7}$";

Pattern pat = Pattern.compile(emailRegex);

if (emailAddress == null)

return false;

return pat.matcher(emailAddress).matches();

}

// validates the mobile No entered.

public boolean isMobileNumberValid(){

if (mobileNo == null || mobileNo.equals(""))

return false;

if (mobileNo.length() < 10 || mobileNo.length() > 10)

return false;

if (mobileNo.equals("0000000000"))

return false;

return true;

}

@Override

public String toString() {

return "Student [studentId=" + studentId + ", firstName=" + firstName + ", lastName=" + lastName + ", dob=" + dob + ", mobileNo=" + mobileNo + ", emailAddress=" + emailAddress + ", hobbies=" + hobbies + "]";

}

}

Please let me know in case of any clarifications required. Thanks!