a class, Team.java, that has the following:  * two private instance variables: a String named color and an int named score.  * a default constructor with no parameters that initializes color to "Red" and score to zero.  * a constructor that takes two parameters (one for each instance variable) and sets the values of the instance variables.  * a public getter and setter method for each instance variable.  * a toString method that returns the color and score in the following format: "Red Team with 0 points."

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need to write a jave program to keep track of a team sport.

Write a class, Team.java, that has the following:
 * two private instance variables: a String named color and an int named score.
 * a default constructor with no parameters that initializes color to "Red" and score to zero.
 * a constructor that takes two parameters (one for each instance variable) and sets the values of the instance variables.
 * a public getter and setter method for each instance variable.
 * a toString method that returns the color and score in the following format: "Red Team with 0 points."

Expert Solution
Step 1

// Java Code:

import java.io.*;

class Team{

//declaring the private variables

private String color;

private int score;

//default constructor

Team()

{

this.color="Red";

this.score=0;

}

//parameterized constructor

Team(String c, int s)

{

this.color=c;

this.score=s;

}

//public getter method to get color

public String getColor()

{

return color;

}

//public getter method to get score

public int getScore()

{

return score;

}

// public setter method to set color

public void setColor(String c)

{

this.color=c;

}

//public setter method to set score

public void setScore(int s)

{

this.score=s;

}

//toString method

public String toString()

{

return color+" Team with "+score+" points.";

}

//the working of the constructors and the methods are demonstrated using the main function

public static void main(String[] args)

{

//invoking the default constructor

Team t1=new Team();

//invoking the parameterized constructor

Team t2=new Team("Pink",23);

//using the getter functions

System.out.println(t1.getColor());

//using the to string method

System.out.println(t1);

System.out.println(t2);

//using setter function

t1.setColor("Green");

t2.setScore(46);

//using the toString method after the values have been changed using the setter method

System.out.println(t1);

System.out.println(t2);

}

}

OUTPUT: (Please refer the comments in the java code to see the details regarding of the output)

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education