> For the complete documentation index, see [llms.txt](https://scls-cs.gitbook.io/apcs-lab/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://scls-cs.gitbook.io/apcs-lab/apcsa-i-2023-fall/di-shi-er-zhou.md).

# 第十二周

本周任务如下：

1. 注册OnlineGDB并且加入课程群：<https://onlinegdb.com/classroom/invite/Fd0aduv55>
2. 完成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:

{% code title="Person.java" %}

```java
public class Person
{
    // instance variables
    private String name;
    private String email;
    private String phoneNumber;

    // constructor: construct a Person copying in the data into the instance
    // variables
    public Person(String initName, String initEmail, String initPhone)
    {
        name = initName;
        email = initEmail;
        phoneNumber = initPhone;
    }

    // Print all the data for a person
    public void print()
    {
        System.out.println("Name: " + name);
        System.out.println("Email: " + email);
        System.out.println("Phone Number: " + phoneNumber);
    }
    
    //To be implement in Exercise 1
    public boolean isValidEmail() {
        return false;
    }
}
```

{% endcode %}

#### Exercise1: Validate person's email

The '@' symbol is a crucial component of the syntax for email addresses. According to the standard format,&#x20;

&#x20;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.

<mark style="color:red;">Your task is to add a method</mark> <mark style="color:red;"></mark>*<mark style="color:red;">isValidEmail()</mark>* <mark style="color:red;"></mark><mark style="color:red;">to this class that checks if the person's email contains the '@' .</mark> This method should return `true` if the email contains '@', and `false` otherwise.

The method signature should be:

`public boolean isValidEmail()`&#x20;

#### Exercise 2: Test your Person Class.&#x20;

Create a driver class. Paste the code here. Create the following two Person Objects in the driver class.&#x20;

```java
public class Main {
    public static void main(String[] args)
    {
        // call the constructor to create a new person
        Person p1 = new Person("Sana", "sana@gmail.com", "123-456-7890");
        // call p1's print method
        p1.print();
        
        Person p2 = new Person("Jean", "jean@gmail.com", "404 899-9955");
        p2.print();
        
        Person p3 = new Person("X", "xyz", "xxx");
        
        System.out.println(p1.isValidEmail());
        System.out.println(p3.isValidEmail());
    }
}

```

Click test, then you can see the result.&#x20;

#### When you are ready, submit your code.&#x20;
