Java 使用方法将书本添加到库数组

Java 使用方法将书本添加到库数组,java,methods,Java,Methods,在这个程序中,我需要将4本书添加到一个库中。代码是针对我的book类的,但我需要在我的library类的另一个文件中创建一个包含4个参数的方法,该方法将把书添加到库数组中。在main中有第三个文件,我将在其中全部打印出来,但我无法解决这个问题 书的例子:作者小丑,标题个人主义,价格-5.50,isbn-978-52-234-43-012 private String author; private String title; private double price; private int i

在这个程序中,我需要将4本书添加到一个库中。代码是针对我的book类的,但我需要在我的library类的另一个文件中创建一个包含4个参数的方法,该方法将把书添加到库数组中。在main中有第三个文件,我将在其中全部打印出来,但我无法解决这个问题

书的例子:作者小丑,标题个人主义,价格-5.50,isbn-978-52-234-43-012

private String author;
private String title;
private double price;
private int isbn;

public book(String a, String t, double p, int i){
    author=a;
    title=t;
    price=checkPrice(p);
    isbn=checkIsbn(i);
}

在Book类中创建getter和setter,并在Library类中创建以Book对象为参数的方法。
//First and foremost you need to create the book object

public class Book extends Library{
private String author;
private String title;
private double price;
private int isbn;

//Null Constructor-this creates
public book() {
this.author = abcd;
this.title = abcd;
this.price = 0.0;
this.isbn = 0000000;
}

//Now its time for the book with parameters
public book(String a, String t, double p, int i){
author = a;
title = t;
price = p;
isbn = i;
    }

//Now it's time to set and get the above values you want
public void setAuthor(String author){
this.author = author;
}

public String getAuthor(){
return this.author;
}

public void setTitle(String title){
this.title = title;
}

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

public void setPrice(double price){
this.price = price;
}

public double getPrice(){
return this.price;
}

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

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

//Now you are going to want to toString(), that way you can display the books in the library
public String toString() {
//Im assuming you have learned that Library is your super class and has a toString() as well
return(super.toString()+ "Book Author: " + this.author + "Book Title: " + this.title + "Book Price: " + this.price + "Book ISBN: " + this.isbn);    

}
}
//Now simply call this method within your main method to display books in Output!! 
//Hope this helps, if you have further questions please leave below!!