LAB Seatwork 04292026
2026-04-29 21:49
Tags: #java
Author: Duke Hsu
Key takeaways
- Using Inheritance and Encapsulation create a number guess games .
- Parent class
Character - Child classes
Player,Monster - Including
whileloop,if-elsestatement - Using GETTER and SEETER update and get data
Program logical
- Import the required classes (
ScannerandRandom) - Generate a random number (1–6) as the secret number
- Prompt the user to enter a guess
- Check the result:
- Correct guess → Monster - 20 HP
- Wrong guess → Player - 10 HP
UML
Code Example
Main Class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
Parent Class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
Child class Player
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Child class Monster
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
