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. Include a constructor, the accessor and mutator, and methods toString and equals. Write a client class to test all the methods in your class. Your must create a Java project and two separate classes. Cannot use @override.

Solution

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));
   }

}

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;
       }
   }
}

Output:

Enter the first team name: Mighty Deccans
Enter the second team name: Hazzardes
Team Name: Mighty Deccans
Team Name: Hazzardes
Both teams equals: false

Write a class encapsulating the concept of a team (for example, “Orioles”), assuming a team has only one attribute: the team name. Include a constructor, the ac
Write a class encapsulating the concept of a team (for example, “Orioles”), assuming a team has only one attribute: the team name. Include a constructor, the ac

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site