CSCD 210 Homework #4

$35.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (2 votes)

 

1Write a Java program that plays the kids’ game rock-paper-scissors (RPS). Assume scissors win vs. paper, paper wins vs. rock and rock wins vs. scissors. The program randomly generates one of rock, paper, or scissors for the computer’s move. The program prompts the user to enter a string value (one of “rock”, “paper” or “scissors”; all other inputs should be treated as illegal and the user should be prompted to re-enter their input). The program then determines who has won that round and displays a message accordingly, based on the RPS game rules above. Should both the user and the program pick the same choice, the game is tied (i.e., nobody won).

 

Your program should keep prompting the user to keep making choices and playing against the computer, until one player has won 3 games (so, it’s “best-of-five” except that, unlike baseball or NBA, there is a possibility of ties here, and ties do not count towards the total tally of games won).Show the output of your repeated game showing the sequence of plays (including ties) and stopping once either the human user or the computer has won a total of three rounds (not necessarily consecutively).

 

  1. Write a program that reads an unspecified number of integers (but no more than twenty, total), determined how many of those were positive vs. negative, and computes the total sum and the average of the entered values. The program stops prompting the user to enter more integers once either 0 has been entered as input, or if there have been twenty entered (all non-zero) values.

 

Show the output of your Java program on five sets of inputs, total. Three sets are your choice, under the constraint that there should be at least five input non-zero values before the first 0 is encountered.

The remaining two test runs should be on the following input sequences:

  • 1 2  -1  3  0
  • 1 -1  2  -2  3  -3  4  -4  5  -5  0

 

  1. Write a Java program that prompts the user to enter a hexadecimal number that as anywhere between 1 and 5 digits, converts it to a decimal integer, and displays that (decimal) value. For example, hex 7 is also 7 in decimal and hex B is decimal 11. An example of a 5-digit hexadecimal number would be 1FA7D. As before, hex digits that are represented as English letters can be either uppercase or lowercase (so, either ‘A’ or ‘a’ would stand for decimal 10).You are encouraged to use one or more loop(s). You are not allowed to use arrays, in this or any other problem on this assignment.

 

For an incorrect input, your program should notify the user that the input was not valid.

Show the output of your code for five test input values of your choice, at least three of which are hexadecimal numbers with 3 or more digits each; one of your test inputs should be an illegal input (i.e., not a valid hexadecimal number).

 

  1. Write a Java program that displays all integers between 100 and 1,000 (inclusive) that are divisible by a) both 5 and 6 and b) either 5 or 6, but not both. Display ten numbers per line, where consecutive numbers are separated by a single space. Clearly show separately the outputs for a) and b).

 

  1. Write a method with the following header to display a positive integer in reverse order:

public static void reverse (int number)

 

Call this method reverse from main, after prompting the user to enter a positive integer with at most 10 (decimal) digits, and then printing the int entered by user in reverse. Should the user enter an integer with too many digits or a negative integer (or any value that’s not an integer), your program should notify the user that his or her input was not valid, and prompt the user to enter a new input.

Show the output of your program for the following inputs: 42, 3456, 10000, 35753, 10201.

(State briefly how your program treats trailing 0’s, such as in input 10000.)