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 above class is a simple DvdName class. It has a titleName property, which is set in the constructor, and the setter and getter methods. In addition, it has a setNameStarsOn method, which replaces all spaces in the titleName with a '*' character, and a method which reverses that. Finally, it has a toString method which returns the object as a String.

Questions about programming?Chat with your personal AI assistant