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
a_sh-v [17]
3 years ago
13

Write a GUI-based program that plays a guess-the-number game in which the roles of the computer and the user are the reverse of

what they are in the Case Study of this chapter. In this version of the game, the computer guesses a number between 1 and 100 and the user provides the responses. The window should display the computer’s guesses with a label. The user enters a hint in response, by selecting one of a set of command buttons labeled Too small, Too large, and Correct. When the game is over, you should disable these buttons and wait for the user to click New game, as before.
Engineering
1 answer:
AURORKA [14]3 years ago
8 0

Answer:

import javax.swing.*;

import java.awt.*;

import java.util.Random;

import java.awt.event.*;

public class Guess extends JFrame

{

   private static final long serialVersionUID = 1L;

   private JButton newGame;

   private JButton enter;

   private JButton exit;

   private JTextField guess;

   private JLabel initialTextLabel;

   private JLabel enterLabel;

   private JLabel userMessageLabel;

   private int randNum;

   private int userInput;

   private int maxtries = 0;

   public Guess()

   {

       super("Guessing Game");

       newGame = new JButton("New Game");

       exit = new JButton("Exit Game");

       enter = new JButton("Enter");

       guess = new JTextField(4);

       initialTextLabel = new JLabel("I'm thinking of a number between 1 and 100. Guess it!");

       enterLabel = new JLabel("Enter your guess.");

       userMessageLabel = new JLabel("");

       randNum = new Random().nextInt(100) + 1;

       setLayout(new FlowLayout());

       add(initialTextLabel);

       add(enterLabel);

       add(guess);

       add(newGame);

       add(enter);

       add(exit);

       add(userMessageLabel);

   

       setSize(500, 300);

       addWindowListener(new WindowAdapter()

       {

           public void windowClosing(WindowEvent e)

           {

               System.exit(0);

           }

       });

       newGameButtonHandler nghandler = new newGameButtonHandler();

       newGame.addActionListener(nghandler);

       ExitButtonHandler exithandler = new ExitButtonHandler();

       exit.addActionListener(exithandler);

       enterButtonHandler enterhandler = new enterButtonHandler();

       enter.addActionListener(enterhandler);

   }

   class newGameButtonHandler implements ActionListener

   {

       public void actionPerformed(ActionEvent e)

       {

           setBackground(Color.ORANGE);

           guess.setEnabled(true);

           guess.setText("");

           enter.setEnabled(true);

           maxtries = 0;

           userMessageLabel.setText("");

           randNum = new Random().nextInt(100) + 1;

       }

   }

   class ExitButtonHandler implements ActionListener

   {

       public void actionPerformed(ActionEvent e)

       {

           System.exit(0);

       }

   }

   class enterButtonHandler implements ActionListener

   {

       public void actionPerformed(ActionEvent e)

       {

           userInput = Integer.parseInt(guess.getText());

           checkGuess(randNum);

      if(userInput > 100 )

          {

                               userMessageLabel.setText("invalid entry");

          }

       }

   }

   public void checkGuess(int randomNumber)

   {

       maxtries++;

     if(maxtries==10){

           userMessageLabel.setText("You Lose!!");

           guess.setEnabled(false);

           enter.setEnabled(false);

         

       }else if (userInput == randomNumber)

           {

               userMessageLabel.setText("Correct !");

           }

       else if (userInput > randomNumber)

           {

               userMessageLabel.setText("Too high");

           }

       else if (userInput < randomNumber)

           {

               userMessageLabel.setText("Too Low");

           }

   }

   public static void main(String[] args)

   {

       Guess game = new Guess();

       game.setVisible(true);

   }

}

You might be interested in
A joining process in which a filler metal is melted and distributed by capillary action between faying surfaces, the base metals
PolarNik [594]

Answer:

A soldering process

Explanation:

Given that ,The filler metal's melting point temperature is less than 450 ° C.

Usually, the brazing material has the liquid temperature of the melting point, the full melting point of the filler material approaching 450 degrees centigrade, while the filler material is less than 450 degrees centigrade in the case of soldering.

Therefore the answer is "A soldering process".

4 0
3 years ago
Why different types of <br> engines used gas turbine give reasons
Romashka [77]

Answer:

Four types of gas turbine engines are used to propel and power aircraft. They are the turbojet, turbofan, turboprop, and turboshaft.

6 0
3 years ago
Read 2 more answers
A flat plate is subjected to a load of 5KN as shown in figure. The plate material is grey cast iron FFG 200 and the factor of sa
lianna [129]

Answer:

57.14 N/mm2

Explanation:

3 0
3 years ago
Cooling water for a chemical plant must be pumped from a river 2500 ft from the plant site. Preliminary design cans for a flow o
Vesna [10]

Answer:

The power cost savings for the 8 inches pipe offsets the increased cost for the pipe therefore to save costs the 8-inch pipe should be used

Explanation:

The given parameters in the question are;

The distance of the river from the the site, d = 2,500 ft.

The planned flow rate = 600 gal/min

The diameter of the pipe, d = 6-in.

The pipe material = Steel

The cost of pumping = 3 cents per kilowatt-hour

The Bernoulli's equation is presented as follows;

\dfrac{P_a}{\rho} + g\cdot Z_a + \dfrac{V^2_a}{2} + \eta\cdot W_p = \dfrac{P_b}{\rho} + g\cdot Z_b + \dfrac{V^2_b}{2} +h_f +W_m

{P_a} = {P_b} = Atmospheric \ pressure

Z_a  =  Z_b

Vₐ - 0 m/s (The river is taken as an infinite source)

W_m = 0

The head loss in 6 inches steel pipe of at flow rate of 600 gal/min = 1.19 psi/100 ft

Therefore; h_f = 1.19 × 2500/100 = 29.75 psi

\eta\cdot W_p = \dfrac{V^2_b}{2} +h_f

V_b = Q/A_b = 600 gal/min/(π·(6 in.)²/4) = 6.80829479 ft./s

V_b ≈ 6.81 ft./s

The pressure of the pump = P =  62.4 lb/ft³× (6.81 ft./s)²/2 + 29.75 psi ≈ 30.06 psi

The power of the pump = Q·P ≈ 30.06 psi × 600 gal/min = 7,845.50835 W

The power consumed per hour = 7,845.50835  × 60  × 60 W

The cost = 28,243.8301 kW × 3  = $847.31  per hour

Annual cost =  $847.31 × 8766 = $7,427,519.46

Pipe  cost = $15/ft × 2,500 ft = $37,500

Annual charges = 20% × Installed cost = 0.2 × $37,500 = $7,500

Total cost = $37,500 + $7,500 + $7,427,519.46 = $7,475,519.46

For the 8-in pipe, we have;

V_b = Q/A_b = 600 gal/min/(π·(8 in.)²/4) = 3.83 ft./s

h_f = 1.17 ft/100 feet

Total head loss = (2,500 ft/100 ft) × 1.17 ft. = 29.25 ft.

h_p = \dfrac{V^2_b}{2 \cdot g} +h_f

∴ h_p = (3.83 ft./s)²/(2 × 32.1740 ft/s²) + 29.25 ft. ≈ 29.5 ft.

The power of the pump = ρ·g·h × Q

Power of pump = 62.4 lb/ft³ × 32.1740 ft/s² × 29.5 ft.× 600 gal/min = 3,363.8047 W

The cost power consumed per annum = 3,363.8047 W × 60 × 60 × 3 × 8766 = $3,184,608.1

The Cost of the pipe = $20/ft × 2,500 ft. = $50,000

The total cost plus charges = $3,184,608.1 + $50,000 + $10,000 = $3,244,608.1

Therefore it is more affordable to use the 8-in pipe which provides substantial savings in power costs

8 0
3 years ago
The current though a capacitor cannot change instantaneously.
malfutka [58]

Answer: The answer is (b) False

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • A car starts at rest and moves along a perfectly straight highway with an acceleration of α1 = 10 m/s2 for a certain amount of t
    15·1 answer
  • What are the three basic types of positive displacement pumps.
    5·1 answer
  • What are materials engineers trying to discover when they study different materials?
    15·2 answers
  • A 3/8-16 UNC nut and bolt are used to assemble steel plates. The clearance holes in the plates are 7/16 in. The plates are clamp
    13·1 answer
  • 1.<br> Defensive driving involves?
    14·1 answer
  • If a vehicle is built with a top speed of 140 mph, what should its tires minimum speed
    5·1 answer
  • When did michael faraday invent wind powered electrical generation?
    11·1 answer
  • Also discuss how bandwidth is affected by increasing the number of signal elements.
    5·1 answer
  • Briggs &amp; Stratton engines feature both a pressure lubrication and a pressure filtration system. Which statement is true?
    6·1 answer
  • g A steam turbine is part of a power cycle. The flow rate of steam is 30 kg/s. If the steam entering the turbine is 5000C and ha
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!