Hey all.. I have 3 classes in my program but Iam having trouble accesing a method in another class. Iam getting the error message cannot find symbol method printInfo(). Below is the code
class Book{
private String author;
private String title;
private int year;
private Chapter first;
private Chapter second;
private Chapter third;
public Book(){
author="";
title="";
year=0;
first= new Chapter("Chapter 1",0);
second=new Chapter("Chapter 2",0);
third=new Chapter("Chapter 3", 0);
}
public void Book(String author, String title,int year,Chapter first,Chapter second,Chapter third){
this.author=author;
this.title=title;
this.year=year;
this.first=first;
this.second=second;
this.third=third;
}
public String getAuthor()
{
return author;
}
public String getTitle()
{
return title;
}
public int getYear()
{
return year;
}
private int TotalPages()
{
int total=0;
total=first.getPages();//+second.getPages()+third.getPages;
return total;
}
public void printInfo()
{
System.out.println("Book title: " +getTitle());
System.out.println("");
System.out.println("Book Author:" +getAuthor());
System.out.println("");
System.out.println("Year:" +getYear());
System.out.println("");
// System.out.println("Number of pages:" +getPages());
System.out.println("");
}
public void printContents()
{
System.out.println("Contents:");
// System.out.println("1." +getTitle()"........." +getPages());
// System.out.println("");
// System.out.println("2." +getTitle()"...........:" +getPages()"\n");
// System.out.println("");
// System.out.println("3."+getTitle()"...........:" +getPages()"\n");
// System.out.println("");
}
}
class Chapter
{
private String title;
private int numberOfPages;
/*public Chapter()
{
title="";
numberOfPages=0;
}*/
public Chapter(String title, int numberOfPages)
{
this.title=title;
this.numberOfPages=numberOfPages;
}
public String getTitle()
{
return title;
}
public int getPages()
{
return numberOfPages;
}
}
class mainPrg
{
public static void main (String[] args)
{
Chapter chptobj1=new Chapter("Introduction",100);
Chapter chptobj2=new Chapter("Main Ideas", 150);
Chapter chptobj3=new Chapter("Conclusion", 200);
Book bkobj1=new Book();
chptobj1.printInfo();
}
}
I would also like to get any advice on how I can improve on the code and reasons for the suggestions. Thank you.
Iam also getting the following errors:
1. "( expected in line 68"
2. "cannot find method getPages" in line 61