SlideShare a Scribd company logo
public class Team {
//Attributes
private String teamId;
private String name;
private String firstName;
private String lastName;
private String phone;
private String email;
/**
* Constructor
* param teamId
* param name
* param firstName
* param lastName
* param phone
* param email
*/
public Team(String teamId, String name, String firstName, String lastName, String phone,
String email) {
this.teamId = teamId;
this.name = name;
this.firstName = firstName;
this.lastName = lastName;
this.phone = phone;
this.email = email;
}
/**
* return the teamId
*/
public String getTeamId() {
return teamId;
}
/**
* return the name
*/
public String getName() {
return name;
}
/**
* return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* return the phone
*/
public String getPhone() {
return phone;
}
/**
* return the email
*/
public String getEmail() {
return email;
}
Override
public String toString() {
return "Team {teamId=" + teamId + ", name=" + name + ", firstName=" + firstName + ",
lastName=" + lastName
+ ", phone=" + phone + ", email=" + email + "}";
}
Override
public boolean equals(Object obj) {
if(obj == null)
return false;
else {
if(!(obj instanceof Team))
return false;
else {
Team other = (Team)obj;
if(this.teamId.equalsIgnoreCase(other.teamId) &&
this.name.equalsIgnoreCase(other.name) &&
this.firstName.equalsIgnoreCase(other.firstName) &&
this.lastName.equalsIgnoreCase(other.lastName) &&
this.phone.equalsIgnoreCase(other.phone) &&
this.email.equalsIgnoreCase(other.email))
return true;
else
return false;
}
}
}
/**
* Checks if the email id contains "(at sign)".
* Is yes returns true else returns false
*/
public boolean isValidEmail() {
return this.email.contains("(at sign)");
}
}
public class Game {
//Attributes
private String gameID;
private String homeTeamId;
private String guestTeamId;
private String gameDate;
private int homeTeamScore;
private int guestTeamScore;
/**
* Constructor
* param gameID
* param homeTeamId
* param guestTeamId
* param gameDate
* param homeTeamScore
* param guestTeamScore
*/
public Game(String gameID, String homeTeamId, String guestTeamId, String gameDate, int
homeTeamScore,
int guestTeamScore) {
this.gameID = gameID;
this.homeTeamId = homeTeamId;
this.guestTeamId = guestTeamId;
this.gameDate = gameDate;
this.homeTeamScore = homeTeamScore;
this.guestTeamScore = guestTeamScore;
}
/**
* return the gameID
*/
public String getGameID() {
return gameID;
}
/**
* return the homeTeamId
*/
public String getHomeTeamId() {
return homeTeamId;
}
/**
* return the guestTeamId
*/
public String getGuestTeamId() {
return guestTeamId;
}
/**
* return the gameDate
*/
public String getGameDate() {
return gameDate;
}
/**
* return the homeTeamScore
*/
public int getHomeTeamScore() {
return homeTeamScore;
}
/**
* return the guestTeamScore
*/
public int getGuestTeamScore() {
return guestTeamScore;
}
Override
public String toString() {
return "Game {gameID=" + gameID + ", homeTeamId=" + homeTeamId + ",
guestTeamId=" + guestTeamId + ", gameDate="
+ gameDate + ", homeTeamScore=" + homeTeamScore + ", guestTeamScore=" +
guestTeamScore + "}";
}
Override
public boolean equals(Object obj) {
if(obj == null)
return false;
else {
if(!(obj instanceof Game))
return false;
else {
Game other = (Game)obj;
if(this.gameID.equalsIgnoreCase(other.gameID) &&
this.homeTeamId.equalsIgnoreCase(other.homeTeamId) &&
this.guestTeamId.equalsIgnoreCase(other.guestTeamId) &&
this.gameDate.equalsIgnoreCase(other.gameDate) &&
(this.homeTeamScore == other.homeTeamScore) &&
(this.guestTeamScore == other.guestTeamScore))
return true;
else
return false;
}
}
}
/**
* Checks if the game date is between 20160101 and 20160531
* If yes return true or return false
*/
public boolean isValidDate() {
int date = Integer.parseInt(gameDate);
return ((20160101 <= date) && (date <= 20160531));
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Test {
/**
* Creates a Team object with the parameter passed and returns it
* param teamId
* param name
* param firstName
* param lastName
* param phone
* param email
* return
*/
public static Team setTeamAttribute(String teamId, String name, String firstName, String
lastName, String phone, String email) {
return new Team(teamId, name, firstName, lastName, phone, email);
}
/**
* Creates a Game object with the parameter passed and returns it
* param gameID
* param homeTeamId
* param guestTeamId
* param gameDate
* param homeTeamScore
* param guestTeamScore
* return
*/
public static Game setGameAttribute(String gameID, String homeTeamId, String guestTeamId,
String gameDate, int homeTeamScore,
int guestTeamScore) {
return new Game(gameID, homeTeamId, guestTeamId, gameDate, homeTeamScore,
guestTeamScore);
}
public static void main(String[] args) {
//Input file
final String INPUT_FILENAME = "input/hw1input.txt";
//Test 1a
System.out.println("RUNNING TEST 1a");
Team team1 = new Team("1", "Team1", "Ann", "Matt", "123456", "abcxyz.com");
System.out.println(team1);
//Test 1b
System.out.println();
System.out.println("RUNNING TEST 1b");
Game game1 = new Game("101", "Home Team", "Guest Team", "20160303", 12, 18);
System.out.println(game1);
//Open input file
Scanner input = null;
Team team2 = null;
Game game2 = null;
try {
input = new Scanner(new File(INPUT_FILENAME));
//Read first line
String[] inputDtls = input.nextLine().split(",");
//Test 2a
if(inputDtls[0].equalsIgnoreCase("TEAM")) {
System.out.println();
System.out.println("RUNNING TEST 2a");
team2 = setTeamAttribute(inputDtls[1], inputDtls[2], inputDtls[3], inputDtls[4], inputDtls[5],
inputDtls[6]);
if(!team2.isValidEmail())
System.err.println("ERROR: Invalid email address. Is missing (at sign): " +
team2.getEmail());
//Display team1 attributes
System.out.println(team2.getTeamId());
System.out.println(team2.getName());
System.out.println(team2.getFirstName());
System.out.println(team2.getLastName());
System.out.println(team2.getPhone());
System.out.println(team2.getEmail());
}
//Read second line
inputDtls = input.nextLine().split(",");
//Test 2b
if(inputDtls[0].equalsIgnoreCase("GAME")) {
System.out.println();
System.out.println("RUNNING TEST 2b");
game2 = setGameAttribute(inputDtls[1], inputDtls[2], inputDtls[3], inputDtls[4],
Integer.parseInt(inputDtls[5]), Integer.parseInt(inputDtls[6]));
if(!game2.isValidDate())
System.err.println("ERROR: Invalid game date: " + game2.getGameDate());
//Display team attributes
System.out.println(game2.getGameID());
System.out.println(game2.getHomeTeamId());
System.out.println(game2.getGuestTeamId());
System.out.println(game2.getGameDate());
System.out.println(game2.getHomeTeamScore());
System.out.println(game2.getGuestTeamScore());
}
} catch(FileNotFoundException fnfe) {
System.err.println("Data file not found");
} finally {
//Close file
if(input != null)
input.close();
}
//Test 3a
System.out.println();
System.out.println("RUNNING TEST 3a");
System.out.println("TEAM 1 : " + team1);
System.out.println("TEAM 2 : " + team2);
if(team1.equals(team2))
System.out.println("The two teams are same");
else
System.out.println("The two teams not are same");
//Test 3b
System.out.println();
System.out.println("RUNNING TEST 3b");
System.out.println("GAME 1 : " + game1);
System.out.println("GAME 2 : " + game2);
if(game1.equals(game2))
System.out.println("The two games are same");
else
System.out.println("The two games not are same");
}
}
SAMPLE OUTPUT:
RUNNING TEST 1a
Team {teamId=1, name=Team1, firstName=Ann, lastName=Matt, phone=123456,
email=abcxyz.com}
RUNNING TEST 1b
Game {gameID=101, homeTeamId=Home Team, guestTeamId=Guest Team,
gameDate=20160303, homeTeamScore=12, guestTeamScore=18}
RUNNING TEST 2a
ERROR: Invalid email address. Is missing (at sign): roadrunner#gmail.com
1
Road Runner
David
Brown
303-123-4567
roadrunner#gmail.com
RUNNING TEST 2b
ERROR: Invalid game date: 20150105
101
1
2
20150105
4
3
RUNNING TEST 3a
TEAM 1 : Team {teamId=1, name=Team1, firstName=Ann, lastName=Matt, phone=123456,
email=abcxyz.com}
TEAM 2 : Team {teamId=1, name=Road Runner, firstName=David, lastName=Brown,
phone=303-123-4567, email=roadrunner#gmail.com}
The two teams not are same
RUNNING TEST 3b
GAME 1 : Game {gameID=101, homeTeamId=Home Team, guestTeamId=Guest Team,
gameDate=20160303, homeTeamScore=12, guestTeamScore=18}
GAME 2 : Game {gameID=101, homeTeamId=1, guestTeamId=2, gameDate=20150105,
homeTeamScore=4, guestTeamScore=3}
The two games not are same
Solution
public class Team {
//Attributes
private String teamId;
private String name;
private String firstName;
private String lastName;
private String phone;
private String email;
/**
* Constructor
* param teamId
* param name
* param firstName
* param lastName
* param phone
* param email
*/
public Team(String teamId, String name, String firstName, String lastName, String phone,
String email) {
this.teamId = teamId;
this.name = name;
this.firstName = firstName;
this.lastName = lastName;
this.phone = phone;
this.email = email;
}
/**
* return the teamId
*/
public String getTeamId() {
return teamId;
}
/**
* return the name
*/
public String getName() {
return name;
}
/**
* return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* return the phone
*/
public String getPhone() {
return phone;
}
/**
* return the email
*/
public String getEmail() {
return email;
}
Override
public String toString() {
return "Team {teamId=" + teamId + ", name=" + name + ", firstName=" + firstName + ",
lastName=" + lastName
+ ", phone=" + phone + ", email=" + email + "}";
}
Override
public boolean equals(Object obj) {
if(obj == null)
return false;
else {
if(!(obj instanceof Team))
return false;
else {
Team other = (Team)obj;
if(this.teamId.equalsIgnoreCase(other.teamId) &&
this.name.equalsIgnoreCase(other.name) &&
this.firstName.equalsIgnoreCase(other.firstName) &&
this.lastName.equalsIgnoreCase(other.lastName) &&
this.phone.equalsIgnoreCase(other.phone) &&
this.email.equalsIgnoreCase(other.email))
return true;
else
return false;
}
}
}
/**
* Checks if the email id contains "(at sign)".
* Is yes returns true else returns false
*/
public boolean isValidEmail() {
return this.email.contains("(at sign)");
}
}
public class Game {
//Attributes
private String gameID;
private String homeTeamId;
private String guestTeamId;
private String gameDate;
private int homeTeamScore;
private int guestTeamScore;
/**
* Constructor
* param gameID
* param homeTeamId
* param guestTeamId
* param gameDate
* param homeTeamScore
* param guestTeamScore
*/
public Game(String gameID, String homeTeamId, String guestTeamId, String gameDate, int
homeTeamScore,
int guestTeamScore) {
this.gameID = gameID;
this.homeTeamId = homeTeamId;
this.guestTeamId = guestTeamId;
this.gameDate = gameDate;
this.homeTeamScore = homeTeamScore;
this.guestTeamScore = guestTeamScore;
}
/**
* return the gameID
*/
public String getGameID() {
return gameID;
}
/**
* return the homeTeamId
*/
public String getHomeTeamId() {
return homeTeamId;
}
/**
* return the guestTeamId
*/
public String getGuestTeamId() {
return guestTeamId;
}
/**
* return the gameDate
*/
public String getGameDate() {
return gameDate;
}
/**
* return the homeTeamScore
*/
public int getHomeTeamScore() {
return homeTeamScore;
}
/**
* return the guestTeamScore
*/
public int getGuestTeamScore() {
return guestTeamScore;
}
Override
public String toString() {
return "Game {gameID=" + gameID + ", homeTeamId=" + homeTeamId + ",
guestTeamId=" + guestTeamId + ", gameDate="
+ gameDate + ", homeTeamScore=" + homeTeamScore + ", guestTeamScore=" +
guestTeamScore + "}";
}
Override
public boolean equals(Object obj) {
if(obj == null)
return false;
else {
if(!(obj instanceof Game))
return false;
else {
Game other = (Game)obj;
if(this.gameID.equalsIgnoreCase(other.gameID) &&
this.homeTeamId.equalsIgnoreCase(other.homeTeamId) &&
this.guestTeamId.equalsIgnoreCase(other.guestTeamId) &&
this.gameDate.equalsIgnoreCase(other.gameDate) &&
(this.homeTeamScore == other.homeTeamScore) &&
(this.guestTeamScore == other.guestTeamScore))
return true;
else
return false;
}
}
}
/**
* Checks if the game date is between 20160101 and 20160531
* If yes return true or return false
*/
public boolean isValidDate() {
int date = Integer.parseInt(gameDate);
return ((20160101 <= date) && (date <= 20160531));
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Test {
/**
* Creates a Team object with the parameter passed and returns it
* param teamId
* param name
* param firstName
* param lastName
* param phone
* param email
* return
*/
public static Team setTeamAttribute(String teamId, String name, String firstName, String
lastName, String phone, String email) {
return new Team(teamId, name, firstName, lastName, phone, email);
}
/**
* Creates a Game object with the parameter passed and returns it
* param gameID
* param homeTeamId
* param guestTeamId
* param gameDate
* param homeTeamScore
* param guestTeamScore
* return
*/
public static Game setGameAttribute(String gameID, String homeTeamId, String guestTeamId,
String gameDate, int homeTeamScore,
int guestTeamScore) {
return new Game(gameID, homeTeamId, guestTeamId, gameDate, homeTeamScore,
guestTeamScore);
}
public static void main(String[] args) {
//Input file
final String INPUT_FILENAME = "input/hw1input.txt";
//Test 1a
System.out.println("RUNNING TEST 1a");
Team team1 = new Team("1", "Team1", "Ann", "Matt", "123456", "abcxyz.com");
System.out.println(team1);
//Test 1b
System.out.println();
System.out.println("RUNNING TEST 1b");
Game game1 = new Game("101", "Home Team", "Guest Team", "20160303", 12, 18);
System.out.println(game1);
//Open input file
Scanner input = null;
Team team2 = null;
Game game2 = null;
try {
input = new Scanner(new File(INPUT_FILENAME));
//Read first line
String[] inputDtls = input.nextLine().split(",");
//Test 2a
if(inputDtls[0].equalsIgnoreCase("TEAM")) {
System.out.println();
System.out.println("RUNNING TEST 2a");
team2 = setTeamAttribute(inputDtls[1], inputDtls[2], inputDtls[3], inputDtls[4], inputDtls[5],
inputDtls[6]);
if(!team2.isValidEmail())
System.err.println("ERROR: Invalid email address. Is missing (at sign): " +
team2.getEmail());
//Display team1 attributes
System.out.println(team2.getTeamId());
System.out.println(team2.getName());
System.out.println(team2.getFirstName());
System.out.println(team2.getLastName());
System.out.println(team2.getPhone());
System.out.println(team2.getEmail());
}
//Read second line
inputDtls = input.nextLine().split(",");
//Test 2b
if(inputDtls[0].equalsIgnoreCase("GAME")) {
System.out.println();
System.out.println("RUNNING TEST 2b");
game2 = setGameAttribute(inputDtls[1], inputDtls[2], inputDtls[3], inputDtls[4],
Integer.parseInt(inputDtls[5]), Integer.parseInt(inputDtls[6]));
if(!game2.isValidDate())
System.err.println("ERROR: Invalid game date: " + game2.getGameDate());
//Display team attributes
System.out.println(game2.getGameID());
System.out.println(game2.getHomeTeamId());
System.out.println(game2.getGuestTeamId());
System.out.println(game2.getGameDate());
System.out.println(game2.getHomeTeamScore());
System.out.println(game2.getGuestTeamScore());
}
} catch(FileNotFoundException fnfe) {
System.err.println("Data file not found");
} finally {
//Close file
if(input != null)
input.close();
}
//Test 3a
System.out.println();
System.out.println("RUNNING TEST 3a");
System.out.println("TEAM 1 : " + team1);
System.out.println("TEAM 2 : " + team2);
if(team1.equals(team2))
System.out.println("The two teams are same");
else
System.out.println("The two teams not are same");
//Test 3b
System.out.println();
System.out.println("RUNNING TEST 3b");
System.out.println("GAME 1 : " + game1);
System.out.println("GAME 2 : " + game2);
if(game1.equals(game2))
System.out.println("The two games are same");
else
System.out.println("The two games not are same");
}
}
SAMPLE OUTPUT:
RUNNING TEST 1a
Team {teamId=1, name=Team1, firstName=Ann, lastName=Matt, phone=123456,
email=abcxyz.com}
RUNNING TEST 1b
Game {gameID=101, homeTeamId=Home Team, guestTeamId=Guest Team,
gameDate=20160303, homeTeamScore=12, guestTeamScore=18}
RUNNING TEST 2a
ERROR: Invalid email address. Is missing (at sign): roadrunner#gmail.com
1
Road Runner
David
Brown
303-123-4567
roadrunner#gmail.com
RUNNING TEST 2b
ERROR: Invalid game date: 20150105
101
1
2
20150105
4
3
RUNNING TEST 3a
TEAM 1 : Team {teamId=1, name=Team1, firstName=Ann, lastName=Matt, phone=123456,
email=abcxyz.com}
TEAM 2 : Team {teamId=1, name=Road Runner, firstName=David, lastName=Brown,
phone=303-123-4567, email=roadrunner#gmail.com}
The two teams not are same
RUNNING TEST 3b
GAME 1 : Game {gameID=101, homeTeamId=Home Team, guestTeamId=Guest Team,
gameDate=20160303, homeTeamScore=12, guestTeamScore=18}
GAME 2 : Game {gameID=101, homeTeamId=1, guestTeamId=2, gameDate=20150105,
homeTeamScore=4, guestTeamScore=3}
The two games not are same

More Related Content

PDF
Team public class Team {    private String teamId;    priva.pdf
PDF
Thanks so much for your help. Review the GameService class. Noti.pdf
PDF
package com.test;public class Team {    private String teamId;.pdf
PDF
VideoGamepublic class VideoGam.pdf
PPTX
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
PDF
Here is the game description- Here is the sample game- Here is the req.pdf
PDF
31 Coach class For this class you only need to implement .pdf
PDF
はじめてのGroovy
Team public class Team {    private String teamId;    priva.pdf
Thanks so much for your help. Review the GameService class. Noti.pdf
package com.test;public class Team {    private String teamId;.pdf
VideoGamepublic class VideoGam.pdf
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Here is the game description- Here is the sample game- Here is the req.pdf
31 Coach class For this class you only need to implement .pdf
はじめてのGroovy

Similar to public class Team {Attributes private String teamId; private.pdf (20)

PDF
Keep getting a null pointer exception for some odd reasonim creati.pdf
PDF
question.(player, entity ,field and base.java codes are given)Stop.pdf
PDF
public interface Game Note interface in place of class { .pdf
PDF
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
PDF
Here are the instructions and then the code in a sec. Please R.pdf
PDF
mainpublic class AssignmentThree {    public static void ma.pdf
PDF
Goal- Your goal in this assignment is to write a Java program that sim.pdf
PDF
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
PDF
I really need some help if I have this right so far. PLEASE CHANG.pdf
PDF
package com.tictactoe; public class Main {public void play() {.pdf
PDF
I really need some help if I have this right so far. Please Resub.pdf
PDF
@author public class Person{   String sname, .pdf
PDF
2024 PHPCon - Symfony background processing
PDF
Please use java to write the program that simulates the card game!!! T (1).pdf
PDF
Creating a Facebook Clone - Part XX.pdf
PDF
public class Storm {   Attributes    private String stormName;.pdf
DOCX
CS117-S18-AlharbiMohammed-master.gitignore.class.ctxt..docx
PDF
Mocks introduction
PDF
Create a Code that will add an Add, Edi, and Delete button to the GU.pdf
DOCX
TilePUzzle class Anderson, Franceschi public class TilePu.docx
Keep getting a null pointer exception for some odd reasonim creati.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdf
public interface Game Note interface in place of class { .pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here are the instructions and then the code in a sec. Please R.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
Goal- Your goal in this assignment is to write a Java program that sim.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdf
package com.tictactoe; public class Main {public void play() {.pdf
I really need some help if I have this right so far. Please Resub.pdf
@author public class Person{   String sname, .pdf
2024 PHPCon - Symfony background processing
Please use java to write the program that simulates the card game!!! T (1).pdf
Creating a Facebook Clone - Part XX.pdf
public class Storm {   Attributes    private String stormName;.pdf
CS117-S18-AlharbiMohammed-master.gitignore.class.ctxt..docx
Mocks introduction
Create a Code that will add an Add, Edi, and Delete button to the GU.pdf
TilePUzzle class Anderson, Franceschi public class TilePu.docx
Ad

More from anushasarees (20)

PDF
Properties of enantiomers Their NMR and IR spec.pdf
PDF
O2 will be released as Na+ will not get reduce bu.pdf
PDF
Huntingtons disease and other hereditary diseas.pdf
PDF
ionic character BaF MgO FeO SO2 N2 .pdf
PDF
Nitrogen can hold up to 4 bonds. In sodium amide.pdf
PDF
C. hydrogen bonding. between N and H of differen.pdf
PDF
  import java.util.;import acm.program.;public class FlightPla.pdf
PDF
We Know that    Amines are generally basic in naturebecause of th.pdf
PDF
There are so many java Input Output classes that are available in it.pdf
PDF
Three are ways to protect unused switch ports Option B,D and E is.pdf
PDF
The water turns green because the copper(II)sulfate is breaking apar.pdf
PDF
The mutation is known as inversion. In this a segment from one chrom.pdf
PDF
The main organelles in protein sorting and targeting are Rough endop.pdf
PDF
Successfully supporting managerial decision-making is critically dep.pdf
PDF
SolutionTo know that the team has identified all of the significa.pdf
PDF
Solutiona) Maximum bus speed = bus driver delay + propagation del.pdf
PDF
Solution Polymerase chain reaction is process in which several co.pdf
PDF
Doubling [NO] would quadruple the rate .pdf
PDF
Correct answer F)4.0 .pdf
PDF
D.) The system is neither at steady state or equi.pdf
Properties of enantiomers Their NMR and IR spec.pdf
O2 will be released as Na+ will not get reduce bu.pdf
Huntingtons disease and other hereditary diseas.pdf
ionic character BaF MgO FeO SO2 N2 .pdf
Nitrogen can hold up to 4 bonds. In sodium amide.pdf
C. hydrogen bonding. between N and H of differen.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf
We Know that    Amines are generally basic in naturebecause of th.pdf
There are so many java Input Output classes that are available in it.pdf
Three are ways to protect unused switch ports Option B,D and E is.pdf
The water turns green because the copper(II)sulfate is breaking apar.pdf
The mutation is known as inversion. In this a segment from one chrom.pdf
The main organelles in protein sorting and targeting are Rough endop.pdf
Successfully supporting managerial decision-making is critically dep.pdf
SolutionTo know that the team has identified all of the significa.pdf
Solutiona) Maximum bus speed = bus driver delay + propagation del.pdf
Solution Polymerase chain reaction is process in which several co.pdf
Doubling [NO] would quadruple the rate .pdf
Correct answer F)4.0 .pdf
D.) The system is neither at steady state or equi.pdf
Ad

Recently uploaded (20)

PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Classroom Observation Tools for Teachers
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Institutional Correction lecture only . . .
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Lesson notes of climatology university.
PPTX
master seminar digital applications in india
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
2.FourierTransform-ShortQuestionswithAnswers.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Complications of Minimal Access Surgery at WLH
Final Presentation General Medicine 03-08-2024.pptx
Classroom Observation Tools for Teachers
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Basic Mud Logging Guide for educational purpose
Institutional Correction lecture only . . .
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Sports Quiz easy sports quiz sports quiz
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Lesson notes of climatology university.
master seminar digital applications in india
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...

public class Team {Attributes private String teamId; private.pdf

  • 1. public class Team { //Attributes private String teamId; private String name; private String firstName; private String lastName; private String phone; private String email; /** * Constructor * param teamId * param name * param firstName * param lastName * param phone * param email */ public Team(String teamId, String name, String firstName, String lastName, String phone, String email) { this.teamId = teamId; this.name = name; this.firstName = firstName; this.lastName = lastName; this.phone = phone; this.email = email; } /** * return the teamId */ public String getTeamId() { return teamId; } /** * return the name */
  • 2. public String getName() { return name; } /** * return the firstName */ public String getFirstName() { return firstName; } /** * return the lastName */ public String getLastName() { return lastName; } /** * return the phone */ public String getPhone() { return phone; } /** * return the email */ public String getEmail() { return email; } Override public String toString() { return "Team {teamId=" + teamId + ", name=" + name + ", firstName=" + firstName + ", lastName=" + lastName + ", phone=" + phone + ", email=" + email + "}"; } Override public boolean equals(Object obj) {
  • 3. if(obj == null) return false; else { if(!(obj instanceof Team)) return false; else { Team other = (Team)obj; if(this.teamId.equalsIgnoreCase(other.teamId) && this.name.equalsIgnoreCase(other.name) && this.firstName.equalsIgnoreCase(other.firstName) && this.lastName.equalsIgnoreCase(other.lastName) && this.phone.equalsIgnoreCase(other.phone) && this.email.equalsIgnoreCase(other.email)) return true; else return false; } } } /** * Checks if the email id contains "(at sign)". * Is yes returns true else returns false */ public boolean isValidEmail() { return this.email.contains("(at sign)"); } } public class Game { //Attributes private String gameID; private String homeTeamId; private String guestTeamId; private String gameDate; private int homeTeamScore;
  • 4. private int guestTeamScore; /** * Constructor * param gameID * param homeTeamId * param guestTeamId * param gameDate * param homeTeamScore * param guestTeamScore */ public Game(String gameID, String homeTeamId, String guestTeamId, String gameDate, int homeTeamScore, int guestTeamScore) { this.gameID = gameID; this.homeTeamId = homeTeamId; this.guestTeamId = guestTeamId; this.gameDate = gameDate; this.homeTeamScore = homeTeamScore; this.guestTeamScore = guestTeamScore; } /** * return the gameID */ public String getGameID() { return gameID; } /** * return the homeTeamId */ public String getHomeTeamId() { return homeTeamId; } /** * return the guestTeamId */
  • 5. public String getGuestTeamId() { return guestTeamId; } /** * return the gameDate */ public String getGameDate() { return gameDate; } /** * return the homeTeamScore */ public int getHomeTeamScore() { return homeTeamScore; } /** * return the guestTeamScore */ public int getGuestTeamScore() { return guestTeamScore; } Override public String toString() { return "Game {gameID=" + gameID + ", homeTeamId=" + homeTeamId + ", guestTeamId=" + guestTeamId + ", gameDate=" + gameDate + ", homeTeamScore=" + homeTeamScore + ", guestTeamScore=" + guestTeamScore + "}"; } Override public boolean equals(Object obj) { if(obj == null) return false; else { if(!(obj instanceof Game)) return false; else {
  • 6. Game other = (Game)obj; if(this.gameID.equalsIgnoreCase(other.gameID) && this.homeTeamId.equalsIgnoreCase(other.homeTeamId) && this.guestTeamId.equalsIgnoreCase(other.guestTeamId) && this.gameDate.equalsIgnoreCase(other.gameDate) && (this.homeTeamScore == other.homeTeamScore) && (this.guestTeamScore == other.guestTeamScore)) return true; else return false; } } } /** * Checks if the game date is between 20160101 and 20160531 * If yes return true or return false */ public boolean isValidDate() { int date = Integer.parseInt(gameDate); return ((20160101 <= date) && (date <= 20160531)); } } import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Test { /** * Creates a Team object with the parameter passed and returns it * param teamId * param name * param firstName * param lastName * param phone
  • 7. * param email * return */ public static Team setTeamAttribute(String teamId, String name, String firstName, String lastName, String phone, String email) { return new Team(teamId, name, firstName, lastName, phone, email); } /** * Creates a Game object with the parameter passed and returns it * param gameID * param homeTeamId * param guestTeamId * param gameDate * param homeTeamScore * param guestTeamScore * return */ public static Game setGameAttribute(String gameID, String homeTeamId, String guestTeamId, String gameDate, int homeTeamScore, int guestTeamScore) { return new Game(gameID, homeTeamId, guestTeamId, gameDate, homeTeamScore, guestTeamScore); } public static void main(String[] args) { //Input file final String INPUT_FILENAME = "input/hw1input.txt"; //Test 1a System.out.println("RUNNING TEST 1a"); Team team1 = new Team("1", "Team1", "Ann", "Matt", "123456", "abcxyz.com"); System.out.println(team1); //Test 1b System.out.println();
  • 8. System.out.println("RUNNING TEST 1b"); Game game1 = new Game("101", "Home Team", "Guest Team", "20160303", 12, 18); System.out.println(game1); //Open input file Scanner input = null; Team team2 = null; Game game2 = null; try { input = new Scanner(new File(INPUT_FILENAME)); //Read first line String[] inputDtls = input.nextLine().split(","); //Test 2a if(inputDtls[0].equalsIgnoreCase("TEAM")) { System.out.println(); System.out.println("RUNNING TEST 2a"); team2 = setTeamAttribute(inputDtls[1], inputDtls[2], inputDtls[3], inputDtls[4], inputDtls[5], inputDtls[6]); if(!team2.isValidEmail()) System.err.println("ERROR: Invalid email address. Is missing (at sign): " + team2.getEmail()); //Display team1 attributes System.out.println(team2.getTeamId()); System.out.println(team2.getName()); System.out.println(team2.getFirstName()); System.out.println(team2.getLastName()); System.out.println(team2.getPhone()); System.out.println(team2.getEmail()); } //Read second line inputDtls = input.nextLine().split(","); //Test 2b
  • 9. if(inputDtls[0].equalsIgnoreCase("GAME")) { System.out.println(); System.out.println("RUNNING TEST 2b"); game2 = setGameAttribute(inputDtls[1], inputDtls[2], inputDtls[3], inputDtls[4], Integer.parseInt(inputDtls[5]), Integer.parseInt(inputDtls[6])); if(!game2.isValidDate()) System.err.println("ERROR: Invalid game date: " + game2.getGameDate()); //Display team attributes System.out.println(game2.getGameID()); System.out.println(game2.getHomeTeamId()); System.out.println(game2.getGuestTeamId()); System.out.println(game2.getGameDate()); System.out.println(game2.getHomeTeamScore()); System.out.println(game2.getGuestTeamScore()); } } catch(FileNotFoundException fnfe) { System.err.println("Data file not found"); } finally { //Close file if(input != null) input.close(); } //Test 3a System.out.println(); System.out.println("RUNNING TEST 3a"); System.out.println("TEAM 1 : " + team1); System.out.println("TEAM 2 : " + team2); if(team1.equals(team2)) System.out.println("The two teams are same"); else System.out.println("The two teams not are same");
  • 10. //Test 3b System.out.println(); System.out.println("RUNNING TEST 3b"); System.out.println("GAME 1 : " + game1); System.out.println("GAME 2 : " + game2); if(game1.equals(game2)) System.out.println("The two games are same"); else System.out.println("The two games not are same"); } } SAMPLE OUTPUT: RUNNING TEST 1a Team {teamId=1, name=Team1, firstName=Ann, lastName=Matt, phone=123456, email=abcxyz.com} RUNNING TEST 1b Game {gameID=101, homeTeamId=Home Team, guestTeamId=Guest Team, gameDate=20160303, homeTeamScore=12, guestTeamScore=18} RUNNING TEST 2a ERROR: Invalid email address. Is missing (at sign): roadrunner#gmail.com 1 Road Runner David Brown 303-123-4567 roadrunner#gmail.com RUNNING TEST 2b ERROR: Invalid game date: 20150105 101 1 2 20150105 4 3 RUNNING TEST 3a TEAM 1 : Team {teamId=1, name=Team1, firstName=Ann, lastName=Matt, phone=123456,
  • 11. email=abcxyz.com} TEAM 2 : Team {teamId=1, name=Road Runner, firstName=David, lastName=Brown, phone=303-123-4567, email=roadrunner#gmail.com} The two teams not are same RUNNING TEST 3b GAME 1 : Game {gameID=101, homeTeamId=Home Team, guestTeamId=Guest Team, gameDate=20160303, homeTeamScore=12, guestTeamScore=18} GAME 2 : Game {gameID=101, homeTeamId=1, guestTeamId=2, gameDate=20150105, homeTeamScore=4, guestTeamScore=3} The two games not are same Solution public class Team { //Attributes private String teamId; private String name; private String firstName; private String lastName; private String phone; private String email; /** * Constructor * param teamId * param name * param firstName * param lastName * param phone * param email */ public Team(String teamId, String name, String firstName, String lastName, String phone, String email) { this.teamId = teamId; this.name = name; this.firstName = firstName; this.lastName = lastName;
  • 12. this.phone = phone; this.email = email; } /** * return the teamId */ public String getTeamId() { return teamId; } /** * return the name */ public String getName() { return name; } /** * return the firstName */ public String getFirstName() { return firstName; } /** * return the lastName */ public String getLastName() { return lastName; } /** * return the phone */ public String getPhone() { return phone; } /** * return the email */
  • 13. public String getEmail() { return email; } Override public String toString() { return "Team {teamId=" + teamId + ", name=" + name + ", firstName=" + firstName + ", lastName=" + lastName + ", phone=" + phone + ", email=" + email + "}"; } Override public boolean equals(Object obj) { if(obj == null) return false; else { if(!(obj instanceof Team)) return false; else { Team other = (Team)obj; if(this.teamId.equalsIgnoreCase(other.teamId) && this.name.equalsIgnoreCase(other.name) && this.firstName.equalsIgnoreCase(other.firstName) && this.lastName.equalsIgnoreCase(other.lastName) && this.phone.equalsIgnoreCase(other.phone) && this.email.equalsIgnoreCase(other.email)) return true; else return false; } } } /** * Checks if the email id contains "(at sign)". * Is yes returns true else returns false
  • 14. */ public boolean isValidEmail() { return this.email.contains("(at sign)"); } } public class Game { //Attributes private String gameID; private String homeTeamId; private String guestTeamId; private String gameDate; private int homeTeamScore; private int guestTeamScore; /** * Constructor * param gameID * param homeTeamId * param guestTeamId * param gameDate * param homeTeamScore * param guestTeamScore */ public Game(String gameID, String homeTeamId, String guestTeamId, String gameDate, int homeTeamScore, int guestTeamScore) { this.gameID = gameID; this.homeTeamId = homeTeamId; this.guestTeamId = guestTeamId; this.gameDate = gameDate; this.homeTeamScore = homeTeamScore; this.guestTeamScore = guestTeamScore; } /** * return the gameID */
  • 15. public String getGameID() { return gameID; } /** * return the homeTeamId */ public String getHomeTeamId() { return homeTeamId; } /** * return the guestTeamId */ public String getGuestTeamId() { return guestTeamId; } /** * return the gameDate */ public String getGameDate() { return gameDate; } /** * return the homeTeamScore */ public int getHomeTeamScore() { return homeTeamScore; } /** * return the guestTeamScore */ public int getGuestTeamScore() { return guestTeamScore; } Override public String toString() { return "Game {gameID=" + gameID + ", homeTeamId=" + homeTeamId + ",
  • 16. guestTeamId=" + guestTeamId + ", gameDate=" + gameDate + ", homeTeamScore=" + homeTeamScore + ", guestTeamScore=" + guestTeamScore + "}"; } Override public boolean equals(Object obj) { if(obj == null) return false; else { if(!(obj instanceof Game)) return false; else { Game other = (Game)obj; if(this.gameID.equalsIgnoreCase(other.gameID) && this.homeTeamId.equalsIgnoreCase(other.homeTeamId) && this.guestTeamId.equalsIgnoreCase(other.guestTeamId) && this.gameDate.equalsIgnoreCase(other.gameDate) && (this.homeTeamScore == other.homeTeamScore) && (this.guestTeamScore == other.guestTeamScore)) return true; else return false; } } } /** * Checks if the game date is between 20160101 and 20160531 * If yes return true or return false */ public boolean isValidDate() { int date = Integer.parseInt(gameDate); return ((20160101 <= date) && (date <= 20160531)); }
  • 17. } import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Test { /** * Creates a Team object with the parameter passed and returns it * param teamId * param name * param firstName * param lastName * param phone * param email * return */ public static Team setTeamAttribute(String teamId, String name, String firstName, String lastName, String phone, String email) { return new Team(teamId, name, firstName, lastName, phone, email); } /** * Creates a Game object with the parameter passed and returns it * param gameID * param homeTeamId * param guestTeamId * param gameDate * param homeTeamScore * param guestTeamScore * return */ public static Game setGameAttribute(String gameID, String homeTeamId, String guestTeamId, String gameDate, int homeTeamScore, int guestTeamScore) { return new Game(gameID, homeTeamId, guestTeamId, gameDate, homeTeamScore, guestTeamScore); }
  • 18. public static void main(String[] args) { //Input file final String INPUT_FILENAME = "input/hw1input.txt"; //Test 1a System.out.println("RUNNING TEST 1a"); Team team1 = new Team("1", "Team1", "Ann", "Matt", "123456", "abcxyz.com"); System.out.println(team1); //Test 1b System.out.println(); System.out.println("RUNNING TEST 1b"); Game game1 = new Game("101", "Home Team", "Guest Team", "20160303", 12, 18); System.out.println(game1); //Open input file Scanner input = null; Team team2 = null; Game game2 = null; try { input = new Scanner(new File(INPUT_FILENAME)); //Read first line String[] inputDtls = input.nextLine().split(","); //Test 2a if(inputDtls[0].equalsIgnoreCase("TEAM")) { System.out.println(); System.out.println("RUNNING TEST 2a"); team2 = setTeamAttribute(inputDtls[1], inputDtls[2], inputDtls[3], inputDtls[4], inputDtls[5], inputDtls[6]); if(!team2.isValidEmail()) System.err.println("ERROR: Invalid email address. Is missing (at sign): " + team2.getEmail());
  • 19. //Display team1 attributes System.out.println(team2.getTeamId()); System.out.println(team2.getName()); System.out.println(team2.getFirstName()); System.out.println(team2.getLastName()); System.out.println(team2.getPhone()); System.out.println(team2.getEmail()); } //Read second line inputDtls = input.nextLine().split(","); //Test 2b if(inputDtls[0].equalsIgnoreCase("GAME")) { System.out.println(); System.out.println("RUNNING TEST 2b"); game2 = setGameAttribute(inputDtls[1], inputDtls[2], inputDtls[3], inputDtls[4], Integer.parseInt(inputDtls[5]), Integer.parseInt(inputDtls[6])); if(!game2.isValidDate()) System.err.println("ERROR: Invalid game date: " + game2.getGameDate()); //Display team attributes System.out.println(game2.getGameID()); System.out.println(game2.getHomeTeamId()); System.out.println(game2.getGuestTeamId()); System.out.println(game2.getGameDate()); System.out.println(game2.getHomeTeamScore()); System.out.println(game2.getGuestTeamScore()); } } catch(FileNotFoundException fnfe) { System.err.println("Data file not found"); } finally { //Close file if(input != null) input.close();
  • 20. } //Test 3a System.out.println(); System.out.println("RUNNING TEST 3a"); System.out.println("TEAM 1 : " + team1); System.out.println("TEAM 2 : " + team2); if(team1.equals(team2)) System.out.println("The two teams are same"); else System.out.println("The two teams not are same"); //Test 3b System.out.println(); System.out.println("RUNNING TEST 3b"); System.out.println("GAME 1 : " + game1); System.out.println("GAME 2 : " + game2); if(game1.equals(game2)) System.out.println("The two games are same"); else System.out.println("The two games not are same"); } } SAMPLE OUTPUT: RUNNING TEST 1a Team {teamId=1, name=Team1, firstName=Ann, lastName=Matt, phone=123456, email=abcxyz.com} RUNNING TEST 1b Game {gameID=101, homeTeamId=Home Team, guestTeamId=Guest Team, gameDate=20160303, homeTeamScore=12, guestTeamScore=18} RUNNING TEST 2a ERROR: Invalid email address. Is missing (at sign): roadrunner#gmail.com 1 Road Runner David Brown
  • 21. 303-123-4567 roadrunner#gmail.com RUNNING TEST 2b ERROR: Invalid game date: 20150105 101 1 2 20150105 4 3 RUNNING TEST 3a TEAM 1 : Team {teamId=1, name=Team1, firstName=Ann, lastName=Matt, phone=123456, email=abcxyz.com} TEAM 2 : Team {teamId=1, name=Road Runner, firstName=David, lastName=Brown, phone=303-123-4567, email=roadrunner#gmail.com} The two teams not are same RUNNING TEST 3b GAME 1 : Game {gameID=101, homeTeamId=Home Team, guestTeamId=Guest Team, gameDate=20160303, homeTeamScore=12, guestTeamScore=18} GAME 2 : Game {gameID=101, homeTeamId=1, guestTeamId=2, gameDate=20150105, homeTeamScore=4, guestTeamScore=3} The two games not are same