Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A. Write a java program that do the following: Create a class named TV that consists of the following: - Three instance data members of
A. Write a java program that do the following: Create a class named TV that consists of the following: - Three instance data members of private access modifier: tvld: represents the id of the TV and its data type is integer. tvDisType: represents the screen display type of the TV and its data type is string. tvPrice: represents the price of the TV and its data type is double. - One static data member of public access modifier: tvCounter: keeps track of the number of TV's objects that are created from the TV class. Its type is integer. - Member methods as follows: 1. Default constructor to initialize the tvld to zero, tvDisType to empty string, and the tvPrice to zero. 2. Parameterized constructor that receives values for the following data members (tvid, tvDisType, and tvPrice), then it sets the received values in the class data members. 3. Create a method named setTVPrice that sets a value in the tvPrice data member. Be sure that the value is nonnegative. 4. Create a method named getTVId that returns the value of the tvld. 5. Create a method named isCheap that returns true if the price of the TV is less than or equals to $200, and returns false otherwise. 6. Create a method named calculateTVLicence that returns the annual cost required for the reception of television broadcasts according to the following: - If you only watch on a black and white TV, the licence cost to pay is $5.5 per month. [Hint: TV Licence cost=cost per month*12] - If you only watch on colour TV, the licence cost to pay if $15 per month. - Otherwise there is no cost to pay. 7. Create a method named showTVDetails that prints the values of the data members in the following format: Example 1: If the values in the created object is (id =111, type = "black and white TV", price =200 ) The TV id is 111 and its display type is black and white TV. The TV license costs $66. However, it is a cheap TV. - 2021-2022 Faculty of Information Technology (FIT), Applied Science University, Amman, Jordan. 1 Example 2: If the values in the created object is (id =222, type = "colour TV", price =250 ) The TV id is 222 and the type is colour TV. The TV license costs $180. However, it is an expensive TV. [Hint: you may use the isCheap method to detect if the TV is cheap or expensive. Also you may use the calculateTVLicence method to calculate the amount that will be paid for a TV license]. B. Write a Demo class that contains the main method. In the main method do the following: 1. Create an object of the TV class named tv1 using the default constructor. 2. Create another object of the TV class named tv2 using the parameterized constructor. Ask the user to input the tvld, tvDisType, and tvPrice. 3. Call the method setTVPrice for the tv1 object to set the price of that object to be 300 . 4. Print the value of the tvCounter static data member. 5. Call the showTVDetails method using the object tv1. 6. Call the showTVDetails method using the object tv2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started