write a class encapsulating the concept of a team for exampl
write a class encapsulating the concept of a team (for example, \"Orioles\"), assuming a team has only one attribute: The team name. i need to include a constructor, the accessor and mutator, and methods toString and equals. Also i need to write a client class to test all the methods in your class. Thank you so much!
Solution
Orioles.java
public class Orioles {
private String name;
public Orioles(){
}
public Orioles(String n){
name = n;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String toString(){
return \"Team Name: \"+name;
}
public boolean equals(Orioles o){
if(this.name.equals(o.name)){
return true;
}
else{
return false;
}
}
}
OriolesTest.java
import java.util.Scanner;
public class OriolesTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print(\"Enter the first team name: \");
String name1 = scan.nextLine();
Orioles o1 = new Orioles(name1);
System.out.print(\"Enter the second team name: \");
String name2 = scan.nextLine();
Orioles o2 = new Orioles();
o2.setName(name2);
System.out.println(o1.toString());
System.out.println(o2.toString());
System.out.println(\"Both teams equals: \"+o1.equals(o2));
}
}
Output:
Enter the first team name: Mighty Decaans
Enter the second team name: Mighty Warriors
Team Name: Mighty Decaans
Team Name: Mighty Warriors
Both teams equals: false

