java - Song Class, Using abstract class and interface -


what i'am trying program output information of song using tostring on song class. when output it, fine except songtype/genre. still outputting undetermined.

 abstract class song implements isong //song class  { private string name;  private string rating; private int id; private songtype genre;  public song() {     name = " ";     rating = " ";     id = 0;     genre = songtype.undetermined; } public song(string name, string rating, int id) {     this.name = name;     this.rating = rating;     this.id = id;     this.genre =song.undetermined; } public void setname(string name) {     this.name = name; } public void setrating(string rating) {     this.rating = rating; } public void setid(int id) {     this.id = id; } public string getname() {     return(this.name); } public string getrating() {     return(this.rating); } public int getid() {     return(this.id); }   @override public string tostring() {     return("song: " + this.name +            "\nid: " + this.id +            "\nrating: " + this.rating +            "\ngenre: " + this.genre); } }  class pop extends song //pop class {     public pop(string name, string rating, int id) {     super(name, rating, id); } }  interface isong //interface { public enum songtype {pop, country, hiphop, soul, undetermined;}  }  public class test{ public static void main(string [] args) {     song 1 = new pop("pop song", "five", 123);      system.out.println(one); }  } 

when output it, fine except songtype/genre. still outputting undetermined.

but set genre field songtype.undetermined?

i suggest give song class , isong interface public songtype getgenre() method returns current genre, appropriate setter method, public void setgenre(songtype genre) , constructors accept songtype genre parameter if need be. tostring() method should call getgenre() method current genre state.

most important, need set genre in concrete class other songtype.undetermined before trying print out.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -