code to explanationWed, 28 Dec 2022

public class DvdName { private String titleName; public DvdName(String titleName) { this.setTitleName(titleName); } public final void setTitleName(String titleNameIn) { this.titleName = titleNameIn; } public final String getTitleName() { return this.titleName; } public void setNameStarsOn() { this.setTitleName(this.getTitleName().replace(' ','*')); } public void setNameStarsOff() { this.setTitleName(this.getTitleName().replace('*',' ')); } public String toString() { return ("DVD: " + this.getTitleName()); } }

The class DvdName has two public methods getTitleName() and setTitleName(). The method getTitleName returns the data for the DVD title. The method setTitleName sets the DVD title. The title is stored in a private final String called titleName. The constructor DvdName() is used to set the initial value of the titleName. The first method setNameStarsOn() replaces all the spaces in the titleName with an asterisk (*). The second method setNameStarsOff() replaces all the asterisks in the titleName with a space. The toString() method is used to display the DVD title.

Questions about programming?Chat with your personal AI assistant