В приведенном ниже коде постоянно выдается следующая ошибка: Снимок экрана терминала Java с ошибкой
Я пробовал довольно много онлайн-исправлений, но, похоже, они не работают,Мой код ниже, и я прокомментировал местоположение ошибки (происходит в основной функции драйвера)
ПРИМЕЧАНИЕ. Код компилируется правильно, если я изменяю public static void main (String args []) to public void main (String args []) , но когда я его запускаю, выдается ошибка " Заменить main на static void main ".Я немного застрял здесь.
import java.util.*;
class Exercise{ //Exercise Begins
class UtilityFunctions{
public String getAuthor(){ return "";};
public String getPublisher(){return "";};
public void display(){};
}
class Book extends UtilityFunctions{
private String title;
private String author;
private String category;
private String datePublished;
private String publisher;
private double price;
public Book(String authorParam, String publisherParam){
author = authorParam;
publisher = publisherParam;
}
//List of Setters
public void setTitle(String title){
this.title = title;
}
public void setCategory(String cat){
this.category = cat;
}
public void setDatePublished(String dp){
this.datePublished = dp;
}
public void setPrice(double p){
this.price = p;
}
//List of Getters
public String getTitle(){
return this.title;
}
@Override
public String getAuthor(){
return this.author;
}
public String getCategory(){
return this.category;
}
public String getDatePublished(){
return this.datePublished;
}
@Override
public String getPublisher(){
return this.publisher;
}
public double getPrice(){
return this.price;
}
@Override
public void display(){
System.out.println("Book Title:" + getTitle());
System.out.println("Author:" + getAuthor());
System.out.println("Category:" + getCategory());
System.out.println("Date Published:" + getDatePublished());
System.out.println("Publisher:" + getPublisher());
System.out.println("Price:$" + getPrice());
}
}
class Author extends UtilityFunctions{
private String authorName;
private String birthDate;
private String publisher;
private String email;
private String gender;
List<Book> bookList;
public Author(String publisherParam){
publisher = publisherParam;
}
public void addBook(Book b){
bookList.add(b);
}
//List of Setters
public void setName(String n){
this.authorName = n;
}
public void setEmail(String em){
this.email = em;
}
public void setGender(String gen){
this.gender = gen;
}
public void setBirthDate(String dob){
this.birthDate = dob;
}
//List of Getters
public String getAuthor(){
return this.authorName;
}
public String getPublisher(){
return this.publisher;
}
public String getEmail(){
return this.email;
}
public String getGender(){
return this.gender;
}
public String getBirthDate(){
return this.birthDate;
}
@Override
public void display(){
System.out.println("Author Name:" + getAuthor());
System.out.println("Email:" + getEmail());
System.out.println("Gender:" + getGender());
System.out.println("BirthDate:" + getBirthDate());
System.out.println("Publisher:" + getPublisher());
System.out.println("BOOKS:");
for(Book b:bookList){
b.display();
System.out.println();
}
}
}
class Publisher extends UtilityFunctions{
private String publisherName;
private String publisherAddress;
private String publisherEmail;
private int publisherPhoneNumber;
List<Author> authorList;
public Publisher(String name, String add, String email,int phone){
publisherName = name;
publisherAddress = add;
publisherEmail = email;
publisherPhoneNumber = phone;
}
public void addAuthor(Author a){
authorList.add(a);
}
//List of Getters
public String getPublisher(){
return this.publisherName;
}
public String getAddress(){
return this.publisherAddress;
}
public String getEmail(){
return this.publisherEmail;
}
public int getPhoneNumber(){
return this.publisherPhoneNumber;
}
@Override
public void display(){
System.out.println("Publisher Name:" + getPublisher());
System.out.println("Publisher Address:" + getAddress());
System.out.println("Publisher Phone Number:" + getPhoneNumber());
System.out.println("Publisher Email:" + getEmail());
System.out.println("AUTHORS:");
for(Author a:authorList){
a.display();
System.out.println("-------------------------------------");
}
System.out.println("--------------------------------------------------------------------------------");
System.out.println("--------------------------------------------------------------------------------");
}
}
public static void main(String args[]){
ArrayList<Publisher> publisherList = new ArrayList<Publisher>();
//1st ERROR HERE
Publisher pub1 = new Publisher("Riverhead Books","8080 Cross Street","riverhead@riverheadbooks.co.uk",784646533);
//2nd ERROR HERE
Author author1 = new Author(pub1.getPublisher());
author1.setName("Khaled Hosseini");
author1.setGender("Male");
author1.setBirthDate("1965-10-09");
author1.setEmail("khaledhosseini@gmail.com");
pub1.addAuthor(author1);
//3rd ERROR HERE
Book book1 = new Book(author1.getAuthor(),author1.getPublisher());
book1.setTitle("Kite Runner");
book1.setCategory("Historical-Fiction|Drama");
book1.setPrice(39.95);
book1.setDatePublished("2003-05-29");
author1.addBook(book1);
publisherList.add(pub1);
for(Publisher p:publisherList){
p.display();
}
}
} // Концы упражнений