Programming 2: Assignment 1 Solved

30.00 $

Categories: ,
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . zip solution files instantly, after Payment


5/5 - (1 vote)

Please submit your code to Blackboard under the correct assignment folder by 11:59pm on the due date. Place all Java source code (Classes with extension .java) into a folder with your name and student id eg: Jack_Bloggs_1293849 and zip it up (

Question 1) : Tennis Game (25 marks)
Scoring in a single game of tennis starts with love-all, then scores of 15, 30, and 40. A player wins when they are two points ahead of their opponent and has a score of over 40. The terms advantage server, deuce (tied score), and advantage receiver are used when the score is 40 all. If scores are 40 all, a player needs to win two points in a row in order to win the game. They first must obtain the advantage with the first point and then get another point to win the game, if they fail in obtaining the second point then the scores are reset to 40 all.
Prepare a class called TennisGame that can be used to encapsulate the score in a game of tennis.
 It has a constructor which is used to initialize the game.
 It holds two variables which keep an integer score for both server and receiver
 Two constants which define SERVER and RECEIVER as identifiers.
 A getScore method which converts pointsServer and pointsReceiver to a String which holds current scores for each player in a tennis style format. “Eg Server 40: Receiver love”
 HINT: A convertPointsToScore helper method which converts points into actual tennis score strings such as “love”, “15” may be useful.
 A givePoint method which gives a point using the constant SERVER or RECEIVER
 isWinner which returns true if there is a winner
 isWinner overloaded method which returns true whether either the SERVER or RECEIVER have won.
Use the following UML as a guide but feel free to add any private helper methods.
Write a driver program called TennisSet which prompts the user for two player names and passes them into the constructor. The TennisSet holds a flag as to which of the two players is serving. The program should play a set of five games of tennis between two players, playerA and playerB (randomly choosing the winner of each point) and ideally alternating the server for each game. It
should output a commentary of the progress and result of each game.
Use the above UML as a guide.

Question 2) : Simple Slot Machine (10 marks)

Write a class called SimpleSlotMachine that simulates a slot machine in which three numbers between 0 and 9 are randomly selected and printed side by side. This is done using a “pullLever” method. Print an appropriate statement if all three of the numbers are the same, or if any two of the numbers are the same. Continue playing until the user chooses to stop. Then add a field which keeps track of the number of times the pullLever method has been called across ALL
SimpleSlotMachine instances.

Question 3): HitList using Caesar Cipher. (15 marks)

Create a class called HitList which implements the Encryptable interface.
 It should hold victim names as capital letters inside an underlying List called targets.
 By implementing Encryptable, the class should encrypt all elements in the underlying target
List using the specified key and using a Caesar cipher algorithm.
 The key (although a char array) will contain just one character. For example if the key is ‘C’ then all characters need to be rotated by 2 places and wrapping around (So A becomes C, B becomes D, C becomes E, …, X becomes Z, Y becomes A, Z becomes B). If the key is ‘D’ then all characters need to be rotated by 3.
 The reverse is used to decrypt by rolling backward.
 To keep things simple keep all information added to the target list and the encrypt/decrypt key as upper case (ignore all other characters and spaces).
 It has methods for adding and removing names from the list (As an encrypted form if the list is currently encrypted or else it just adds the name in its normal unencrypted form)
 A suitable toString that prints out the victims at each line (either encrypted or decrypted).
 Feel free to add any private helper methods to the class and include a main method for testing.