Assignment problems:

Write Java programs for each of the following.
1. Students in a university class are being organized into groups of three for
an upcoming research project. To model this situation:

a. Write a Student class that stores the name, email address and phone
number of a single student. Include two constructors - one that allows
initial values to be set for each of these attributes via parameters and a
second that simply initializes the attributes to empty strings. Your class
should have getter and setter methods for all attributes as well as a
toString method that returns all information about the student in a nicely
formatted string.

b. Write a Group class to collect the three students comprising a group.
Your class should have a single getter and a single setter method to get or
set a particular student. Note that the caller will indicate which student
(1,2 or 3) is to be gotten or set via a parameter. Also include a simple
constructor that sets the three students to null and a toString method that
returns all information about all students in the group.

c. Write a driver class to create a couple of groups, populate them with
students and test your methods.

Sure! Here's a step-by-step guide on how to write the Java programs for each of the given components:

1. Start by creating a new Java file named "Student.java".

a. In the "Student" class, declare private instance variables for the name, email address, and phone number:
```java
private String name;
private String email;
private String phoneNumber;
```

b. Implement two constructors for the "Student" class. The first constructor will have parameters to set the initial attribute values, while the second constructor will initialize the attributes to empty strings:
```java
public Student(String name, String email, String phoneNumber) {
this.name = name;
this.email = email;
this.phoneNumber = phoneNumber;
}

public Student() {
this.name = "";
this.email = "";
this.phoneNumber = "";
}
```

c. Create getter and setter methods for all the attributes:
```java
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
```

d. Implement the "toString" method to return all information about the student in a nicely formatted string:
```java
@Override
public String toString() {
return "Name: " + name + "\nEmail: " + email + "\nPhone Number: " + phoneNumber;
}
```

2. Create a new Java file named "Group.java".

a. In the "Group" class, declare three private instance variables to represent the individual students:
```java
private Student student1;
private Student student2;
private Student student3;
```

b. Implement a simple constructor that sets the three students to null:
```java
public Group() {
this.student1 = null;
this.student2 = null;
this.student3 = null;
}
```

c. Create a getter and setter method to get or set a particular student (1, 2, or 3) via a parameter:
```java
public Student getStudent(int studentNumber) {
switch (studentNumber) {
case 1:
return student1;
case 2:
return student2;
case 3:
return student3;
default:
return null;
}
}

public void setStudent(int studentNumber, Student student) {
switch (studentNumber) {
case 1:
student1 = student;
break;
case 2:
student2 = student;
break;
case 3:
student3 = student;
break;
}
}
```

d. Implement the "toString" method to return all information about all students in the group:
```java
@Override
public String toString() {
return "Student 1:\n" + student1.toString() + "\n\nStudent 2:\n" + student2.toString() + "\n\nStudent 3:\n" + student3.toString();
}
```

3. Create a new Java file named "Driver.java".

a. In the "Driver" class, create a main method for testing purposes:
```java
public class Driver {
public static void main(String[] args) {
// Create student objects
Student student1 = new Student("John", "john", "123456789");
Student student2 = new Student("Alice", "alice", "987654321");
Student student3 = new Student("Bob", "bob", "456123789");

// Create group objects
Group group1 = new Group();
Group group2 = new Group();

// Populate groups with students
group1.setStudent(1, student1);
group1.setStudent(2, student2);
group1.setStudent(3, student3);

group2.setStudent(1, student3);
group2.setStudent(2, student1);
group2.setStudent(3, student2);

// Test the methods
System.out.println("Group 1:\n" + group1.toString());
System.out.println("\nGroup 2:\n" + group2.toString());
}
}
```

That's it! You have successfully implemented the Java programs for the given assignment problems.

Sure! Here's an explanation of what the Java programs for each part of the assignment should look like:

1a. The Student class:
- Create a new Java class named "Student" with the necessary attributes (name, email address, and phone number).
- Implement two constructors: one with parameters for setting the values of the attributes, and another that initializes the attributes to empty strings.
- Provide getter and setter methods for each attribute to retrieve and modify the values.
- Override the toString() method to return all information about the student in a formatted string.

Here's an example implementation:

```java
public class Student {
private String name;
private String emailAddress;
private String phoneNumber;

public Student(String name, String emailAddress, String phoneNumber) {
this.name = name;
this.emailAddress = emailAddress;
this.phoneNumber = phoneNumber;
}

public Student() {
// Empty constructor
this.name = "";
this.emailAddress = "";
this.phoneNumber = "";
}

// Getter methods
public String getName() {
return name;
}

public String getEmailAddress() {
return emailAddress;
}

public String getPhoneNumber() {
return phoneNumber;
}

// Setter methods
public void setName(String name) {
this.name = name;
}

public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

// toString method
@Override
public String toString() {
return "Name: " + name + "\nEmail Address: " + emailAddress + "\nPhone Number: " + phoneNumber;
}
}
```

1b. The Group class:
- Create another Java class named "Group" to represent a group of three students.
- Define private attributes to store the three students.
- Implement a constructor that initializes the three students to null.
- Provide getter and setter methods to get or set a particular student.
- Override the toString() method to return all information about all students in the group.

Here's an example implementation:

```java
public class Group {
private Student student1;
private Student student2;
private Student student3;

public Group() {
student1 = null;
student2 = null;
student3 = null;
}

// Getter and setter methods for each student
public Student getStudent1() {
return student1;
}

public void setStudent1(Student student1) {
this.student1 = student1;
}

public Student getStudent2() {
return student2;
}

public void setStudent2(Student student2) {
this.student2 = student2;
}

public Student getStudent3() {
return student3;
}

public void setStudent3(Student student3) {
this.student3 = student3;
}

// toString method
@Override
public String toString() {
String groupInfo = "Group Information\n";
groupInfo += "Student 1:\n" + student1.toString() + "\n";
groupInfo += "Student 2:\n" + student2.toString() + "\n";
groupInfo += "Student 3:\n" + student3.toString() + "\n";
return groupInfo;
}
}
```

1c. The driver class:
- Create a new Java class named "Driver" to test the Student and Group classes.
- Instantiate a few Student objects with different attribute values.
- Instantiate a Group object.
- Use the appropriate setter methods to assign the Student objects to the Group object.
- Print the Group object using the toString() method to verify the results.

Here's an example implementation:

```java
public class Driver {
public static void main(String[] args) {
Student student1 = new Student("John", "john", "1234567890");
Student student2 = new Student("Jane", "jane", "9876543210");
Student student3 = new Student("Bob", "bob", "5555555555");

Group group = new Group();
group.setStudent1(student1);
group.setStudent2(student2);
group.setStudent3(student3);

System.out.println(group.toString());
}
}
```

That's it! This should cover the requirements for each part of the assignment. Let me know if you have any further questions.