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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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