Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[C#] I need to create a television class which has a name, price, and size. There are three parts to this and it can be

[C#] I need to create a television class which has a name, price, and size. There are three parts to this and it can be tedious, but I'll take any help I can get.

image text in transcribed

Here is the second part:

image text in transcribedHere is part 3(the tedious one)

image text in transcribed

1. Implement the Television class. Each Television has a brand name (a string), a price (use decinal), and a size (measured diagonally in inches). Give the class a constructor, and getter/setter methods for each of the three data attributes. A. Note that price is actually a decimal, not a double , value B. When a Television object is created using the default ('no-argument') constructor, the price and size should be zero, and the brand should be the empty string(), NOT the value null. C. Remember to validate the input to the setter methods. If you're given a negative value for price or size, reject the new value and keep the current value, instead. Similarly, if the SetBrand method is given a null value, it should reject this null value and keep the current value, instead. D. You also need to implement a Print method, which should print out a message in the following format: Brand: Sony Price: 1000.17 Size:10.5 1. If you haven't done so already, implement two constructors for your Television class A. A default constructor that initializes the brand to (the empty string - NOT the null value), the price to zero, and the size to zero B. A constructor which takes three arguments: the brand, the price, and the screen's size, in that order. The constructor should copy these parameters into the appropriate data fields in the object. Note that these fields should only be set to valid values (e.g., no negative prices, or null for the brand, etc, etc) - if given an invalid value, the default value that the default constructor assigns should be used, instead 2. Implement the PrintArrayofTVs method in the Television Handler class 3. Create an array that can hold a bunch (at least 5) of references to Television objects, within the PrintArray0fTVs method. This will probably look something like: Television[] aBunchOfTVs= new Television [5]; 4. Go through, and create a new Television object for each slot in the array. Your code should continue to work correctly even if you decide to change the size of the array (in the previous step) some time in the future. You'll probably end up having a line like the following in your code (assuming that you've decided to create a constructor for your Television class (which you should do)) aBunchofTVs [0]new Television ("Brand X", 10, 42); For each TV you should give it the brand "Brand X", the size should be 42, and the price should be 10 in the array that the Television is being assigned to the index 5. Go through (using a separate loop) and call the Print0 method on each of your objects. An example of correct output is: Brand: Brand X Price: 10 Size:42 Brand: Brand X Price: 11 Size:42 Brand: Brand X Price:12 Size:42 Brand: Brand X Price: 13 Size:42 Brand: Brand X Price:14 Si re 42 1. Implement the PrintArrayOfPossiblyNul1TVs method in the TelevisionHandler class. The method needs to do all of the following steps: A. The first thing the method should do is create an array of 10 references to Television objects. B. Next, write a for loop that loops over the array, and checks each space in the array- if that slot is null, the program should print out a message saying that "Slot X is null", where X is the space number. If the first element of the array is null, you will see "Slot 0 is null". What do you see when you run this code? l. Include an easy to find comment explaining why you get the results you do, when you use a 'printing loop' on the array immediately after the array has been created C. Next, write code that allocates 4 Television objects, and stores those objects into the array.Put one object into slot 0, another object into slot 1, another into slot 5, and the last into a slot 9 . For each TV you should give it the brand "Brand X", the size should be 42, and the price should be 10the index in the array that the Television is being assigned to. D. Copy-and-paste the for loop that you wrote above, so that you can figure out which slots in the array are null, and which aren't. For slots that are null, continue to print out the warning message. For any slots that aren't null,call the Print method on the object referred to by the slot. I. Note that you can check for non-null slots either by using the else part of the existing if statement, or else by asking if (array[slot] null) I. Include an easy to find comment explaining why you get the results you do, when you use a printing loop' on the array after you put 4 objects into the the array E. Next, add a loop that goes through the array. Each time it finds an array slot that is null, it should create a new Television, and store that object into the empty slot (in the slot with null in it). When this loop finishes running, every slot in the array will be occupied l. For each TV you should give it the brand "Brand X", the size should be 42, and the price should be 10 the index in the array that the Television is being assigned to. Il. Include an easy to find comment explaining why you get the results you do, when you use a printing loop' on the array after you've filled up the array with objects. F Lastly, copy-and-paste the for loop that you wrote above (in part b), so that you can figure out which slots in the array are null, and which aren't. Since there should be no null slots, this means that this loop should print out 10 separate TVs

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

Recommended Textbook for

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions

Question

5-8 What are the advantages and disadvantages of the BYOD movement?

Answered: 1 week ago