2016-04-24 5 views
-1
public class Book { 

    //variables 
    private String title = ""; 
    int isbn = 0; 
    int quantity = 0; 

    public Book(String title, int isbn, int quantity) throws Exception { 
     this.setTitle(title); 
     this.setIsbn(isbn); 
     this.setQuantity(quantity); 
    } 

    //toString method that return with book information 
    public String toString() { 
     String s = ""; 

     s = "title:" + this.title; 
     s = s + "\nIsbn:" + this.isbn; 
     s = s + "\nQuantity:" + this.quantity; 

     return s; 
    } 

    public void setTitle(String newTitle) throws Exception { 
     if ((newTitle != null)) { 
      this.title = newTitle; 
     } else { 
      BookException be = new BookException(); 
      be.setMessage("wrong input, title should not be blank."); 
      throw be; 
     } 
    } 

    public String getTitle() { 
     return this.title; 
    } 
} 

warum es gab kein Symbol im Code this.setIsbn(isbn) und this.setQuantity(quantity)Fix kann nicht Symbol in öffentlichen Klasse java

+0

Wo haben Sie die Methoden 'setIsbn' und' setQuantity'? –

Antwort

1

Da Ihre Klasse haben keine Methoden finden setIsbn und setQuantity Sie sie erstellen müssen und dann können nur Sie verwenden sie

public void setIsbn(int isbn) { 
    this.isbn = isbn; 
} 

public void setQuantity(int quantity) { 
    this.quantity = quantity; 
} 

Und auf ähnliche Weise sollten Sie auch Getter haben für diese

public int getIsbn() { 
    return this.isbn; 
} 

public int getQuantity() { 
    return this.quantity; 
} 
Verwandte Themen