Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a project with the following: A class for info about a sports team and th

ID: 3594350 • Letter: C

Question

Create a project with the following: A class for info about a sports team and their game scores. The constructor should take the team name. The class should also have a method that will accept a game score. The score will consist of the team’s score and the opponent’s score. Finally, there should be methods to return the following; The team’s record in terms of wins-losses- draws. These can be returned by separate methods. The team’s average score. The team’s opponents’ average score. A main executable class that will ask for the team name. It should then ask the user for the team’s score in a game and then the opponent’s score in that game. It should continue to ask until the user enters -1 for the team’s score. After the user has entered -1, the class should display the following info from the team class: the team name, their record in terms of wins-losses-draws, their average score and their opponent’s average score. The team name should be from 3 to 20 characters. The scores should be from 0 to 1000.

Give the whole program step by step and plz give the output as well.

Explanation / Answer

PRogram for the above question:

First we made a class named "team" and its variables for stroring name,team score,team opponent score,team average score, team opponent avg score ,team win loss draw record.

Then we made few methods either to mutate or access member variables of "team" class.

Then, we have to make a main() class.

we name this class as "callteam" and defined the main() function inside it.

Inside this class, we defined an object of "team" class, asked its name from user...and then ask the user to input the team score and opponent team score.

we are adding the team score to sum1 and opponent team score to sum2. We are also incrementing a variable "i" for every score entered by user except the last.

As soon as the user enter the value "-1", the input stops and the required result is output on screen.

My Program:


import java.util.Scanner;
class team
{
  
   public Scanner sc= new Scanner(System.in);
   String tname;// variable to store name of the team
   public int score1,oscore1,win1,loss1,draw1,avgsc1,avgsc2; // variables to store other value of a team
   team(String s)   // constructor with team name
   {
       this.tname=s;
   }
   String name()   // method to return team name
   {
       return this.tname;
   }
   void setscore() // method to set team score and team opponet score
   {
       System.out.println("enter team and opponent score ");
       //cin>>this.score1>>this.oscore1;
       this.score1=sc.nextInt();
       this.oscore1=sc.nextInt();
      
   }
  
   int getscore() //method to get team score
   {
       return this.score1;
   }
   
   int getoscore() // method to get opposite team score
     {
        return this.oscore1;
   }
   int win()   // // method to get team win records
   {
      return this.win1;
   }
   int loss() // method to get team loss records
   {
      return this.loss1;
   }
   int draw() // method to get team draw records
   {
      return this.draw1;
   }
     float avgsct() // // method to get team average score
      {
         return this.avgsc1;
      }
      float avgsco() // method to get oppposite team average score
      {
       return this.avgsc2;
      }

}

class callteam // class that contain main() method
{
public static Scanner sc= new Scanner(System.in);
public static void main(String args[])
{
   int i=0;int sum1=0,sum2=0;
   String name;
   System.out.println("enter the team name"); // team name input by user
   name=sc.nextLine();
   team t1=new team(name); // object of team class
   while(true)
   {
   t1.setscore(); // set team and team opponent score
   if(t1.score1==-1)
   break;
   i++;
   if(t1.score1>t1.oscore1)
   t1.win1++;
   else if(t1.score1==t1.oscore1)
   t1.draw1++;
   else
   t1.loss1++;
   sum1=sum1+t1.score1;
   sum2=sum2+t1.oscore1;
  
    }
   t1.avgsc1=sum1/i;   // calculate team average
   t1.avgsc2=sum2/i;    //calculate opponent team average
   System.out.println("the name of the team is==>"+t1.name()); // for output display
   System.out.println("win--loss--draw record of team is "+t1.win()+" "+t1.loss()+" "+t1.draw());
  
   System.out.println("team average score is ==> "+t1.avgsct());
  
   System.out.println("team opponent score is==>"+t1.avgsco());
  
  
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote