create java classes to manage CD and publisher and expand the classes so that you can handle book and DVD. This should be done with the help of inheritance. A general superclass, Media, will be created to be able to reuse common data and functionality between the CD, Book and DVD classes. These 3 class must thus inherit their properties from the Media class. The Media class is a superclass for different type of media. you will collect instance variables and methods that are common to all type of media. All instance variables in the class are declared as protected, which mean that classes that inherit from Media have a direct access to these variables.The class only needs 2 constructors. One takes 3 argument that set values for all instance variables in the class, and the other takes no arguments but sets certain default values of the instance variables. If you think that more designers are necessary, you can add. In the setLength method, perform a check so that the value submitted is not less than zero. It should also not be possible to create a Media object whose length is less than 0. There is no point in setting the length of a media to -1. If the value sent to the method is less than 0, the value should be set to 0 . If the value sent to the method is greater than 0, we can assign this value to the instance variable. The first subclass to create is DVD. This class contains only an "own" instance variable, ageLimit, which is used to specify the age limit of a video. There must also be set and get methods for this instance variable. all properties are inherited from the Media class. The length of a DVD is stored in the class as the total number of seconds. In the setAgeLimit method, you must make a check so that the submitted value is not less than 0, the same check performed for the setLength method in the Media class. Some methods you need to overshado
create java classes to manage CD and publisher and expand the classes so that you can handle book and DVD. This should be done with the help of inheritance. A general superclass, Media, will be created to be able to reuse common data and functionality between the CD, Book and DVD classes. These 3 class must thus inherit their properties from the Media class. The Media class is a superclass for different type of media. you will collect instance variables and methods that are common to all type of media. All instance variables in the class are declared as protected, which mean that classes that inherit from Media have a direct access to these variables.The class only needs 2 constructors. One takes 3 argument that set values for all instance variables in the class, and the other takes no arguments but sets certain default values of the instance variables. If you think that more designers are necessary, you can add. In the setLength method, perform a check so that the value submitted is not less than zero. It should also not be possible to create a Media object whose length is less than 0. There is no point in setting the length of a media to -1. If the value sent to the method is less than 0, the value should be set to 0 . If the value sent to the method is greater than 0, we can assign this value to the instance variable. The first subclass to create is DVD. This class contains only an "own" instance variable, ageLimit, which is used to specify the age limit of a video. There must also be set and get methods for this instance variable. all properties are inherited from the Media class. The length of a DVD is stored in the class as the total number of seconds. In the setAgeLimit method, you must make a check so that the submitted value is not less than 0, the same check performed for the setLength method in the Media class. Some methods you need to overshadow in DVD to get the behavior we want. To begin with, the toString method should return a string representation of the current DVD object. print method should print all the values of the object and call the print method in the superclass to print its values. You must type a getLengthAsString () method. The method should return the length of the DVD as a string according to the format: HHh MMm SSs. string of hours (HH), minutes (MM) and seconds (SS) must always contain at least 2 digits. in cases where the hours, minutes or seconds are less than 10, a zero shall be set in front. Ex of strings that can be returned
00h 54m 09s (When length = 3249)
01h 09m 45s (When length = 4185)
100h 00m 00s (When length = 360000)
There should be at least 2 different ways to create DVD objects. A constructor who takes 4 arguments and one who takes no arguments at all. Then it's up to you if you want more ways to create objects. It should not be possible to create a DVD whose length or age limit has a negative value (in which case change the value to 0). The 2th subclass you should create is Book which contains an instance variable, author. this class will inherit its properties from Media, but there will be set- and get- methods for author. The toString and print methods should be overshadowed and getLengthAsString should return the length of the book as a string according to the format: xxx page (s)
if the number of pages is only 1, the page is printed according to the number of pages. If the number of pages is more than 1, pages are printed afterwards. Ex of strings that can be returned: 0 pages (length = 0)
1 page (length = 1)
321 pages (length = 321)
Constructors for creating objects of Book should be present where one has 4 parameters and the other has no parameters at all. If you want more ways to create books, you are free to add designers for it.The final subclass is a CD that you do not need to make any major changes to. Thanks to the Media superclass, you can remove certain instance variables and methods from your original CD class. Some methods you need to overshadow so they fit into the inheritance structure. as for DVD and Book, the print and toString methods. Implementation of getLengthAsString should return the length of the CD as a string according to the format: HH: MM: SS. The string of hours (HH), minutes (MM) and seconds (SS) must always contain at least 2 digits. In cases where the hours, minutes or seconds are less than 10, a zero shall be set in front. Ex of strings that can be returned:
00:54:09 (When length = 3249)
01:09:45 (When length = 4185)
100: 00: 00(When length = 360000)
there should be at least 2 different ways to create objects from CD. A constructor that has 4 parameters and one that has none at all. it's up to you if you want more way to create objects.
To check that everything work as intended, write a testclass that create at least 2 object each of Book, DVD and CD (at least 6 objects). Call it MediaTest. it should appropriately test all the methods available in the classes you have written. No requirement to use input to give the objects values.
Step by step
Solved in 7 steps with 7 images