CH 5: Input & Output in Programming

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

The print an integer right justified with a width 15, the correct format sting fro System.out.printf method would be?

"%15d" The correct answer is ''%15d'' where 15 specifies the width and since it is positive it is right justified and d specified integer

The print a floating point number with a precision of 4 decimal places, the correct format string for System.out.printf would be?

".4f" he correct answer is ''%.4f'' where .4 specifies the precision and f specifies it is a floating point number.

The special sequence for inserting a newline within a format string using System.out.printf so that what follows will be printed on the next line is:

/n

The following code fragment will result in which output? System.out.println(67.5); System.out.println(92.3);

67.5 92.3

The graphical user interface (GUI) of Java can be broken down into which of the following two classes?

Abstract Window Toolkit (AWT) and Swing

When it comes to Java, a(n) _____ is used to hold or store all things relating to the graphical user interface (GUI).

Container

Which of the following Java classes is used to create and render 2-dimensional graphics?

Graphics2D

If you wanted to know if a user selected ''Oranges'' from a list of check boxes, which event listener is most appropriate?

ItemListener

Which of the following options will allow users to select as many items as they want?

JCheckBox

In order to add a JLabel to a GUI application, which component is needed first?

JFrame

Which of the following GUI classes allows you to add all of the elements discussed in this lesson?

JFrame

Which of the following is required before adding text fields, labels, buttons, or tool tips?

JFrame

Which of the following correctly creates a new JFrame without a title?

JFrame jf = new JFrame();

Which of the following creates a JFrame and sets it to a height of 900 pixels and a width of 800 pixels?

JFrame jf = new JFrame(); jf.setSize(800, 900); After creating the instance of JFrame, you use setSize and pass the width and height as integer values.

Which syntax represents the valid way of setting the title of a frame?

JFrame jframe = new JFrame(''New JFrame Title'');

Consider the following Java code. What is the name of the constructor for the class being instantiated? JFrame thisFrame = new JFrame('Hi There');

JFrame()

What are the two containers that form the basis GUI application structure in Java?

JPanel and content panes

You are developing a program to accept user input. Users will enter population counts of bacteria and dd them together. (numbers in the billions). Which data type would be best for the user to cover their input?

Long

When using the Scanner class to read data from the console, if the nextInt() method is used but the value in the stream is not an integer but a character, the method will?

Throw inputMatchException

The following are the properties of GUI components that are modified by the layout manager object except?

Top

In the context of common computer graphical elements, what does the acronym WIMP represent?

Window, icon, menu, and pointer.

You are developing a user interface for a software application. How would you proceed with this process?

You would perform user analysis, and collect functionality requirements.

How would you draw a rectangle that is a solid color?

g.fillRect(10, 20, 100, 100); he fillRect method takes a starting and ending x, y coordinate. If you set the fill for the Graphics object (in this case g), it will be filled with that color.

Which of the following options will create a rectangle using the Graphics2D instance named g3?

g3.draw(new Rectangle2D.Double(20, 100, 100, 50)); he Rectangle2D object creates a 2-d rectangle, and you provide starting x,y and height width.

Which of these is not a class that represents a layout manager?

java.swing.CircleLayout

Which of the java commands will compile java files from the command-line prompt?

javac he command javac will compile java source files into bytecodes and the .class file(s).

You have created a new JFrame (jf) and added several other Swing elements. Which code statement correctly ensures that you will see your new GUI application on screen?

jf.setVisible(true);

How would you change the text of a JLabel (lblUser) to "Enter User Name?"

lblUser.setText("Enter User Name"); The setText method can be used at run time to programmatically change the text of the JLabel.

When using the Scanner class to read data from the console, in order to read data which is a double and assign it directly to a double variable you can use the method

nextDouble() The correct answer is 'nextDouble()' which will obtain the next value and convert it to double data type and return it as such.

The println method in Java ___

terminates the line

Examine the following code. What could we add to ensure only integers where entered? int qty1; int qty2; Scanner enterQty = new Scanner(System.in); System.out.print;n("Enter Quantity"); qty1= enterQty.nextInt(); qty2 = enterQty.nextInt(); System.out.println(qty1 + qty2):

while (!enterQty.hasNextInt()) { System.out.println(:Enter integer"); enterQty.next(); The exclamation point indicates an inversion/false. In other words, while the enterQty value is NOT an integer, display an error. Use the next() function to read the next value.

Mike is working on a graphical user interface. How would he describe the most important aspect of the graphical user interface design to his colleagues?

Usability is important so that the product can be used by specified users.

To print a floating point number with a precision of 2 and a width of 6, the correct format string for System.out.printf would be:

"%6.2f'' The correct answer is ''%6.2f'' where 6 specifies the width, .2 the precision, and f the floating point number.

The process of manually setting components' properties without the use of the layout manager is known as?

Absolute positioning

When creating a JLabel that has an icon instead of text, what do you need to create first?

An instance of ImageIcon

Which class, BufferedReader or oScanner, can be used when it needs to be shared across multiple threads?

BufferedReader Because its synchronized

Which is the correct way to specify input from the console using the BufferedReader contractor?

BufferedReader(new inputStreamReader(System.in)) The correct answer is 'BufferedReader(new InputStreamReader(System.in))' because the constructor takes Reader as a parameter and System.in specifies the standard input stream.

When it comes to Java, a(n) _____ is used to fill up the rest of the container with content and can be called its extension.

Component

This code will not compile, Java displays an error. What is missing? Scanner i2 = new Scanner (system.in);

The Scanner utility was not imported

When the main method pares the input parameters, it stores the larges numbers first?

False

The command-line is the only way to pass parameters to main method ?

False When running a program from within other environments such as an Integrated Development Environment (IDE), you can specify the configuration options to include program arguments.

As you are building a GUI application, you want to add a text entry field, but default it with some text. Which line of code achieves this task?

JTextField text1 = new JTextField("[Enter User Name]");

Which place is the best to look for all the methods available in the Graphics2D class?

Javadocs

The layout manager object is an implementation of which interface?

LayoutManager interface

Which of the following does NOT represent usability of the interface of a computer software application?

Licensing

Tool Tips are:

Methods

The main methods parameter, args allows passing which of the following?

Multiple arguments separated by space. Arguments are stored in a string array and can be converted by the main method to whatever data types it expects.

In Java, which of the following is true of Abstract Window Toolkit (AWT) and Swing?

One is called lightweight and the other is heavyweight They are tools that developers use to create the GUI They are used to make components, such as buttons and scroll bars

Which of the following is possible with the Graphics2D class?

Overlapping shapes

If you were to create a rounded rectangle, which option correctly creates the shape?

RoundRectangle2D newRect = new RoundRectangle2D.Float(5, 20, 200, 43, 2, 2); Rounded rectangles include starting and ending x, y coordinates as well as the angle of the arc/sweep on the corners.

In order to create a polygon, what do you need to do first?

Create an instance of the Polygon class

Which of these is not a component of event-driven programming in Java?

Event GUI

The following code fragment will result in which output? System.out.println(''Good morning\nJoe'');

Good morning Joe

The following code fragment will result in which output? System.out.println(''Good morningnJoe'');

Good morningnJoe he correct answer is 'Good morningnJoe'. A special character sequence has a slash such as \n but in this string, we just have an n within a string which is just a literal.

The Graphics2D class is an extension of what other Java class?

Graphics

The following are all event listener interfaces except?

GuiListener

Which of the following creates a JLabel with text?

JLabel jl = new JLabel("New Label"); By passing a string to the constructor, the new JLabel will have the text of 'New Label'

Why is the graphical user interface (GUI) such an important function of a program or application?

It gives the user the ability to use the program or application t's a mandatory requirement for users to interact with It allows the user to see what's going on

How would you describe the use of a wizard in the context of computer software applications?

It is a series of pre-defined steps to implement a specific workflow.

Examine the following code. What is true about the variable inputValue ? Scanner inputValue = new Scanner(System.in);

It is an instance of the Scanner class order to read user input, we need to create an instance of the Scanner class to capture that input. We will read the input into the inputValue instance variable.

Why is there a need to have at least one JFrame instance in a Java GUI application?

It serves as the base container.

The following are examples of GUI classes in Java EXCEPT?

JButtonChecker

How can the text in a label component be changed?

Programatically at run time.

The following code fragment will result in which output? int value = 15; System.out.println(''The price= ''+value);

The price= 15 The correct answer is 'The price= 15' because there is a space after equals symbol and then it prints the value.

Which of these is a method in an ActionListener interface?

addActionListener()

When three arguments are passed to the main method, they will be stored in?

args[0] through arg[2] Java array indexes start at 0 and there are 3 values: args[0], args[1], and args[2].

Which of the following correctly adds a listener to a button?

button.addActionListener(new ActionListener() { }

Consider the following Java code. Which of the following options will correctly add a check box to the group? ButtonGroup buttons = new ButtonGroup(); JCheckBox checkers = new JCheckBox('Room 237');

buttons.add(checkers);

Th BufferedReader class has a smaller buffer than the Scanner class

fasle The correct answer is 'False'. BufferedReader has a default 8KB buffer whereas Scanner only has a 1KB buffer. BufferedReader also lets you provide a bigger buffer than the default, if needed.

Which of these is not a method for drawing shapes?

fillLine

The System.out.printf method works exactly the same as the:

format method

Based on the following code, what data types could be entered without error? entry1 = enterV.nextFloat(); entry2 = enterV.nextFloat(); System.out.println(entry1 + entry2);

integer, float ava will accept an integer in a float field (would just make it something like 25.0). But, if you try to enter other data types it will fail (although double may also work, depending on the length and precision). It's best to check for valid values or allow double from the start.

This method determines where an element will be displayed on the screen and its size:

setBounds

Which class allows you to set the thickness of a line?

setStroke

What JTextFields method is used for managing action events?

void addActionListener() void addActionListener(ActionListener l) is responsible for adding the specified action listener to receive action events from the text field.


संबंधित स्टडी सेट्स

PATH 370 - CYU (44, 45, 47, 51, 52)

View Set

Chapter 3.1 Definition of a Tort

View Set

Ch 44 Care of patients with Problems of the Peripheral Nervous System

View Set

Behavioural Economics essay type questions

View Set

Sense Organs and their parts/functions

View Set

Chapter 3: Supply and Producer Choice

View Set

MGMT 495 Final WWU Nordin (Ch. 6-10)

View Set

Driver's Permit test questions and answers

View Set