Java 如何在一条路径中生成结果?
这是我的代码:Java 如何在一条路径中生成结果?,java,arrays,oop,Java,Arrays,Oop,这是我的代码: import java.util.Arrays; public class BookClasss { private String name; public AuthorClass[] author ; private double price ; private int qty =0; public BookClasss(String names, AuthorClass[] authors, double price2, int qtyes) {
import java.util.Arrays;
public class BookClasss {
private String name;
public AuthorClass[] author ;
private double price ;
private int qty =0;
public BookClasss(String names, AuthorClass[] authors, double price2,
int qtyes)
{
this.name = names;
this.author = authors;
this.price = price2;
this.qty = qtyes;
}
public void SetBookDetails (String names, AuthorClass[] authors,double price2 , int qtyes)
{
this.name = names;
this.author = authors;
this.price = price2;
this.qty = qtyes;
}
public String Getbookname()
{
return name;
}
public double getprice()
{
return price;
}
public void setprice (double prices)
{
price = prices;
}
public void setQty (int qtnties)
{
qty = qtnties;
}
public int getQty ()
{
return qty;
}
public void GetAll ()
{
for (int i=0; i<author.length;i++)
{
System.out.println("Book name : "+name+", Authors : "+Arrays.asList(author[i].ToAll())+" , Price : "+price+"");
}
}
}
Book name : Java OOP, Authors : [Author Name=John , Mail = John@yahoo.com] , Price : 120.2
Book name : Java OOP, Authors : [Author Name=Sam , Mail = Sam@yahoo.com] , Price : 120.2
我使用forloop获得所有作者的数组结果,但我希望打印结果如下:
Book name : Java OOP, Authors : [Author Name=John , Mail = John@yahoo.com] , [Author Name=Sam , Mail = Sam@yahoo.com] , Price : 120.2
在一个结果中,不重复书名和价格。。我该怎么做?有人能帮我吗
public void GetAll()
{
System.out.println(“书名:+name+”,作者:);
for(int i=0;iClasses的名称中不应包含Class
。就像您不命名方法一样getAllMethod()
或变量namevaluate
,类不应被称为AuthorClass
。此外,标准的Java约定是以小写字母开头方法名称。但你所指的类的名称中不应包含class。?@shmoselPost在问题注释中。同样,错误的部分。他可能不会注意到。
Book name : Java OOP, Authors : [Author Name=John , Mail = John@yahoo.com] , [Author Name=Sam , Mail = Sam@yahoo.com] , Price : 120.2
public void GetAll ()
{
System.out.println("Book name : "+name+", Authors : ");
for (int i=0; i<author.length;i++)
{
System.out.print(Arrays.asList(author[i].ToAll())+" ,");
}
System.out.println("Price : "+price+"");
}