CD - title : String - artist : String - length : int - publisher : Publisher CDTest use 1..1 3..* + main(args : String[ ]) + CD() + CD(title : String, artist : String, lenth : int, publisher : Publisher) + setLength(length : int) + setTitle(title : String) + setArtist(artist : String) + setPublisher(publisher : Publisher) + setPublisher(name : String, phone : String) + getLength() : int + getTitle() : String + getArtist() : String + getPublisher() : Publisher + print() + toString() : String Publisher Has 1..1 0..*
Overview
The task in this part is also to create a class and a number of objects / instances of this class. To be able to do this, we also need a test class.
The purpose of the task is to, in addition to getting acquainted with the concepts of object, class, constructor and overlay, learn to use other classes in a class. You should also know how we use the Integer class to convert strings to integers.
Task
You must create a class that represents a CD. The class should be named CD and saved in a source file called CD.java. The class must contain data about the CD's title, artist, length (in number of seconds) and which publisher the disc is published on.
Methods must be available for setting and retrieving data for all instance variables, as well as for printing all information about the disk. The setPublisher method should be superimposed so that a variant takes an object of the type Publisher as an argument. The second variant should take two strings as arguments, which are the publisher's name and telephone number.
The print method must print all data about the object as well as the publisher on which the disc is published. Only the publisher's name should be printed. The toString method should return a string representation of the CD object (optionally any information)
to be returned, but e.g. artist and title may be appropriate).
The class diagram below (UML) gives you an idea of what the class is supposed to look like (what instance variables and methods there should be).
You must write a test class that creates at least three CD objects that appropriately demonstrate all the methods in the CD class. Call the class CDTest and save it in the source file CDTest.java. At least one of the objects must be created by asking the user for data. Choose yourself if you want to use the Scanner class or if you use dialog boxes. You can "hardcode" other objects.
Requirement
In order for the information to be considered approved, in addition to the above-mentioned details, it is also required that the requirements that follow are met.
• No public instance variables may be in any class, only methods and constructors may be public.
• All screen prints should be well-structured and easy to understand.
Comment on the source code and describe what is happening.
In addition, you should generate documentation for Publisher and CD using the javadoc tool.
Step by step
Solved in 6 steps with 5 images