Java 英文编程题【急】Implement a class named textBook which has two attributes:pages for the number of pages and title for the textbook’s title.Then write a derived class mathBook which has two inherited attributes and two new attributes:de
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/27 11:50:16
Java 英文编程题【急】Implement a class named textBook which has two attributes:pages for the number of pages and title for the textbook’s title.Then write a derived class mathBook which has two inherited attributes and two new attributes:de
Java 英文编程题【急】
Implement a class named textBook which has two attributes:pages for the
number of pages and title for the textbook’s title.Then write a derived class
mathBook which has two inherited attributes and two new attributes:definitions
and average.The definitions is an integer representing the number of defined
words in the mathBook.The average is:
number of definitions
number of pages
which is of type double.The class mathBook should also define a new method
getAverage() which prints and returns the average number of definitions per
page.
Java 英文编程题【急】Implement a class named textBook which has two attributes:pages for the number of pages and title for the textbook’s title.Then write a derived class mathBook which has two inherited attributes and two new attributes:de
class TextBox
{
TextBox(int pages,String title)
{
this.pages=pages;
this.title=title;
}
int pages;//页数
String title;//标题
}
class MathBook extends TextBox
{
MathBook(int d)
{
definitions=d;
}
int definitions;//定义过的word的数量
double average;//每页定义的word的平均数量
double getAverage()
{
return average=(double)definitions/page;
}
}