Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Repetition Assignment - Module 4 This assignment is designed to give you experience creating small programs with sequence, selection and repetition.and repetition. When writing these

Repetition Assignment - Module 4

This assignment is designed to give you experience creating small programs with sequence, selection and repetition.and repetition.

When writing these programs, only use sequence, selection and repetition. Do not include other statements. Do not use any data types that have not been covered so far.and repetition. Do not include other statements. Do not use any data types that have not been covered so far.

Do NOT usebreak(except to terminate a case in a switch statement),continue, JOptionPane, orSystem.exitJOptionPane, orSystem.exitstatements.

Be sure to choose the best control structure for your solutions.

Each program must follow the documentation and style rules for the class.Use ECLIPSE formatting aid to avoid style point deductions! You will be graded on completeness, correctness and programming style. Programs that do not compile or give incorrect results are not useful programs and are not worth much credit.

If you have questions about your code or you are tempted to search for a solution on the internet, send me Canvas email.

Submit two separate files named exactly as:

HiLoGame.java,

DiamondPrinter.java.

Remember: programs that do not compile are worth no more than 10% of the assigned point value.If you have trouble compiling, you should practice compiling programs - use source from the text that you add errors to in order to get used to compiler error messages.If trouble persists, email your instructor many days BEFORE the assignment is due.to in order to get used to compiler error messages.If trouble persists, email your instructor many days BEFORE the assignment is due.

Requirements forHiLoGame

.java(worth 30 points)

Write and test the applicationHiLoGame.javafor a simple number guessing game that allows the user to guess a number between 1 and 100.

The game will start with the application displaying a welcome message to the user and then automatically selecting a random number for the user to guess.The number to be guessed is random and so should typically be different each time a new game begins.Information and examples on the Random class can be found in the current chapter of the textbook.Youselecting a random number for the user to guess.The number to be guessed is random and so should typically be different each time a new game begins.Information and examples on the Random class can be found in the current chapter of the textbook.Youmustuse theRandomclass from the Java API.Your program MUST use the Random class to generate the secret number for the user to guess.

This guessing game is also sometimes called high/low:Each time the user makes a guess, the game will respond whether the guess is too high or too low along with the range of values for the next guess. Notice that the prompt includes theguess number(which doesnotchange when the guess is out of range) and that the range given in the prompt changes to account for the last guess if it was a valid guess. When a guess is valid, the range will getnarrower. The rangeNEVERgets wider for any guess.If the guessed value is out of range, an error message is printed, the guess count does not increase, and the range does not change.

Once the secret number has been correctly guessed, the numbers of valid and out of range (or invalid) guesses are displayed.This final display telling the user that the number was correctly guessed (along with the counts of valid and invalid guesses) must be displayed from a print statement OUTSIDE (AFTER) the loop.This display should NOT be done from inside the loop.The main loop should iterate as long as (while) the guess is not correct.Get the first guess before the loop and only ONCE inside the loop at the end of the loop body.

When your program is executing, the console should lookEXACTLYlike the following example of input and output (User input is shown in bold):

Guess 1: Enter a number between 1 and 100 >>60

60 is too high

Guess 2: Enter a number between 1 and 59 >>20

20 is too low

Guess 3: Enter a number between 21 and 59 >>16

16 is not between 21 and 59

Guess 3: Enter a number from 21 and 59 >>40

40 is correct

It took you 3 valid guesses to find the number

You had 1 out of range guess

Notice that every prompt includes the guess count and the current range.The guess count is NOT incremented when the guess was out of range.The range always begins at 1 to 100, but narrows with each valid guess.100, but narrows with each valid guess.

Requirements for

DiamondPrinter

.

java(worth 30 points)

Write and test the program test the programDiamondPrinter.javathat will continue printing diamond shapes according to two user inputs until the user wants to stop.The first input is the pen character, that is, the single character that will be used to draw the shape.This character can be any single character (type,char) entered by the user.The second input is the number of characters that will appear on themiddle line of the diamond, i.e., the line with the most characters.This integer input by the user must be apositive odd number.The program should continue to ask the user for apositive odd integeras long as the user enters an integer that violates these two requirements (positive and odd).This is an input validation loop that long as the user enters an integer that violates these two requirements (positive and odd).This is an input validation loop thatforcesthe user to enter valid data.

Once the program has the two valid inputs from the user, the diamond shape should be displayed one character at a time by embedding the needed print statements inside for-loops.There should be one for-loop to display the top portion of the diamond and a second one for the bottom portion of the diamond.Inside these two major loops there will also need to be nested for-loops to display the characters needed for each line: a series of some number of blanks (spaces) followed by the proper number of pen characters for that line.

Here is an example.Suppose the user enters the character, '#', for the pen character, and then the integer, 7.The program will begin by having its first for-loop print a total of 4 lines.The first line will have 3 spaces followed by one pen character (# in this example), the second line will have 2 spaces followed by three pen characters, the third line will have 1 space followed by five pen characters, and the fourth line will have seven pen characters.The program would then complete the shape by having its second major for-loop display three more lines: the first of these would have 1 space followed by five pen characters, the second would have 2 spaces followed by three pen characters, and the third would have 3 spaces followed by one pen character.

Here is what the console would look like as your program executes the example just described, plus another example: (user input in bold)

Welcome to the Diamond printing program!

With what character do you want to draw:#

What will be the length of the middle line:7

Your Diamond:

#

###

#####

#######

#####

###

#

Do you want to display another diamond?Y

With what character do you want to draw:+

What will be the length of the middle line:8

INVALID INPUT: Integer must be odd and positive

What will be the length of the middle line:0

INVALID INPUT: Integer must be odd and positive

What will be the length of the middle line:3

Your Diamond:

+

+++

+

Do you want to display another diamond?N

Program terminating.

Your program should look just like the output of this example as it is executing.Your program must display a proper diamond shape for any positive odd integer entered by the user.

Submittal

Submit the source code as twoseparatejava files submitted at the same time (click SUBMIT once after attaching both java files). Make sure that the correct files are submitted and you receive confirmation.Name your files as they are named in these requirements.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions