Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Good Evening Chegg, I have a few question I would like some help on. Thank you i

ID: 3568847 • Letter: G

Question

Good Evening Chegg, I have a few question I would like some help on. Thank you in advance:


For Questions 33 to 41 , consider the following class:
Given Code:
[
import javax.swing.*;
import java.awt.*;

public class B extends JFrame
{
private Container c;
private JPanel pl;
private JPanel p2;
private JButton [ ] buttons; //line12
private JTextField [] textfields; //line 10
private JLabel labell;
private JLabel labe12;
}
]

34. This code adds Label1 to the north area of the window. **
My Code:
[

]

36. This code sets the layout manager of the panel p1 to be a 3-by-4 grid
layout manager.
My Code:
[

]

38. This code adds the panel p1 in the center area of the window.
My Code:
[

]


Find and Fix the Error:
50.**
Given Code:
[
import javax.swing.*:
import java.awt.*:
import java.awt.event.*;

public class MyGame extends JFrame
{
private JButton b;
private JTextField tf;
private Container contents;

public MyGame ( )
{
super ( "Play this game" );
contents = getContentPane ( );
contents.setLayout ( new GridLayout ( 1, 2 ) );
b = new JButton ( "Click here" );
tf = new JTextField ( "Hello" );
contents.add ( b );
contents.add ( tf );
setSize ( 400, 400 );
setVisible( true );
}

private class MyHandler implements ActionListener
{
public void actionPerfonmed ( ActionEvent ae )
{
tf.setText ( "Hi " );
}
}
public static void main ( String [ ] args )
{
MyGame g = new MyGame ( );
g.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}

Compile Error:
The code compiles and runs. However, when you dick the button, the text in the

text field does not change.
]
Debugging:


Write a short program:

56. Write a program that simulates a guessing game in a GUI program. Ask the user for a number between 1 and 6 in a text field, then roll a die randomly and tell the user if he or she won. Write the program in
such a way that any in valid user input ( i. e., not an integer between 1 and 6) is rejected and the user is asked again for input.

Explanation / Answer

import java.util.Random;
import java.util.Scanner;


public class GuessTheNumber1 {

public static final int TriesAvailable = 6;


public static void main(String[] args) {
Random randNumber = new Random();
Scanner NumScan = new Scanner(System.in);
short LowNumber = 1;
short HighNumber = 10;
int RandomToGuess = randNumber.nextInt(HighNumber - LowNumber) + LowNumber;
short UserTries = 6;
short DisplayUserTries = 6;
short GuessNumber;
String[] NumTriesAvailable = new String[TriesAvailable];
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++Welcome to Guess The Number++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println(" ");
System.out.println("Difficulty: Beginner");
System.out.println("Guess The Number in 6 Tries");
System.out.println(" ");

for (int x = 0; x < 6; x++) {
GuessNumber = (short) NumScan.nextInt();

if (GuessNumber == RandomToGuess) {
System.out.println("Congratulations you got the correct number!");
break;
} else if (GuessNumber > RandomToGuess) {
UserTries--;
DisplayUserTries--;
System.out.println("Number Too High");
System.out.println(DisplayUserTries + "Tries remaining:");
if (UserTries == 0) {
System.out.println("GAMEOVER :P");
System.out.println("The number was: " + RandomToGuess);
break;
}
} else if (GuessNumber < RandomToGuess) {
UserTries--;
DisplayUserTries--;
System.out.println("Oops! Too Low");
System.out.println(DisplayUserTries + "Tries remaining:");
if (UserTries == 0) {
System.out.println("GAMEOVER :P");
System.out.println("The number was: " + RandomToGuess);
break;
}
} else {
System.out.println("Please input integerss only");
}
}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote