Create a class named TennisGame that holds data about a single tennis game. The
class has six fields: the names of the two players, the integer final scores for the
players, and the String values of the final scores. Include a get method for each of
the six fields. Also include a set method that accepts two players’ names, and
another set method that accepts the two integer final score values. The integer final
score for a player is the number of points the player won during the game; this value
should be in the range of 0 through 4. If either of the set method parameters for a
score is not in the range of 0 through 4, assign 0 to both scores and assign “error” to
the String scores. If both players’ score parameters are 4, assign 0 to both scores
and “error” to the String scores. The String score values are set by the method that
sets the integer score values. The String final score for each player contains the
traditional names for points in tennis: love, 15, 30, 40, or game, respectively, for the
values 0 through 4. Create a subclass named DoublesTennisGame that includes two
additional fields for the names of the first two players’ partners. Include get methods
for the names. Override the parent class setNames() method to accept the names of
all four players. Write an application named DemoTennisGames that instantiates
several objects of each of these classes. Demonstrate that all the methods assign
correct values. Save the files as TennisGame.java, DoublesTennisGame.java,
and DemoTennisGames.java.
สร้างชื่อ TennisGame ระดับที่ใช้เก็บข้อมูลเกี่ยวกับเกมเทนนิสที่เดียว
ชั้นมีหกสาขา: ชื่อของผู้เล่นสองจำนวนเต็มสุดท้ายสำหรับคะแนนของ
ผู้เล่นและค่าของคะแนนสุดท้ายของสตริง รวมถึงวิธีการที่ได้รับแต่ละ
หกฟิลด์ วิธีการที่เจ็ด ได้แก่ รับสองชื่อของผู้เล่นและ
anothe กันยายนยอมรับวิธีการที่สุดท้ายคะแนนสองค่าจำนวนเต็ม จำนวนเต็มสุดท้าย
คะแนนสำหรับผู้เล่นคือจำนวนของจุดที่ได้รับรางวัลในระหว่างเกมที่ผู้เล่นนั้น ค่านี้
ควรอยู่ในช่วง 0 ถึง 4 หากทั้งสองของชุดพารามิเตอร์ใช้วิธีการสำหรับ
คะแนนไม่ได้อยู่ในช่วง 0 ถึง 4 ให้กำหนดและกำหนดคะแนนของ 0 ทั้งข้อผิดพลาด "" เพื่อ
คะแนนของสตริง ถ้าคะแนนผู้เล่นทั้งสองสี่พารามิเตอร์การกำหนดคะแนนของทั้ง 0
และ "ข้อผิดพลาด" ถึงคะแนนของสตริง ค่าคะแนน String เป็นวิธีที่เดือนกันยายนว่า
ตั้งค่าคะแนนจำนวนเต็ม คะแนนสุดท้ายสำหรับผู้เล่นแต่ละสายมี
ชื่อดั้งเดิมสำหรับคะแนนในเทนนิส: love, 15, 30, 40, หรือเกมตามลำดับสำหรับ
ค่า 0 ถึง 4 สร้างคลาสที่ชื่อ DoublesTennisGame ที่มีสอง
เขตข้อมูลเพิ่มเติมสำหรับชื่อของ พันธมิตรผู้เล่นสองคนแรก ' รวมถึงวิธีการได้รับ
สำหรับชื่อ SetNames แทนที่ระดับผู้ปกครอง () วิธีการที่จะยอมรับชื่อของ
ทั้งสี่ผู้เล่น เขียนแอพลิเคชันที่มีชื่อที่ DemoTennisGames instantiates
หลายแต่ละชั้นเรียนเหล่านี้ของวัตถุ แสดงให้เห็นว่าวิธีการทั้งหมดกำหนด
ค่าที่ถูกต้อง บันทึกไฟล์ที่เป็น TennisGame.java, DoublesTennisGame.java,
และ DemoTennisGames.java
การแปล กรุณารอสักครู่..
