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

  Question superclass and provide a different implementa

Add a method addText to the Question superclass and provide a different implementa- tion of ChoiceQuestion that calls addText rather than storing an array list of choices.

  Design and develop a console application

Required to design and develop a console (text-based) application for a small car servicing company -

  How to apply filter in servlet

Can you do this assignment please help int this how to apply filter in servlet create 3 class and show the filter chaining phenomenon..... Show the working program thanks.............

  Square matrix of dimension

You are given a square matrix of dimension N. Let this matrix be called A. Your task is to rotate A in clockwise direction byS degrees, where S is angle of rotation. On the matrix, there will be 3 types of operations viz.

  Requirementspig is a folk jeopardy dice game with simple

requirementspig is a folk jeopardy dice game with simple rules two players race to reach 100 points. each turn a player

  Create a program in java that displays hello world

Create a program in Java that displays "Hello world!", No Design Section is required for this assignment, Copy and Paste your code into the Source Programs section and a screen shot of the results in the Output section.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Declare a string variable named empty

Declare a string variable named empty, and initialize it to the empty string.

  Outline a test plan for a substantial real-life system

Describe how you would approach the design and testing process to ensure success and quality in the result and where are the risks? How are you going to address them?

  Web engineering principles

web application development, Web Engineering methodology, UML-based Web Engineering (UWE), models to the expansion of web applications, Object Oriented Web Solutions (OOWS),Web Modeling Language (WebML) methodology, Object-Oriented Hypermedia Design..

  Create a new class called dwelling

1 Create a new class called Dwelling that includes the functionality below 2.    The new class has the attributes of: category - dwelling's category (i.e.:"House", "Condo", "Apartment","shach",etc.), type String numberOfBedrooms - the number of bedro..

  Will the direction and magnitude be integers or doubles

Define a Physics_vector class which consists of a struct containing the direction and magnitude, and also define a function

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