Write a program which randomly chooses an integer

Assignment Help JAVA Programming
Reference no: EM13934798

Question 1:

Write a program (save in a file called GuessGame.java) which randomly chooses an integer from 1 to 100. The program should then tell the user. "I am thinking of a number from 1 to 100 ... guess what it is?". The user should then enter an integer as a guess. If the guess is above the randomly-chosen number, then the program should tell the user: "Lower!" and then wait for another guess. If the guess was below the randomly chosen number, then the program should tell the user: "Higher!" and then wait for another guess. It should repeat this until the user enters the correct number. Then it should print out "Congratulations. You guessed the number in X tries!", where X is the number of guesses that the user made. The program should then quit. You may assume that the user always enters an integer. Here is an example output:

I am thinking of a number from 1 to 100 ... guess what it is?
34
Higher!
78
Higher!
86
Lower!
82
Congratulations. You guessed the number in 4 tries!

Question 2:

Write a program (saved in a file called SmartGame.java) which displays the following 5x5 table of letters (note the board should start with the initialized state shown here). The program should then ask the user to complete the puzzle such that each row and each column consists of the letters 'S', 'M', 'A', 'R', and 'T' in some order. No letter should be repeated in any row or any column. The program should prompt the user for a row, a column and a letter. it should then insert (or replace) the letter at the given row and column with the entered letter and display the table again.

You may assume that the user always enters a value of the correct type (i.e., an integer for row and column and a string containing one char for the letter). However, if an invalid letter is entered (e.g., 'Q') the program should display "Invalid letter. Use 'S', 'M', 'A', 'R', or 'T'!". If an invalid row number is entered (e.g. -1 or 6), the program should display "Invalid row number!". A similar response should be included for invalid column numbers.

Given successful information, a placed letter can be replaced at any time. The program should repeatedly display the updated table and ask for a new letter to be placed. The program should end when each row and each column contains a unique valid letter. It should then display. "Congratulation! You must be SMART." and then quit. You MUST store all letters in a 2-dimensional array as follows:

char[][] table = new char[5][5];

Also, you must create a separate procedure for displaying the table, which should be called from your main program. The table should be displayed as shown below:

	     1   2   3   4   5
	   +---+---+---+---+---+
	 1 | S | M | A | R | T |
	   +---+---+---+---+---+
	 2 |   | T | S | M |   |
	   +---+---+---+---+---+
	 3 |   |   | R |   | S |
	   +---+---+---+---+---+
	 4 |   | S | M |   |   |
	   +---+---+---+---+---+
	 5 |   |   | T | S |   |
	   +---+---+---+---+---+

To determine if the game has ended, you can simply add up the numeric values for each letter (i.e., use (int)table[r][c] to get the numeric value for the letter at row r column c) for each row and column. The total for each row and each column must be 391 exactly for the table to be completed properly.

Sample output for the game:

    1   2   3   4   5
  +---+---+---+---+---+
1 | S | M | A | R | T |
  +---+---+---+---+---+
2 |   | T | S | M |   |
  +---+---+---+---+---+
3 |   |   | R |   | S |
  +---+---+---+---+---+
4 |   | S | M |   |   |
  +---+---+---+---+---+
5 |   |   | T | S |   |
  +---+---+---+---+---+

Enter a row (1-5): 3
Enter a column (1-5): 2
Enter a letter (S,M,A,R or T): G
Invalid letter. Use 'S', M', 'A', 'R' or 'T'.

    1   2   3   4   5
  +---+---+---+---+---+
1 | S | M | A | R | T |
  +---+---+---+---+---+
2 |   | T | S | M |   |
  +---+---+---+---+---+
3 |   |   | R |   | S |
  +---+---+---+---+---+
4 |   | S | M |   |   |
  +---+---+---+---+---+
5 |   |   | T | S |   |
  +---+---+---+---+---+
Enter a row (1-5): 3
Enter a column (1-5): 1
Enter a letter (S,M,A,R or T): T

    1   2   3   4   5
  +---+---+---+---+---+
1 | S | M | A | R | T |
  +---+---+---+---+---+
2 |   | T | S | M |   |
  +---+---+---+---+---+
3 | T |   | R |   | S |
  +---+---+---+---+---+
4 |   | S | M |   |   |
  +---+---+---+---+---+
5 |   |   | T | S |   |
  +---+---+---+---+---+
Enter a row (1-5): 4
Enter a column (1-5): 4
Enter a letter (S,M,A,R or T): T

    1   2   3   4   5
  +---+---+---+---+---+
1 | S | M | A | R | T |
  +---+---+---+---+---+
2 |   | T | S | M |   |
  +---+---+---+---+---+
3 | T |   | R |   | S |
  +---+---+---+---+---+
4 |   | S | M | T |   |
  +---+---+---+---+---+
5 |   |   | T | S |   |
  +---+---+---+---+---+ 
Enter a row (1-5):

Documentation and Testing

Ensure that your name and student number are in comments at the top of all files. Document the purpose of each method including its expected inputs (parameters) and output (return). Include evidence of testing your code in a separate testing.txt file. Comment your testing as to what you are testing and why, giving expected output as well as observed output and explanations for any differences.

Ensure that your code is well-formatted and easily readable; a happy TA is a generous TA.

Verified Expert

The paper is about to check grip on java basics and coding techniques which includes two programing exercises GuessGame and SamrtGame. As name suggests GuessGame is to guess number and revert if input is right where as SmartGame is a puzzle game having some tricky part in it. Both the exercises helps to develop basic concepts of core java.

Reference no: EM13934798

Questions Cloud

A sample database for hotel reservation transactions develop : A sample database for hotel reservation transactions developed in Microsoft Access is shown next, but the Web site may have a more recent version of this database for this exercise. Develop some reports that provide information to help management mak..
What job numbers likely relate to the balance : What is Cost of Goods Sold? What job numbers likely relate to the balance in Cost of Goods Sold?
Analyze the changing landscape of the health care system : Analyze the changing landscape of the health care system. Differentiate the various places health care is delivered. Analyze what impact cultural demographics have on the health care market. Analyze the targeted audience of the clinic or office bas..
Clarify analysis what sort of people were likely to survive : In this challenge, we ask you to complete the analysis of what sorts of people were likely to survive. In particular, we ask you to apply the tools of machine learning to predict which passengers survived the tragedy.
Write a program which randomly chooses an integer : Write a program which randomly chooses an integer from 1 to 100. The program should then tell the user.The program should then ask the user to complete the puzzle such that each row and each column consists of the letters
Research and development project scheduled : Your program has a research and development project scheduled to start in January 2017 which is expected to take 40 months to complete. The project is expected to cost a total of $150 million (then-year dollars), with cost expected to be incurred as ..
Aircraft production contract planned for award fiscal year : Time now is February 2015. You have been asked to determine the amount that should be included in the Air Force's FY 2017 budget request for an aircraft production contract planned for award in that fiscal year. The contractor estimates that the cost..
Arithmetic unit and related self testing in mips : Write an arithmetic unit and related self testing in MIPS assembly as following. Put all the source codes in a directory and compress them into a zip file and upload. Grader should be able to download your zip file, unzip it and directly load it i..
Explain the basis for its ability to cause weight loss : The molecule 2, 4 -dinitrophenol (DNP) is an uncoupler of oxidative phosphorylation. For a short period of time, it was prescribed clinically as a pill for weight reduction (against the advice of ssientists). Explain the basis for its ability to c..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Accepts a binary number from the user

Write a Java test program that accepts a binary number from the user. You should store the binary number in a String. Your program should then use afor loop to sequence through every character in the String, counting the number of ones, zeros, and..

  You need to prepare the java applet

If the typed number is valid, display a product description and price; otherwise, display an appropriate error message. Save the file as JProductFinder.java.

  Implement a simple number guessing game using html forms

Your assignment is to implement a simple number guessing game using HTML forms and a Java servlet. The HTML page should introduce the game and provide a form for the user to guess a number on. The servlet should use an HTTP session object to store..

  1 what makes a program easy to modify2 describe the order

1. what makes a program easy to modify?2. describe the order of magnitude of the following code section using bigo

  What is the advantage of a double-linked list

What is the difference between the size and the capacity of an ArrayLi st? Why might we have a constructor that lets us set the initial capacity?

  Determine if strings are equal

Complete the recursive method match in the code below which will determine whether or not two strings match.

  Which drags html list items to and from a javascript array

Write a program which drags html list items to and from a javascript array.

  Develop the game using the concepts of cohesion

Develop the game using the concepts of Cohesion, Coupling and RDD, i.e., responsibility-driven design.

  Which a ball is released from a user-defined height

Write a program in which a ball is released from a user-defined height and free-falls to the ground. The ball is pulled by earth's gravity of 9.8 m/sec 2 . Assume that each pixel represents

  Quadratic that solves quadratic equations

Write a method called quadratic that solves quadratic equations and prints their roots. Recall that a quadratic equation is a polynomial equation in terms of a variable x of the form ax2 + bx + c = 0. The formula for solving a quadratic equation is ?..

  Write a program that prompts the user to input a string

Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string.

  Create a servlet to display a table

NetBeans for Java with GlassFish/Tomcat: https://netbeans.org/downloads/ (select All option)) and create a servlet to display a table that contains factorials for the numbers from 0 to 10, as shown

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd