我正在使用 java 进行 Objects 的练习以进行自我审查。我遇到问题的练习部分是它要求我找到 refNumber 字符串的长度。如果字符串的长度为零,则打印出一行“zzz”。我尝试通过创建一个局部变量并使其等于 refNumber.length() 来做到这一点。但是,在我的条件语句中,bluejay 表明我的类型不兼容。呃,请帮忙。提前致谢。
class Book
{
// The fields.
private String author;
private String title;
private int pages;
private String refNumber;
/**
* Set the author and title fields when this object
* is constructed.
*/
public Book(String bookAuthor, String bookTitle, int numberOfPages)
{
author = bookAuthor;
title = bookTitle;
numberOfPages = pages;
refNumber = "";
}
public String getAuthor()
{
return author;
}
public String getTitle()
{
return title;
}
public int getPages()
{
return pages;
}
public String getRefNumber()
{
return refNumber;
}
public void setRefNumber(String ref){
ref = refNumber;
}
public void printTitle() {
System.out.println("Book desciption: " + title);
}
public void printAuthor() {
System.out.print(" by " + author);
}
public void printPages(){
System.out.println("Pages: " + pages);
}
public void printRef(){
int count = refNumber.length();
if (count = 0){ //incompatible type wtf?
System.out.println("zzz");
}
else {
System.out.println("Reference Number: " + referenceNumber);
}
}