95-712 Practice problem 8
This problem brings together what you learned in inheritance,
polymorphism, access specifiers, and JavaFX
Problem statement: The GUI for this app is provided to you
(Fig.1). It currently supports three pets: Cat, Dog, and Bird.
User clicks on the any one of the three pet buttons, and the
app displays the sound made by that pet. It also displays a
count of number of times the user clicks on each pet. (Fig.2, 3, 4). You
need to create the Pet classes and write event-handlers to complete the app.
Figure 2: User clicked Cat once Figure 3: Then user clicked Dog once Figure 4: Then user clicked Dog again, and then Bird
Solution Design: The UML in Figure 5 shows classes, their methods and variables. The app is launched from PickAPet.java.
Its GUI has three buttons as shown in Fig.1. You need to do the following
95-712留学生作业代做、代写Java编程设计作业
1. Create an abstract Pet class with abstract talk() method, and a variable petCount to count all pets selected by user.
2. Create Cat, Dog, and Bird classes that extend Pet and implement talk() that returns a string “Meow…”, “Bark…”, and
“Tweet…” respectively. They also have their own count variables to count the number of times they are chosen.
3. Create three handlers as member classes in PickAPet.java to update countLabels and resultLabel as shown in Figure
2, 3, 4. Bind them to the three buttons in setupScreen() method - buttons[0], buttons[1], and buttons[2].
4. Finally, run the test-cases to check correct execution of your program.
Figure 5: Solution Design
Note: The pet objects are already created for you and stored in pets array in PickAPet.java. You should not be creating
any new pet objects.
main(args: String[]): void
resultLabel: Label
countLabels: Lable[]
start(primaryStage: Stage): void
setupScreen(): void
<<Interface>>
ActionEvent
EventHandler
handle(event:ActionEvent): void
Application
start(primaryStage: Stage): void
Figure 1: GUI components in opening screen
因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:[email protected]
微信:codehelp
原文地址:https://www.cnblogs.com/weljavat/p/11700020.html