首页 > > 详细

Java辅导:O BJECT -O RIENTED P ROGRAMMING I NDIVIDUAL P ROJECT 02辅导留学生Java语言

Introduction
:
,,,

:
,.
Requirement
O BJECT -O RIENTED P ROGRAMMING
I NDIVIDUAL P ROJECT 02
Project 02 Background
This is an individual programming assignment. It is not to be completed as part
of a team or with a peer programming partner.
Your goal is to create a program that is made up of seven classes:
CSC211Project2
Project2Panel
Student
Textbook
DrawableInterface
DrawableStudent
DrawableTextbook
The application should draw two students
and have the left student toss a textbook that
bounces between the two students. A demo of
the application and several files to help you
get started are available for download on the
course web site.
The project’s learning objective is to use inheritance to quickly create a pair of new object classes
that take advantage of work performed in previous labs and projects. The UML below shows
how these classes relate together.
+getX(): int
+getY(): int
+getLocation(): Point
+moveTo(absX: int, absY: int): void
+moveTo(whereToGo: Point): void
+moveBy (dX: int, dY: int): void
+move (): void
+getVelocityX(): double
+getVelocityY(): double
+setVelocity(dvX: double, dvY: double): void
+getColor(): Color
+setColor(theColor: Color): void
+draw(pen: Graphics): void
«interface»
DrawableInterface
+tossBook(): void
-Location: Point
-xVelocity: double
-yVelocity: double
-shirtColor: Color
-myBook: DrawableTextbook
DrawableStudent
-getBookInitials: String
-checkBounds(pen: Graphics): void
-Location: Point
-xVelocity: double
-yVelocity: double
-bookColor: Color
DrawableTextbook
+getName: String
+getBook: Textbook
+getHealth: double
+getKnowledge: int
+setName(theName: String): void
+learnSomething(numPages: int): int
-name: String
-book: Textbook
-health: double
-knowledge: int
Student
+getSubject: String
+getPageCount: int
+getUnreadPageCount: int
+getWeight: double
+readPages(numPages: int): int
-subject: String
-pageCount: int
-unreadPageCount: int
Textbook
REQUIREMENTS FOR EACH CLASS CAN BE FOUND BELOW:
The Textbook Class
You should re-use your Textbook class from Project 1. To help resolve any issues or errors
you may have had in implementing the class, a model solution has been posted on the course
web site in the Project02 Starter Package.
The Student Class
You should re-use your Student class from Project 1. To help resolve any issues or errors you
may have had in implementing the class, a model solution has been posted on the course web
site in the Project02 Starter Package.
The Interface DrawableInterface
In Lab 06 you designed the Java interface DrawableInterface and implemented it in the
Ball and Block classes. In this project, you will re-use that interface. The requirements for the
interface DrawableInterface can be found in the UML diagram above. This interface and its
methods should be fully documented using javadoc style. comments.
The DrawableStudent Class
The DrawableStudent class represents the visualization of a university student. It should
have all the characteristics and behaviors of a Student, but also implement the
DrawableInterface. You should implement all methods described in the interface,
similar to the steps you took in Lab 06, except, instead of using a data field for the x-
position and a data field for the y-position, use a single Point object.
Because we need to draw our textbook, the Textbook data field of our parent will not be
enough. We need to create our own DrawableTextbook data field, myBook. Yet, we still
want to take advantage of the parent class implementation, so at the end of the constructor,
call setBook(myBook) to replace the default parent class Textbook with your
DrawableTextbook.
The DrawableStudent class needs a tossBook method that sets the velocity of the
DrawableTextbook. You only need to set the x-velocity so the textbook moves to the right.
If all the classes are implemented properly, the textbook will sense when it gets to the right
side of the window and revers direction back to the student.
The DrawableTextbook Class
The DrawableTextbook class represents the visualization of a university-level textbook. It
should have all the characteristics and behaviors of a Textbook, but also implement the
DrawableInterface. You should implement all methods described in the interface, similar to
the steps you took in Lab 06, except, instead of using a data field for the x-position and a data
field for the y-position, use a single Point object.
You can use the following Java code to implement the DrawableTextbook class draw method:
public void draw(Graphics pen)
{
checkBounds(pen);
pen.setColor(bookColor);
pen.fillRect(xPosition, yPosition, 50, 70);
pen.setColor(Color.DARK_GRAY);
pen.setFont(new Font(“Monospaced”, Font.BOLD, 20));
pen.drawString(getBookInitials(), xPosition, yPosition+50);
}
This method calls two private DrawableTextbook methods, getBookInitials and
checkBounds that you must implement.
The checkBounds method should perform. similar to the checkPosition method in the two
previous labs. If the book has moved to the edge of the window, the velocity in that direction
should be reversed and the book moved back into the window if it moved off.
Since this method is a DrawableTextbook method, we don’t have access to the Panel
dimensions. You can use the following code to get the clipping rectangle for the Panel by asking
the Graphics object pen:
Rectangle edgeRect = pen.getClipBounds();
The method getBookInitials creates and returns a string made up of the first letter of each
word in the textbook subject. Here are pseudo-code statements that perform. the task:
String bookSubject = some string to parse
String initials = bookSubject.substring(0,1);
for (int i = 0; i

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!