Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need in C#!!! Question 3a Create a class to represent a baseball bat. Name the class Bat. It will contain four (4) class attributes, its

Need in C#!!!

Question 3a Create a class to represent a baseball bat. Name the class Bat. It will contain four (4) class attributes, its length, its diameter, the possible types of material it is made of, and a number ranging from 0 to 4 (inclusive). The length and diameter both describe the size of the bat. Those should always be under 2.75 inches in diameter and no more than 42.0 inches. If the user enters a length or diameter greater than the maximum value, set the length and diameter to the maximum value. The type of material is an array that holds all possible materials bats can be made from, listed below. NOTE: the array that holds the possible materials of the bat should be set in the class itself and should be the same (unchanging) for all bats. aluminum maple ash hickory bamboo The final class variable is a number that determines which material a particular bat is made of, so it ranges from zero to four since it holds the index of the material. For example, zero (0) for this number means that the bat is made from aluminum. Ensure that all the class variables are private and that only the length and diameter have an accessor (getter) and a mutator (setter). Provide ONE parameterized constructor, which will take in three parameters and use those parameters to set the length, diameter and material type index fields. Next, have a method called Break that checks the bats material and if it was made from any type of wood, it will break into pieces. So, the method should return a message saying, the bat has been broken and change the length and diameter to negative one (-1) to help indicate this. We will also have a ToString (C#) or toString (Java, C++) method, which will simply return a message stating the bats length, diameter, and material.

Question 3b (Mandatory) (20 points) Create a two (2) instances of the Bat class in your Main method. Both can be given a random, hard-coded, or user input value for the length and diameter BUT one bat must be wooden, and one must be made from aluminum. After creating the two bats, print out each of the bats attributes: length, diameter, and material of the bat. Use the Break method the wooden bat and print out the returned message. Change the other bats length and diameter to be 0.5 inches bigger than it was initially. Finally, print out each of the bats attributes again. Example (Blue values are for bat 1 and red is for bat 2): Bat 1s length: 30.00 inches. Bat 1s diameter: 2.00 inches. Bat 1s material: maple Bat 2s length: 40.00 inches. Bat 2s diameter: 2.50 inches. Bat 2s material: aluminum The bat was broken! Its length and diameter were changed to -1. Bat 1s length: -1.00 inches. Bat 1s diameter: -1.00 inches. Bat 1s material: maple Bat 2s length: 40.50 inches. Bat 2s diameter: 2.75 inches. Bat 2s material: aluminum

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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 Accounting questions