mercredi 14 septembre 2016

Setter and Getter need test? And setter in UML

At first , that's the teacher's feedback:"UML lacks setters; use meaningful identifiers (not single characters); getters and setters not tested."

    class Book {
   private String title;
   private String author;
   private String publisher;
   private String date;
   public Book(String t, String a, String p, String d) {
      this.title =     t;
      this.author =    a;
      this.publisher = p;
      this.date =      d;
   }
   public String gettitle() {
      return title;
   }
   public String getauthor() {
      return author;
   }
   public String getpublisher() {
      return publisher;
   }
   public String date() {
      return date;
   }
   public void settitle(String t) {
      this.title=t;
   }
   public void setauthor(String a) {
      this.author=a;
   }
   public void setpublisher(String p) {
      this.publisher=p;
   }
   public void setdate(String d) {
      this.date=d;
   }
   public String toString() {
      String s = "";
      s += "Title     :"+title+"\n"; 
      s += "Author   :"+author+"\n";
      s += "Publisher :"+publisher+"\n";
      s += "Date      :"+date+"\n";
      return s;
   }
}

and the main method:

public class Bookshelf {
   public static void main(String[] args) {
      Book n1 = new Book("Java\n","Alfred\n","Nemski\n","1998");
      Book n2 = new Book("PHP\n","Cole\n","Fisher\n","1991");
      Book n3 = new Book("Flash\n","Arena\n","Gold\n","1990");
      Book n4 = new Book("SQL\n","Oracle\n","Tomb\n","2001");
      System.out.println("Book 1:");
      System.out.println(n1);
      System.out.println("");
      System.out.println("Book 2:");
      System.out.println(n2);
      System.out.println("");
      System.out.println("Book 3:");
      System.out.println(n3);
      System.out.println("");
      System.out.println("Book 4:");
      System.out.println(n4);
   }
}

Finally, my UML is below(I dont understand what's setters in UML, that means it need the set and get in a new file at the UML?)

enter image description here

Aucun commentaire:

Enregistrer un commentaire