2016-09-21 3 views
-1
  1. この私のコード:結果を1つのパスにする方法は?

    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+""); 
        } 
    
        } 
    
    } 
    
  2. そして、それが主な方法です:

    public class TestBook 
    { 
        public static void main(String[] args) 
        { 
    
         AuthorClass[] authors = new AuthorClass[2]; 
         authors[0] = new AuthorClass("John" , "[email protected]" , 'M'); 
         authors[1] = new AuthorClass("Sam" , "[email protected]" , 'M'); 
         BookClasss book = new BookClasss("Java OOP",authors, 200.5, 20); 
         book.GetAll(); 
    
        } 
    
    } 
    
  3. 、出力は次のとおりです。

    Book name : Java OOP, Authors : [Author Name=John , Mail = [email protected]] , Price : 120.2 
        Book name : Java OOP, Authors : [Author Name=Sam , Mail = [email protected]] , Price : 120.2 
    

    私はすべてを取得するためにforloopを使用著者の配列の結果が表示されますが、結果は以下のようになります:

    Book name : Java OOP, Authors : [Author Name=John , Mail = [email protected]] , [Author Name=Sam , Mail = [email protected]] , Price : 120.2 
    

    書籍名と価格を繰り返すことなく1つの結果にできます。どうすればいいですか?
    誰でも私を助けることができますか?

+1

クラスは名前に 'Class'を持つべきではありません。 – shmosel

+0

メソッド 'getAllMethod()'または変数 'nameVariable'の名前を付けないのと同様に、クラスは' AuthorClass'と呼ばれるべきではありません。 – shmosel

+0

また、Javaの標準的な規則は、メソッド名を小文字で開始することです。 – shmosel

答えて

0
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+""); 
    } 
+0

それはありがとうalot :)(y)の –

+0

が働いていますが、クラスでは、名前でクラスを持つべきではないことを意味します。 ?? @shmosel –

+0

投稿する質問のコメント。 –

関連する問題