1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vladimir2022 [97]
3 years ago
7

Create a class named Console, and move all the methods that retrieve and validate user input to that class. These methods can re

main static. Create a class named Game, and move all the methods that display messages and handle user guesses to that class. Adjust these methods so they aren't static, and use instance variables of the Game class to keep track of numbers, guesses, and so on. Update the application to use these classes and their methods. Make sure the application functions the same as it did before.

Computers and Technology
1 answer:
otez555 [7]3 years ago
3 0

Answer:

Here is the Console class:

import java.util.Scanner;  // to accept input from user

public class Console {   // class name

public Console() {}   //class constructor

public int getInt(Scanner sc, String prompt) { //gets user's number  

int i = 0;   //initialize i to 0

boolean isValid = false;   // checks for valid input

while (!isValid) {   //loop iterates as long as input remains valid

System.out.print(prompt);   //displays prompt

if (sc.hasNextInt()) {   // checks for the next token (input number)

i = sc.nextInt();   // scans and reads the next number

isValid = true;   // checks if input is valid

} else {   //if input is not valid

System.out.println("Error! Invalid integer value. Try again.");  }  //displays error message

sc.nextLine(); // discard any other data entered on the line   }

return i;  }  //returns number

public int getIntWithinRange(Scanner sc, String prompt, //checks users guess if outside parameters or not  

int min, int max) {  

int i = 0;  

boolean isValid = false;   //sets isValid to false

while (!isValid) {   //keeps iterating and stops when isValid is false

i = getInt(sc, prompt);   //calls getInt method to get users number

if (i <= min) {   //if number is less than value of min

System.out.println("Error! Number must be greater than " + min);   //displays this message

} else if (i >= max) {   //if number is greater than that of max

System.out.println("Error! Number must be less than " + max);   //displays this message

} else {   //if guess is right

isValid = true;   } } //sets isValid to true

return i;  } //returns that number

public  String getRequiredString(Scanner sc, String prompt) { //Asks for user's string input  

String s = "";  

boolean isValid = false;   //sets isValid to false

while (!isValid) {      //keeps iterating and stops when isValid is false

System.out.print(prompt);    //displays prompt

s = sc.nextLine();   //reads next line (read next string input value)

if (s.equals("")) {   //if user enters nothing

System.out.println("Error! This entry is required. Try again.");   //display this message

} else {   //if user enters a string input

isValid = true;   }  }  //sets isValid to true

return s; }  //returns string

public  String getChoiceString(Scanner sc, String prompt, //Checks for users input for Y/y ignores caps  

String s1, String s2) {

String s = "";  

boolean isValid = false;   //sets isValid to false

while (!isValid) {   //iterates until isValid is false

s = getRequiredString(sc, prompt);   //calls method to get the input string

if (!s.equalsIgnoreCase(s1) && !s.equalsIgnoreCase(s2)) {  // checks users input for Y/y ignores caps  

System.out.println("Error! Entry must be '" + s1 + "' or '" + s2 + "'. Try again.");   // displays error message that entry must be y or Y

} else {   //if user enters y or Y

isValid = true;   } }   //sets isValid to true

return s;  } } //returns y or Y

Explanation:

Here is the Game class

public class Game {  // class name

public Game() {}   //class constructor

public void displayWelcomeMessage() { //displays message  

System.out.println("Welcome to the Guess the Number Game");  

System.out.println("++++++++++++++++++++++++++++++++++++");  

System.out.println(); }

public  void displayPleaseGuessMessage() { //displays message for user to guess from 1-100  

System.out.println("I'm thinking of a number from 1 to 100.");  

System.out.println("Try to guess it.");  

System.out.println();}

public  void displayCorrectGuessMessage(int counter) { //display user's current guess count

System.out.println("You got it in " + counter + " tries.");  

if (counter <= 3) {   //if user guesses the number in 3 or less tries

System.out.println("Great work! You are a mathematical wizard.\n");  

} else if (counter > 3 && counter <= 7) {   //if user guesses the number greater than 3 but less than or equals to 7 tries

System.out.println("Not too bad! You've got some potential.\n");  

} else {   //if user guesses the number after more than 7 tries

System.out.println("What took you so long? Maybe you should take some lessons.\n"); }}

public  void displayGuessAgainMessage(int number, int guessNumber) { //Asks user to guess again  

int difference = guessNumber - number;  

if (guessNumber > number) {   //if guessNumber is greater than number

if (difference > 10) {   //if difference between guessNumber and number is greater than 10

System.out.println("Way too high! Guess again.\n");   //guessed number is higher than correct one

} else {  

System.out.println("Too high! Guess again.\n");  }

} else {  

if (difference < -10) {   //if difference between guessNumber and number is less than -10

System.out.println("Way to low! Guess again.\n");   //guessed number is lower than correct one

} else {  

System.out.println("Too low! Guess again.\n");}}}}

The main program and explanation of these above programs are given in the attached document.

The output of the program is attached.

You might be interested in
A self improvement plan should begin with planning how you will accomplish your goal.
Artist 52 [7]

Answer:

True

Explanation: The first step is to make a goal. The second step is to plan how you will accomplish you goal. The third and final step is to accomplish your goal.

4 0
3 years ago
Read 2 more answers
What technology allows you to hide the private IP address of a system from the Internet?a. SSLb. RADIUSc. PPTPd. NAT
Greeley [361]

Answer:

The answer is "Option d".

Explanation:

In networking, NAT refers to the Network Address Translation. This process is used to translate computer IP addresses into a single IP address in your local network. It allows private IP networks to connect to the Internet using unregistered IP addresses. and other options are incorrect that can be described as follows:

  • In option a, SSL stands for Secure Sockets Layer. It is used in transmission of documents or data over a network that's why it is not correct.
  • In option b, RADIUS stands for Remote Authentication Dial-In User Service. It is used to manage the data on a network.
  • In option c, PPTP stands for Point-to-Point Tunneling Protocol. It is used to provide a set of rules for communicating through a network that's why it is not correct.

6 0
3 years ago
Happy Valentine's day!!
Lorico [155]
Happy valentine’s u too !!
7 0
2 years ago
What is the purpose of a div?
taurus [48]

Answer:

I'd choose A, all of the above.

Reasoning Why:

I'll be taking you on a step to step process on why I inputted the answer.

The <div>, is basically like a container that you can group tougher, why this is great is because you can edit the div using a background-color effecting that group such as the following..

EXAMPLE OF BACKGROUND-COLOR DIV (background-color)

<!DOCTYPE html>

<html>

<head>

<title>Brainly Example | HTML Div</title>

<style>

#byexample{

background-color:red;

/*Example of the Background-color attrib*/

/*You can also use the background-image attrib, however I recommend you checkout W3Schools, on that topic.*/

}

</style>

</head>

<body>

<div id="byexample">

<p>Just some random text to demonstrate.</p>

</div>

</body>

</html>

END OF EXAMPLE

You can also, in the <div> change multiple styles of an element in the div. However, if do want to change the styles of a single element you would need to nest it.

<!DOCTYPE html>

<html>

<head>

<title>Brainly Example | HTML Div</title>

<style>

#byexample #text{

background-color:red;

color:yellow;

}

</style>

</head>

<body>

<div id="byexample">

<p id="text">Just some random text to demonstrate.</p>

</div>

</body>

END OF EXAMPLE

Lastly, you can group elements using divs, as stated in openclassroom (website).

Anyways, I hope this helped!

Happy coding!

5 0
3 years ago
Which of the following is benefit of information communication technology?
igor_vitrenko [27]

Answer:

C. Cost reduction

Explanation:

ICT covers all the products that can store, retrieve, transmit or receive and manipulate the information via the electronic medium in a binary or digital mode. As an example, we can consider the Personal computer, digital television, robots or email as well as the digital communication technologies that allow the organizations and people to talk and share the information between them in a digital manner. And this is cost-effective, there is no employee benefit, increased use of postal mail or less technology. The only advantage is cost reduction. And hence C, Cost reduction is the right answer.

5 0
3 years ago
Read 2 more answers
Other questions:
  • Hi, I have several computer questions. These refer to the history of the internet. I would like to know if everything we look fo
    12·1 answer
  • After the data are appropriately processed, transformed, and stored, what is a good starting point for data mining?
    15·1 answer
  • To increase the view of a document on the screen, use the _____. View icon Zoom slider full-screen reading boldface font
    9·1 answer
  • What is a recent technological breakthrough with an impact that can be compared to the invention of paper nearly 2,000 years ago
    8·1 answer
  • What do you think of my profile picture
    8·2 answers
  • Digital dashboards provide the decision makers with a quick overview of key performance indicators and other key operational sta
    13·1 answer
  • - Which amongst the following is not a Characteristic of Cloud Computing?
    5·1 answer
  • In what ways can you modify the location of the neutral point?
    11·1 answer
  • Lasses give programmers the ability to define their own types. <br><br> a. True<br> b. False
    10·1 answer
  • Select the correct answer from each drop-down menu. A company is recruiting for a web designer. What kind of candidate should th
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!