第十二周
本周任务如下:
注册OnlineGDB并且加入课程群:https://onlinegdb.com/classroom/invite/Fd0aduv55
完成Person Class作业
Person Class
An instance variable can be assigned an initial value in its declaration, just like any other variable. For example, consider a class named Person. An object of this class will represent a person. It will contain three instance variables to represent its name, email and phone number:
Exercise1: Validate person's email
The '@' symbol is a crucial component of the syntax for email addresses. According to the standard format,
email address consists of two main parts: a local part and a domain part. These two parts are separated by the '@' symbol. For example, in the email address "example@example.com", "example" is the local part, and "example.com" is the domain part.
Your task is to add a method isValidEmail() to this class that checks if the person's email contains the '@' . This method should return true
if the email contains '@', and false
otherwise.
The method signature should be:
public boolean isValidEmail()
Exercise 2: Test your Person Class.
Create a driver class. Paste the code here. Create the following two Person Objects in the driver class.
Click test, then you can see the result.
When you are ready, submit your code.
Last updated