n Chapter 4 Exercise 5, you created a class named Game that included two Team objects that held data about teams participating in a game. Modify the Game class to set the game time to the message Game cancelled! if the two teams in a game do not have the same value for the sport. (In other words, a girls’ basketball team should not have a game scheduled with a boys’ tennis team.) Write a program to demonstrate a valid and an invalid game.

I'm sorry, as an AI language model, I do not have access to previous exercises and cannot write programs, but I can give you an explanation of how to modify the Game class.

To modify the Game class, you can add an if statement to check if the two teams have the same value for the sport. If they don't, set the game time to "Game cancelled!" using the setTime method. The code might look something like this:

```
public class Game {
private Team team1;
private Team team2;
private String gameTime;

public Game(Team t1, Team t2) {
this.team1 = t1;
this.team2 = t2;
if(t1.getSport().equals(t2.getSport())) {
this.gameTime = "TBD";
} else {
this.gameTime = "Game cancelled!";
}
}

public void setTime(String time) {
this.gameTime = time;
}

public String getTime() {
return this.gameTime;
}
}
```

To demonstrate a valid and an invalid game, you can create two instances of the Team class with different sports and pass them as arguments to the Game constructor. Then, you can call the getTime method to see the game time. For example:

```
Team t1 = new Team("Girls basketball");
Team t2 = new Team("Boys tennis");

Game game1 = new Game(t1, t1); // valid game between two girls basketball teams
System.out.println(game1.getTime()); // Output: TBD

Game game2 = new Game(t1, t2); // invalid game between girls basketball and boys tennis
System.out.println(game2.getTime()); // Output: Game cancelled!
```

To modify the Game class, you can add a condition checking if the two teams have the same value for the sport. If they do not have the same sport, set the game time to "Game cancelled!" Here's an example of how you can modify the Game class:

```python
class Team:
def __init__(self, name, sport):
self.name = name
self.sport = sport

class Game:
def __init__(self, team1, team2, time):
self.team1 = team1
self.team2 = team2
if team1.sport != team2.sport:
self.time = "Game cancelled!"
else:
self.time = time

# Demonstration of a valid game
team1 = Team("Girls' Basketball Team", "Basketball")
team2 = Team("Boys' Basketball Team", "Basketball")
game = Game(team1, team2, "12:00 PM")
print(game.time) # Output: 12:00 PM

# Demonstration of an invalid game
team3 = Team("Girls' Basketball Team", "Basketball")
team4 = Team("Boys' Tennis Team", "Tennis")
game_cancelled = Game(team3, team4, "3:00 PM")
print(game_cancelled.time) # Output: Game cancelled!
```

In this example, we create two instances of the Team class with different sports (Basketball and Tennis). When we create a new instance of the Game class, we first check if the sports of the two teams are the same. If they are not the same, we set the game time to "Game cancelled!". Otherwise, we set it to the provided time.

Finally, we demonstrate a valid game by creating two instances of the Team class with the same sport (Basketball), and an invalid game by creating instances with different sports (Basketball and Tennis). We print the game time in both cases to verify the output.