如何在新构造函数中调用以前构造的类?

时间:2013-10-30 17:47:40

标签: java

为我的CS类创建一个程序,基本上是一个程序(由我的教师创建)创建了一个程序,可以创建书名和作者,然后代码将通过我的程序运行,该程序将构建一个Book Class和Author Class来制作确定它们是可操作的我的问题是在我的教师代码“a3”的第12行,我的书类中调用了作者,我不知道如何在我的第二类构造函数中调用我的第一个类。 因为我得到一个错误,说“期待三点。”

//my code

public class Author {
  String firstName;
  String lastName;
  //variables
  public Author (String a) {
    firstName = a;
  }
  public Author (String a, String b) {
    firstName = a;
    lastName = b;
  }
}


public class Book {
  String Title;
  String a;
  //variables
  public Book (String c, Author) {
    Title = c;
  }
  public Book () {
  }
}





// instructor's code

  void setup() { 
  Book [] allTheBooks = new Book[30]; 
  int score = 6; 
  int tScore = 0;

  System.out.println( "Attempting constructors:" );

  Author a1 = new Author( "Ballard", "J.G." );
  Author a2 = new Author( "Eggers", "Dave" );
  Author a3 = new Author( "Catton", "Eleanor" );
  Author a4 = new Author( "Adler", "Renata" );


  System.out.println( "  - Author constructors seem functional:  3/3" );



  allTheBooks[1] = new Book( "The Circle" );
  allTheBooks[2] = new Book( "The Luminaries", a3 );
  allTheBooks[3] = new Book();
  allTheBooks[4] = new Book( "Pitch Dark" );
  allTheBooks[5] = new Book( "Speedboat" );
  allTheBooks[6] = new Book();
  allTheBooks[7] = new Book( "The Dissident Gardens" );

  System.out.println( "  - Book constructors seem functional:    3/3" );
}

0 个答案:

没有答案