Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M91605684
  • Price:- $45

Priced at Now at $45, Verified Solution

Have any Question?


Related Questions in Java

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As