联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2019-10-17 10:11

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

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


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp