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

Question 1 What is the name for Java classes that are provided so that values of

ID: 3798043 • Letter: Q

Question

Question 1

What is the name for Java classes that are provided so that values of primitive data types can be treated as objects?

interfaces

extensions

wrappers

event handlers

1 points   

Question 2

Write a program to input the radius of the base and height of a cylinder, and calculate and print the surface area, volume, and area of the base of the cylinder.

Which words from the problem statement above could we use to determine the operations for this program?

input, calculate, print

cylinder, program, volume

height, cylinder, radius

radius, cylinder, print

1 points   

Question 3

Which of the following is not a method of the class JTextField?

setText

setEditable

addActionListener

setVisible

1 points   

Question 4

Which of the following methods is NOT part of the class JFrame?

setVisible

setSize

setTitle

getText

1 points   

Question 5

Show output

Get input

Get input and show results

Display a prompt to the user

1 points   

Question 6

To create a window, which of the following classes has to be extended?

Container

JFrame

JButton

JTextField

1 points   

Question 7

To display a window, you must invoke the method ____.

displayWindow

show

setVisible

setDisplay

1 points   

Question 8

The Java class that you use to create windows is ____.

JTextField

JFrame

JButton

JLabel

1 points   

Question 9

Which method is used to register a listener object to a button object?

addActionListener

registerButton

eventButton

buttonListener

1 points   

Question 10

A(n) ____ is a method of a class that is automatically executed when an object of the class is created.

inheritance

package

constructor

interface

1 points   

Question 11

Which package will you most likely have to import in order to write a GUI program?

java.awt.*

java.io.*

java.text.*

java.net.*

1 points   

Question 12

Write a program that takes as input the pay rate and hours worked of an employee and calculates the pay of the employee.

Based on the problem statement above, which of the following would most likely be chosen as the class?

Pay_Rate

Hours_Worked

Employee

Pay

1 points   

Question 13

Which method contains the code that the program executes when a specific event is generated?

buttonListener

GUIListener

actionPerformed

windowListener

1 points   

Question 14

If Shape is a class and you create a new class Rectangle that extends Shape, then Shape is a(n) ____ and Rectangle is a(n) ____.

Which word goes in the second blank of the sentence above?

subclass

superclass

method

package

1 points   

Question 15

Which class is part of the package java.awt?

JFrame

JButton

JOptionPane

Container

1 points   

Question 16

Write a program that takes as input the pay rate and hours worked of an employee and calculates the pay of the employee.

Based on the problem statement above, which of the following would be a data member?

hoursWorked

employee

pay

job

1 points   

Question 17

Calculate

Exit

Both Calculate and Exit

Perimeter

1 points   

Question 18

Write a program to input the radius of the base and height of a cylinder, and calculate and print the surface area, volume, and area of the base of the cylinder.

According to the problem statement above, which of the following would be a data member?

Radius of the base

Surface area

Volume

Input

1 points   

Question 19

Which of the following sets the window width to 100 pixels and the height to 200 pixels?

setSize(100, 200);

setSize(200, 100);

setDims(100, 200);

set(200, 100);

1 points   

Question 20

Which of the following is NOT a required attribute of a window?

title

width

height

color

interfaces

extensions

wrappers

event handlers

Explanation / Answer

1.

Wrappers.

Explanation: The wrapper classes are used to treat the values of primitive data types as objects. The object of this class wraps and store the primitive data type values.

2.

/*

* program to input the radius of the base and height of a cylinder,

* and calculate and print the surface area, volume,

* and area of the base of the cylinder

*/

import java.util.Scanner;

//define the class Cylinder

public class Cylinder

{

            public static void main(String[] args)

            {

                        double radius, area, Volume, height, baseArea;

                        Scanner sc = new Scanner(System.in);

                        //read the radius of the base and height of a cylinder.

                        System.out.println(" Enter the radius of the base of a Cylinder : ");

                        radius = sc.nextDouble();

                        System.out.println(" Enter the Height of a Cylinder : ");

                        height = sc.nextDouble();

                       

                        //calculate and print the surface area, volume,

                        //and area of the base of the cylinder.

                        area = 2 * Math.PI * radius * (radius + height);

                        Volume = Math.PI * radius * radius * height;

                        baseArea= Math.PI * radius * radius;

                       

                        System.out.println("The Surface area of the Cylinder is: "+ area);

                        System.out.println("The Volume of the Cylinder is: "+ Volume);

                        System.out.println("The base area of the Cylinder is: "+baseArea);

            }

}

From the above problem statement, the words input, calculate, and print are used to determine the operations for this program.

Explanation:

The word input is used to determine the operation of reading the data (radius of the base and height of a cylinder).

The word calculate is used to determine the operation of the calculation of the surface area, volume, and area of the base of the cylinder.

The word print is used to determine the operation of the printing the values of the surface area, volume, and area of the base of the cylinder.

3.

Only addActionListener is a method of JTextField, others are not methods of the class JTextField.

Explanation:

The setText and setEditable methods are inherited from the JTextComponent class and setVisible method is inherited from the JComponent class. The classes JTextComponent and JComponent are the superclasses of the class JTextField.

Therefore, only the addActionListener is a method of JTextField.

4.

getText

Explanation: The methods setVisible, setSize, and setTitle are the part of the class JFrame and used to set the visibility, size, and title of the frame. The method getText is not part of the class JFrame.

5.

Image not clear

6.

JFrame.

Explanation: To create a window, JFrame class has to be extended. Because, the JButton, and JTextField are present in the JFrame class.

7.

setVisible

Explanation: The setVisible method is used to display the window. To display the window, the setVisible method must be invoked in the class.

8.

JFrame

Explanation: The JFrame class is used to create window. It consists of JTextField, JButton, and JLabel methods.

9.

addActionListener method is used to register a listener object to a button object.

Explanation: An object must implement the ActionListener interface to detect when the user clicks on the button.

To register this object to the button object, the addActionListener method is used.

10.

Constructor

Explanation: When the object of the class is created, the Constructor method of a class executes automatically.

11.

java.awt.*

Explanation: GUI program needs separate window to execute the task which is provided by abstract window toolkit known as AWT. So, java.awt.* is used in GUI programs.

12.

/*

* program that takes as input the pay rate and hours worked

* of an employee and calculates the pay of the employee

*/

import java.util.Scanner;

//define the class Employee

public class Employee

{

            public static void main(String[] args)

            {

                        //declare the data members

                        int pay_Rate;

                        int hours_Worked;

                        int pay;

                        //create an scanner object

                        Scanner sc = new Scanner(System.in);

                        //read the pay rate and hours worked of an employee

                        System.out.println("Enter the pay rate of an employee: ");

                        pay_Rate = sc.nextInt();

                        System.out.println("Enter the hours of an employee: ");

                        hours_Worked = sc.nextInt();

                        //calculates the pay of the employee

                        pay= pay_Rate*hours_Worked;

                        System.out.println("The pay of the employee: "+pay);                     

            }

}

Based on the above program, the most likely chosen as the class is Employee.

Because, the program calculates the pay of an employee. Therefore, Employee is the best suitable class.

The Pay_Rate, Hours_Worked, and Pay are the data members.

13.

actionPerformed

Explanation: The actionPerformed method is used to execute a generate event in the java class. When the action is generated, the object of the actionPerformed is invoked.

14.

Subclass

Explanation: If Shape is a class and you create a new class Rectangle that extends Shape, then Shape is a Superclass and the Rectangle is a subclass. The Rectangle class can inherits the methods of the class Shape.

15.

Container

Explanation: The Container class is a part of the java.awt package. The JFrame, JButton, and JOptionPane are part of the javax.swing package but not java.awt package.

16.

Program:

/*

* program that takes as input the pay rate and hours worked

* of an employee and calculates the pay of the employee

*/

import java.util.Scanner;

//define the class Employee

public class Employee

{

            public static void main(String[] args)

            {

                        //declare the data members

                        int pay_Rate;

                        int hoursWorked;

                        int pay;

                        //create an scanner object

                        Scanner sc = new Scanner(System.in);

                        //read the pay rate and hours worked of an employee

                        System.out.println("Enter the pay rate of an employee: ");

                        pay_Rate = sc.nextInt();

                        System.out.println("Enter the hours of an employee: ");

                        hoursWorked = sc.nextInt();

                        //calculates the pay of the employee

                        pay= pay_Rate* hoursWorked;

                        System.out.println("The pay of the employee: "+pay);                     

            }

}

hoursWorked, and pay are the data member for the above problem.

17.

Both Calculate and Exit

Explanation: The Calculate and Exit are of type JButton class in the given window.

18.

Program:

/*

* program to input the radius of the base and height of a cylinder,

* and calculate and print the surface area, volume,

* and area of the base of the cylinder

*/

import java.util.Scanner;

//define the class Cylinder

public class Cylinder

{

            public static void main(String[] args)

            {

                        double radius, area, Volume, height, baseArea;

                        Scanner sc = new Scanner(System.in);

                        //read the radius of the base and height of a cylinder.

                        System.out.println(" Enter the radius of the base of a Cylinder : ");

                        radius = sc.nextDouble();

                        System.out.println(" Enter the Height of a Cylinder : ");

                        height = sc.nextDouble();

                       

                        //calculate and print the surface area, volume,

                        //and area of the base of the cylinder.

                        area = 2 * Math.PI * radius * (radius + height);

                        Volume = Math.PI * radius * radius * height;

                        baseArea= Math.PI * radius * radius;

                       

                        System.out.println("The Surface area of the Cylinder is: "+ area);

                        System.out.println("The Volume of the Cylinder is: "+ Volume);

                        System.out.println("The base area of the Cylinder is: "+baseArea);

            }

}

According to the above problem, Radius of the base would be a data member.

Because, the problem takes the radius of the base of a Cylinder as an input and

calculates the Surface area and Volume.

19.

setSize(100, 200);

Explanation: The method setSize is used to set the size of the window. The first parameter of this method is width and the second parameter is height. Here, the width is 100 and height is 200 pixels.

20.

Color

Explanation: Color is not an attribute of a window. The Window has title, width, and height.

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