Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Question #1: (Chapter 6) Create the class SportsTeam . You are required to code the class with 3 instance variables (data members) that you make

Question #1: (Chapter 6)

Create the class SportsTeam.

You are required to code the class with 3 instance variables (data members) that you make up and a 4th instance variable that is the id of the team. This teamId instance variable will be a unique id" (similar to how a social security number is unique to a person) -- this will be used for the findTeamInfo() method in question #3.

You must have at least 2 constructors --a no-arg constructor and a constructor taking multiple arguments, and setter and getter methods for each of the 4 instance variables.

Question #2: (Chapter 7)

Create a test file where you ask the user how many objects of the class from question #1 that you want to construct? (For example, if your class were a Dog, you would ask the user how many Dog objects they want to construct)

Make an array of that size and then prompt/ask the user for the information to make your objects (you cannot hardcode the information). Put your objects into this array that you created. (hint: see Section 7.7 in your book for a section on making an array of objects!)

Print out the contents of the array you created using a loop.

Question #3: (Chapter 5)

In the same test program used in #2, add 2 "static" methods to be called from your main method:

1) findTeamInfo() -- this method will be a void method; you will pass the team id and array of teams to the method as arguments and then in the method, loop through the array to find that team id. Output to the user if you find the team id or not and if you do find it, output all the team information for that team id.

Call the findTeamInfo() method after you prompt them to enter a team id in your main method.

2) isValidTeamId() -- this method is a value-returning method; it will return a boolean indicating if the team id you passed in is valid or not. You will call this method as the user is entering the team information (probably in a loop in the main method). You will pass to the method as arguments 2 things: the current array of objects AND the team id the user entered. In the method, it will loop through the array one at a time and see if it finds the ID sent in. If it finds it, then this is NOT a valid team id since it is already assigned to another team. In addition to checking if the team id is already used, you must also make sure that the team id is not a negative number. You will return back a boolean set to either true or false to indicate if the team id is valid. In the calling main method, you will ask the user to enter another id if this is not valid; else, you can continue to enter other team information.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions