Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
package com.test;public class Team { private String teamId;.pdf
1. package com.test;
public class Team {
private String teamId;
private String teamName;
private String pFirstName;
private String pLastName;
private String pemail;
private String phoneNumber;
public String getTeamId() {
return teamId;
}
public void setTeamId(String teamId) {
this.teamId = teamId;
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
public String getpFirstName() {
return pFirstName;
}
public void setpFirstName(String pFirstName) {
this.pFirstName = pFirstName;
}
public String getpLastName() {
return pLastName;
}
public void setpLastName(String pLastName) {
this.pLastName = pLastName;
}
public String getPemail() {
return pemail;
}
2. public void setPemail(String pemail) {
this.pemail = pemail;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String toString() {
return "Team [teamId=" + teamId + ", teamName=" + teamName
+ ", pFirstName=" + pFirstName + ", pLastName=" + pLastName
+ ", pemail=" + pemail + ", phoneNumber=" + phoneNumber + "]";
}
public Team(String teamId, String teamName, String pFirstName,
String pLastName, String pemail, String phoneNumber) {
super();
this.teamId = teamId;
this.teamName = teamName;
this.pFirstName = pFirstName;
this.pLastName = pLastName;
this.pemail = pemail;
this.phoneNumber = phoneNumber;
}
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((pFirstName == null) ? 0 : pFirstName.hashCode());
result = prime * result
+ ((pLastName == null) ? 0 : pLastName.hashCode());
result = prime * result + ((pemail == null) ? 0 : pemail.hashCode());
result = prime * result
+ ((phoneNumber == null) ? 0 : phoneNumber.hashCode());
3. result = prime * result + ((teamId == null) ? 0 : teamId.hashCode());
result = prime * result
+ ((teamName == null) ? 0 : teamName.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Team other = (Team) obj;
if (pFirstName == null) {
if (other.pFirstName != null)
return false;
} else if (!pFirstName.equals(other.pFirstName))
return false;
if (pLastName == null) {
if (other.pLastName != null)
return false;
} else if (!pLastName.equals(other.pLastName))
return false;
if (pemail == null) {
if (other.pemail != null)
return false;
} else if (!pemail.equals(other.pemail))
return false;
if (phoneNumber == null) {
if (other.phoneNumber != null)
return false;
} else if (!phoneNumber.equals(other.phoneNumber))
return false;
if (teamId == null) {
if (other.teamId != null)
4. return false;
} else if (!teamId.equals(other.teamId))
return false;
if (teamName == null) {
if (other.teamName != null)
return false;
} else if (!teamName.equals(other.teamName))
return false;
return true;
}
}
package com.test;
import java.util.Date;
public class Game {
private String gameId;
private String teamId;
private String guestTeamId;
private Date gameDate;// yyyymmdd
private int homeTeamScore;
private int guestTeamScore;
public Game(String gameId, String teamId, String guestTeamId,
Date gameDate, int homeTeamScore, int guestTeamScore) {
super();
this.gameId = gameId;
this.teamId = teamId;
this.guestTeamId = guestTeamId;
this.gameDate = gameDate;
this.homeTeamScore = homeTeamScore;
this.guestTeamScore = guestTeamScore;
}
public String toString() {
return "Game [gameId=" + gameId + ", teamId=" + teamId
+ ", guestTeamId=" + guestTeamId + ", gameDate=" + gameDate
5. + ", homeTeamScore=" + homeTeamScore + ", guestTeamScore="
+ guestTeamScore + "]";
}
public String getGameId() {
return gameId;
}
public void setGameId(String gameId) {
this.gameId = gameId;
}
public String getTeamId() {
return teamId;
}
public void setTeamId(String teamId) {
this.teamId = teamId;
}
public String getGuestTeamId() {
return guestTeamId;
}
public void setGuestTeamId(String guestTeamId) {
this.guestTeamId = guestTeamId;
}
public Date getGameDate() {
return gameDate;
}
public void setGameDate(Date gameDate) {
this.gameDate = gameDate;
}
public int getHomeTeamScore() {
return homeTeamScore;
}
public void setHomeTeamScore(int homeTeamScore) {
this.homeTeamScore = homeTeamScore;
}
public int getGuestTeamScore() {
return guestTeamScore;
}
6. public void setGuestTeamScore(int guestTeamScore) {
this.guestTeamScore = guestTeamScore;
}
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((gameDate == null) ? 0 : gameDate.hashCode());
result = prime * result + ((gameId == null) ? 0 : gameId.hashCode());
result = prime * result
+ ((guestTeamId == null) ? 0 : guestTeamId.hashCode());
result = prime * result + guestTeamScore;
result = prime * result + homeTeamScore;
result = prime * result + ((teamId == null) ? 0 : teamId.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Game other = (Game) obj;
if (gameDate == null) {
if (other.gameDate != null)
return false;
} else if (!gameDate.equals(other.gameDate))
return false;
if (gameId == null) {
if (other.gameId != null)
return false;
} else if (!gameId.equals(other.gameId))
return false;
7. if (guestTeamId == null) {
if (other.guestTeamId != null)
return false;
} else if (!guestTeamId.equals(other.guestTeamId))
return false;
if (guestTeamScore != other.guestTeamScore)
return false;
if (homeTeamScore != other.homeTeamScore)
return false;
if (teamId == null) {
if (other.teamId != null)
return false;
} else if (!teamId.equals(other.teamId))
return false;
return true;
}
}
package com.test;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Test {
public static boolean findEmailtoSearch(Team team)
{
String stringToSearch =team.getPemail();
System.out.println(stringToSearch);
Pattern p = Pattern.compile("(at sign)"); // the pattern to search for
8. Matcher m = p.matcher(stringToSearch);
// now try to find at least one match
if (m.find())
{
System.out.println("Found a match");
return true;
}
else
{
System.out.println("Did not find a match");
return false;
}
}
public void textFileReadingExample() throws Throwable {
FileReader reader = new FileReader("D://MyFile.txt");
BufferedReader bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
reader.close();
}
/**
* This program demonstrates how to write characters to a text file using
* a specified charset.
*
public void textFileWritingExample() throws IOException{
FileOutputStream outputStream = new FileOutputStream("D://MyFile.txt");
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, "UTF-
16");
BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
bufferedWriter.write("TEAM,teamId,teamName,firstName,lastName,phoneNumber,email");
bufferedWriter.newLine();
10. Found a match
true
roadrunne(at sign)gmail.com
Found a match
true
Solution
package com.test;
public class Team {
private String teamId;
private String teamName;
private String pFirstName;
private String pLastName;
private String pemail;
private String phoneNumber;
public String getTeamId() {
return teamId;
}
public void setTeamId(String teamId) {
this.teamId = teamId;
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
public String getpFirstName() {
return pFirstName;
}
public void setpFirstName(String pFirstName) {
this.pFirstName = pFirstName;
}
public String getpLastName() {
return pLastName;
11. }
public void setpLastName(String pLastName) {
this.pLastName = pLastName;
}
public String getPemail() {
return pemail;
}
public void setPemail(String pemail) {
this.pemail = pemail;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String toString() {
return "Team [teamId=" + teamId + ", teamName=" + teamName
+ ", pFirstName=" + pFirstName + ", pLastName=" + pLastName
+ ", pemail=" + pemail + ", phoneNumber=" + phoneNumber + "]";
}
public Team(String teamId, String teamName, String pFirstName,
String pLastName, String pemail, String phoneNumber) {
super();
this.teamId = teamId;
this.teamName = teamName;
this.pFirstName = pFirstName;
this.pLastName = pLastName;
this.pemail = pemail;
this.phoneNumber = phoneNumber;
}
public int hashCode() {
final int prime = 31;
int result = 1;
12. result = prime * result
+ ((pFirstName == null) ? 0 : pFirstName.hashCode());
result = prime * result
+ ((pLastName == null) ? 0 : pLastName.hashCode());
result = prime * result + ((pemail == null) ? 0 : pemail.hashCode());
result = prime * result
+ ((phoneNumber == null) ? 0 : phoneNumber.hashCode());
result = prime * result + ((teamId == null) ? 0 : teamId.hashCode());
result = prime * result
+ ((teamName == null) ? 0 : teamName.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Team other = (Team) obj;
if (pFirstName == null) {
if (other.pFirstName != null)
return false;
} else if (!pFirstName.equals(other.pFirstName))
return false;
if (pLastName == null) {
if (other.pLastName != null)
return false;
} else if (!pLastName.equals(other.pLastName))
return false;
if (pemail == null) {
if (other.pemail != null)
return false;
} else if (!pemail.equals(other.pemail))
return false;
13. if (phoneNumber == null) {
if (other.phoneNumber != null)
return false;
} else if (!phoneNumber.equals(other.phoneNumber))
return false;
if (teamId == null) {
if (other.teamId != null)
return false;
} else if (!teamId.equals(other.teamId))
return false;
if (teamName == null) {
if (other.teamName != null)
return false;
} else if (!teamName.equals(other.teamName))
return false;
return true;
}
}
package com.test;
import java.util.Date;
public class Game {
private String gameId;
private String teamId;
private String guestTeamId;
private Date gameDate;// yyyymmdd
private int homeTeamScore;
private int guestTeamScore;
public Game(String gameId, String teamId, String guestTeamId,
Date gameDate, int homeTeamScore, int guestTeamScore) {
super();
this.gameId = gameId;
this.teamId = teamId;
this.guestTeamId = guestTeamId;
this.gameDate = gameDate;
14. this.homeTeamScore = homeTeamScore;
this.guestTeamScore = guestTeamScore;
}
public String toString() {
return "Game [gameId=" + gameId + ", teamId=" + teamId
+ ", guestTeamId=" + guestTeamId + ", gameDate=" + gameDate
+ ", homeTeamScore=" + homeTeamScore + ", guestTeamScore="
+ guestTeamScore + "]";
}
public String getGameId() {
return gameId;
}
public void setGameId(String gameId) {
this.gameId = gameId;
}
public String getTeamId() {
return teamId;
}
public void setTeamId(String teamId) {
this.teamId = teamId;
}
public String getGuestTeamId() {
return guestTeamId;
}
public void setGuestTeamId(String guestTeamId) {
this.guestTeamId = guestTeamId;
}
public Date getGameDate() {
return gameDate;
}
public void setGameDate(Date gameDate) {
this.gameDate = gameDate;
}
public int getHomeTeamScore() {
return homeTeamScore;
15. }
public void setHomeTeamScore(int homeTeamScore) {
this.homeTeamScore = homeTeamScore;
}
public int getGuestTeamScore() {
return guestTeamScore;
}
public void setGuestTeamScore(int guestTeamScore) {
this.guestTeamScore = guestTeamScore;
}
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((gameDate == null) ? 0 : gameDate.hashCode());
result = prime * result + ((gameId == null) ? 0 : gameId.hashCode());
result = prime * result
+ ((guestTeamId == null) ? 0 : guestTeamId.hashCode());
result = prime * result + guestTeamScore;
result = prime * result + homeTeamScore;
result = prime * result + ((teamId == null) ? 0 : teamId.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Game other = (Game) obj;
if (gameDate == null) {
if (other.gameDate != null)
return false;
16. } else if (!gameDate.equals(other.gameDate))
return false;
if (gameId == null) {
if (other.gameId != null)
return false;
} else if (!gameId.equals(other.gameId))
return false;
if (guestTeamId == null) {
if (other.guestTeamId != null)
return false;
} else if (!guestTeamId.equals(other.guestTeamId))
return false;
if (guestTeamScore != other.guestTeamScore)
return false;
if (homeTeamScore != other.homeTeamScore)
return false;
if (teamId == null) {
if (other.teamId != null)
return false;
} else if (!teamId.equals(other.teamId))
return false;
return true;
}
}
package com.test;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Test {
17. public static boolean findEmailtoSearch(Team team)
{
String stringToSearch =team.getPemail();
System.out.println(stringToSearch);
Pattern p = Pattern.compile("(at sign)"); // the pattern to search for
Matcher m = p.matcher(stringToSearch);
// now try to find at least one match
if (m.find())
{
System.out.println("Found a match");
return true;
}
else
{
System.out.println("Did not find a match");
return false;
}
}
public void textFileReadingExample() throws Throwable {
FileReader reader = new FileReader("D://MyFile.txt");
BufferedReader bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
reader.close();
}
/**
* This program demonstrates how to write characters to a text file using
* a specified charset.
*
18. public void textFileWritingExample() throws IOException{
FileOutputStream outputStream = new FileOutputStream("D://MyFile.txt");
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, "UTF-
16");
BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
bufferedWriter.write("TEAM,teamId,teamName,firstName,lastName,phoneNumber,email");
bufferedWriter.newLine();
bufferedWriter.write("TEAM,1,Road Runner,David,Brown,303-123-4567,roadrunner(at
sign)gmail.com");
bufferedWriter.newLine();
bufferedWriter.write("GAME,gameId,homeTeamId,guestTeamId,gameDate,homeTeamScore,g
uestTeamScore");
bufferedWriter.newLine();
bufferedWriter.write("GAME,101,1,2,20160105,4,3");
bufferedWriter.close();
}
/**
* Find out if a String contains a very simple pattern.
*/
public static void main(String[] args) throws Throwable
{
Team team=new Team("1","Road Runner","Joe","Doe",
"roadrunner(at sign)gmail.com","(303) 123-4599");
Team team1 = new Team("1","Road Runner","Joe","Doe",
"roadrunne(at sign)gmail.com","(303) 123-4599");
Game game=new Game("101","1","2",new Date(),4,3);
System.out.println(game);
boolean flag= Test.findEmailtoSearch(team);
System.out.println(flag);
boolean flag1= Test.findEmailtoSearch(team1);
System.out.println(flag1);
Test test=new Test();
test.textFileWritingExample();