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
Assume the impedance of a circuit element is Z = (3 + j4) Ω. Determine the circuit element’s conductance and susceptance.
djyliett [7]

Answer:

B. G = 333 mS, B = j250 mS

Explanation:

impedance of a circuit element is Z = (3 + j4) Ω

The general equation for impedance

Z = (R + jX) Ω

where

R = resistance in ohm

X = reactance

R = 3Ω  X = 4Ω

Conductance = 1/R while Susceptance = 1/X

Conductance = 1/3 = 0.333S

= 333 mS

Susceptance = 1/4 = 0.25S

= 250mS

The right option is B. G = 333 mS, B = j250 mS

8 0
3 years ago
A gas turbine operates with a regenerator and two stages of reheating and intercooling. Air enters this engine at 14 psia and 60
Rzqust [24]

Answer:

flow(m) = 7.941 lbm/s

Q_in = 90.5184 Btu/lbm

Q_out = 56.01856 Btu/lbm

Explanation:

Given:

- T_1 = 60 F = 520 R

- T_6 = 940 = 1400 R

- Heat ratio for air k = 1.4

- Compression ratio r = 3

- W_net,out = 1000 hp

Find:

mass flow rate of the air

rates of heat addition and rejection

Solution:

- Using ideal gas relation compute T_2, T_4, T_10:

                     T_2 = T_1 * r^(k-1/k)

                     T_2 = T_4 = T_10 = 520*3^(.4/1.4) = 711.744 R

- Using ideal gas relation compute T_7, T_5, T_9:

                     T_7 = T_6 * r^(-k-1/k)

                     T_7 = T_5 = T_9 = 1400*3^(-.4/1.4) = 1022.84 R

- The mass flow rate is obtained by:

                     flow(m) = W_net,out / 2*c_p*(1400-1022.84-711.744+520)

                     flow(m) = 1000*.7068 / 2*0.24*(1400-1022.84-711.744+520)

                     flow(m) = 7.941 lbm/s

- The heat input is as follows:

                     Q_in = c_p*(T_6 - T_5)

                     Q_in = 0.24*(1400 - 1022.84)

                     Q_in = 90.5184 Btu/lbm

- The heat output is as follows:

                     Q_out = c_p*(T_10 - T_1)

                     Q_out = 0.24*(711.744 - 520)

                    Q_out = 56.01856 Btu/lbm

                                           

                     

5 0
3 years ago
A cylindrical brass rod has a length of 5.00cm extending from a holder and a diameter of 4.50mm. Its Young's modulus is 98.0GPa.
Galina-37 [17]

Answer:

elongation of the brass rod is 0.01956 mm

Explanation:

given data

length = 5 cm = 50 mm

diameter = 4.50 mm

Young's modulus = 98.0 GPa

load = 610 N

to find out

what will be the elongation of the brass rod in mm

solution

we know here change in length formula that is express as

δ = \frac{PL}{AE}    ................1

here δ is change in length and P is applied load  and A id cross section area and E is Young's modulus and L is length

so all value in equation 1

δ = \frac{PL}{AE}  

δ = \frac{610*50}{\frac{\pi}{4} * 4.50^2 * 98*10^3}  

δ = 0.01956 mm

so elongation of the brass rod is 0.01956 mm

7 0
3 years ago
A 4-stroke Diesel engine with a displacement of Vd = 2.5x10^-3m^3 produces a mean effective pressure of 6.4 bar at the speed of
yKpoI14uk [10]

Answer:

The power developed by engine is 167.55 KW

Explanation:

Given that

V_d=2.5\times 10^{-3} m^3

Mean effective pressure = 6.4 bar

Speed = 2000 rpm

We know that power is the work done per second.

So

P=6.4\times 100\times 2.5\times 10^{-3}\times \dfrac{2\pi \times2000}{120}

We have to notice one point that we divide by 120 instead of 60, because it is a 4 cylinder engine.

P=167.55 KW

So the power developed by engine is 167.55 KW

4 0
3 years ago
I WILL GIVE 20 POINTS!!
Alex777 [14]

Answer:

Use a resume header

Explanation:

Create a Summary

Research industry, employer keywords

there are some hints okay

5 0
3 years ago
Read 2 more answers
Other questions:
  • Who can work on a fixed ladder that extends more than 24 feet?
    11·1 answer
  • A parallel circuit with two branches and an 18 volt battery. Resistor #1 on the first branch has a value of 220 ohms and resisto
    7·1 answer
  • A 150-lbm astronaut took his bathroom scale (a spring scale) and a beam scale (compares masses) to the moon where the local grav
    13·1 answer
  • A ballistic pendulum consists of a 3.60 kg wooden block on the end of a long string. From the pivot point to the center‐of‐mass
    6·1 answer
  • A horizontal curve on a two-lane road is designed with a 2,300-ft radius, 12-ft lanes, and a 65-mph design speed. Determine the
    11·1 answer
  • Think about the science you have studied in the past or are currently studying. Give an example of something you have learned in
    11·1 answer
  • Which actions would the maintenance and operations crews carry out as a building is completed and preparing to open to the publi
    8·2 answers
  • The irreversible losses in the penstock of a hydroelectric dam are estimated to be 7 m. The elevation difference between the res
    14·1 answer
  • The actual tracking weight of a stereo cartridge that is set to track at 3 g on a particular changer can be regarded as a contin
    9·1 answer
  • the left rear brake drum is scored, but the right rear drum looks as good as new. technician a says the left-side drum should be
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!