Objectives:
Performing decisions using if and switch statements.
Lab Assignment:
Write a program that keeps track of the scores for the tennis set. Tennis set consists of games. Two win a set a player has to win at least six games and it has to win by at least two games. There is no tiebreaker in this program.
The games are scored starting at zero, the first point is 15, then 30, then 40, then game point, which wins the game. If the score is tied at 40, that is "deuce". At deuce the player that wins the next point has an "advantage". To break the tie, one player must win two points in a row. The player that wins the next point at "deuce" has "advantage". If player1 has an advantage and the second player wins the next point, then it goes back to deuce, and someone again must win by two points in a row. Yes, this could go on forever.
Hint:There are many ways to approach this problem. You may use two integer variables representing scores for player one and two. Each time a player scores the point increment the players score variable.
Use a switch statement to determine the actual score for example
score 0 represents 0
score 1 represents 15
score 2 represents 30
score 3 represents 40
after that use an if statement to determine if its a tie "deuce" or the players advantage.
Have fun.
What to turn in:The printed and electronic copies of your source code for Lab 5.
Important:
At the top of the program: place your name, date and brief description of the program.
Briefly explain the purpose of the variables used in your program.
Briefly explain code fragments.
Follow the proper code style conventions.
Staple all pages together at the top left corner.
Modularize your code (don't do all the work in actionPerformed, create methods). In this lab you should have at least 4 methods. Use comments and proper style. Explain the methods by writing comment before the method header. Method comment should explain what the method does, what it receive and what it returns.
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。