我很清楚,這種編碼有錯誤(只在java 4周),但我不知道如何解決它。意外類型;要求:變量;發現:值
EDIT2:與現在的代碼的唯一錯誤(它告訴我至少)是所需的類型是可變的,它發現在以下行的值: if(yearPublished = 0 & monthPublished = 0)
/**
* This class describes a book.
* @author Tess Robertson
* @version 10/06/2014
*/
class Book
{
/**
* Instance variables
*/
private String title;
private int bookNumber;
private String lastName;
private String firstName;
private int yearPublished;
private int monthPublished;
private String monthName;
/**
* Default constructor
*/
public Book()
{
}
/**
* Another constructor
* @param initialTitle - the book's title
* @param initialBookNumber - the book's ISBN
* @param initialLastName - the author's last name
* @param initialFirstName - the author's first name
* @param initialYearPublished - the book's publication year
* @param initialMonthPublished - the book's publication month number
* @param initialMonthName - the book's publicaton month name
*/
public Book(String initialTitle, int initialBookNumber, String initialLastName, String initialFirstName, int initialYearPublished, int initialMonthPublished, String initialMonthName)
{
title = initialTitle;
bookNumber = initialBookNumber;
lastName = initialLastName;
firstName = initialFirstName;
yearPublished = initialYearPublished;
monthPublished = initialMonthPublished;
monthName = initialMonthName;
}
/**
* @return the book's title
*/
public String getTitle()
{
return title;
}
/**
* @return the book's ISBN
*/
public int getBookNumber()
{
return bookNumber;
}
/**
* @return the author's last name
*/
public String getLastName()
{
return lastName;
}
/**
* @return the author's first name
*/
public String getFirstName()
{
return firstName;
}
/**
* @return the book's publication year
*/
public int getYearPublished()
{
return yearPublished;
}
/**
* @return the book's publication month
*/
public int getMonthPublished()
{
return monthPublished;
}
/**
* @return the book's publication month name
*/
public String getMonthName()
{
return monthName;
}
/**
* @return the author's full name
*/
public String getFullName()
{
return firstName+lastName;
}
/**
* Prints the title, ISBN, Author full name, and publication year and date
*/
public String printDetails()
{
if(title!=null||title.length()>3)
{
return ("Title: "+title);
}
else if(title==null||title.length()<=3)
{
return ("Title: "+"invalid text");
}
if(bookNumber>=10000&&bookNumber<=20000)
{
return ("ISBN: "+bookNumber);
}
else if(bookNumber==0)
{
return ("ISBN: "+"invalid number");
}
if(lastName==null||firstName==null)
{
return ("Author: "+"invalid text");
}
else
{
return ("Author: "+firstName+" "+lastName);
}
if(yearPublished = 0 & monthPublished = 0)
{
return ("Published: "+"invalid number");
}
else
{
return ("Published: "+monthName+" "+yearPublished);
}
}
/**
* Recieve a book title
* @param newTitle - the title entered by the user
*/
public void setTitle(String newTitle)
{
if(newTitle.length()>3)
{
newTitle=title;
}
else
{
System.out.println("Book title must have more than 3 characters.");
}
}
/**
* Recieve an ISBN
* @param newBookNumber - the ISBN entered by the user
*/
public void setBookNumber(int newBookNumber)
{
if(newBookNumber>=10000&&newBookNumber<=20000)
{
newBookNumber=bookNumber;
}
else
{
System.out.println("ISBN must be a number between 10000 and 20000 inclusive.");
}
}
/**
* Recieve author's last name
* @param newLastName - the last name entered by the user
*/
public void setLastName(String newLastName)
{
if(newLastName != "null")
{
lastName=newLastName;
}
else
{
System.out.println("Author's last name cannot be blank.");
}
}
/**
* Recieve author's first name
* @param newFirstName - the first name entered by the user
*/
public void setFirstName(String newFirstName)
{
if(newFirstName != null)
{
newFirstName=firstName;
}
else
{
System.out.println("Author's first name cannot be blank.");
}
}
/**
* Recieve a publication year
* @param newYearPublished - the year of publication entered by the user
*/
public void setYearPublished(int newYearPublished)
{
if(newYearPublished<=2013&&newYearPublished>=1870)
{
newYearPublished=yearPublished;
}
else
{
System.out.println("Year published must be between 1870 and 2013 inclusive.");
}
}
/**
* Recieve a publication month
* @param newMonthPublished - the month of publication entered by the user
*/
public void setMonthPublished(int newMonthPublished)
{
if(newMonthPublished>=1&&newMonthPublished<=12)
{
newMonthPublished=monthPublished;
}
else
{
System.out.println("Month published must be between 1 and 12 inclusive.");
}
}
/**
* Set monthName given monthPublished
*/
public void setMonthName(String monthName)
{
if(monthPublished==1)
{
monthName="January";
}
else if(monthPublished==2)
{
monthName="February";
}
else if(monthPublished==3)
{
monthName="March";
}
else if(monthPublished==4)
{
monthName="April";
}
else if(monthPublished==5)
{
monthName="May";
}
else if(monthPublished==6)
{
monthName="June";
}
else if(monthPublished==7)
{
monthName="July";
}
else if(monthPublished==8)
{
monthName="August";
}
else if(monthPublished==9)
{
monthName="September";
}
else if(monthPublished==10)
{
monthName="October";
}
else if(monthPublished==11)
{
monthName="November";
}
else if(monthPublished==12)
{
monthName="December";
}
}
}
你能不能更清楚一點,你想要什麼?什麼是錯誤?我們無法修復此代碼的完整語法錯誤。 – 2014-10-08 19:38:13
告訴我們*出現了哪些錯誤,*它們是哪裏,以及*刪除了與該問題無關的代碼。這實際上毫不費力地縮小問題範圍併發佈一個連貫的問題。 – tnw 2014-10-08 19:38:42
另外,幾乎在每一個你的方法中,你都將你的參數與你的類屬性混合在一起。對於前者,setBookNumber將*參數*設置爲*類屬性*,否則應該是相反的。 – tnw 2014-10-08 19:43:15