CS109: Intro to programming 3

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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

''%.4f''

To print an integer right justified with a width 15, the correct format string for System.out.printf method would be:

''%15d''

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 following code fragment will result in which output? System.out.println(67.5); System.out.println(92.3);

67.5 92.3

What is one of the characteristics of a non-static method in Java?

A non-static method belongs to an instance of the class

When used to create a class, the final keyword will prevent the creation of _____

A subclass from the class

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

Absolute positioning

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

Abstract Window Toolkit (AWT) and Swing

To make a method a static method we need to:

Add the keyword 'static' to the method signature

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

All of these answers are correct

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

All of these answers are correct

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

An instance of ImageIcon

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

BufferedReader(new InputStreamReader(System.in))

How is the return value declared in a method?

By the data type alone before the method name

Trying to create a subclass from a final class, or re-initialize a final variable, will result in what?

Compiler errors: program will not run

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

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

Container

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

Create an instance of the Polygon class

To call a non-static method from a static method you have to:

Create an instance of the class

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

Event GUI

When the main method parses the input parameters, it stores the largest numbers first.

False

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

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

Graphics

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

Graphics2D

The following are all event listener interfaces except?

GuiListener

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

Long

Tool Tips are:

Methods

The following code creates a subclass of Customer. Will the last line of code work? class Customer { private long customerPhone; private void getCustomerPhone () { } } class Customer_New extends Customer { Customer newCustomer = new Customer (); newCustomer.getCustomerPhone (); }

No, Customer's methods are private

Examine the following code. Where can the program use the variable fte? public class Employee_Public_View { public String employeeName = new String (); public int jobcode; private float fte; float getFTE (float fte) { this.fte = 1; return fte; } }

Only in the Employee_Public_View class

Which of the following is possible with the Graphics2D class?

Overlapping shapes

It is recommended to create most methods and variables as _____.

Private

Examine the following code. Which variable cannot be re-initialized or assigned a new value? final boolean result; int counter = 0; final String Product = "Rubix Cube";

Product

Which type of variable or method is protected but can be used with classes in the package (and also subclasses)?

Protected

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);

Which statement is NOT true about the static methods?

Static methods can be overridden

What is the difference between an instance method and a static method?

Static methods should be accessed through class and not instance

Which is the parameter in the following method: public static void main (String [ ] args) { }

String [ ] args

How can the text in a label component be changed?

Text editing at run time

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

The Scanner utility was not imported.

_____ are passed to the main method as an array of String objects.

The command line options

What does the keyword static mean in the declaration of the main method?

The method can be called without creating an instance

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

The price= 15

Examine the following code. What is true about the variables and methods within the class NYCustomer? class NYCustomer { public long customerPhone; public void getCustomerPhone () { } }

They can be accessed by other packages and classes

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

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.

Final can be used to protect the following:

Variables, methods and classes

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

Window, icon, menu, and pointer.

Examine the following code. What is wrong? final int myInt = 100; myInt = new Int(200);

You can't assign a new value to a final variable

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.

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

Which of these is a method in an ActionListener interface?

addActionListener()

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);

Most development environments allow setting up a run configuration where you can pre-populate program arguments. If program arguments will change regularly, however, you can use the _____ to run the program and type in the parameters you want to pass.

console/terminal command-line application

In the code below, how can the method findsum be called from the method main? class mathcode { static int findsum (int x, int y) { return x+y; } public static void main (String args [ ] ){ // call method findsum } }

findsum(2, 6);

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

format method

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

g2.fillRect(10, 20, 100, 100);

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

g3.draw(new Rectangle2D.Double(20, 100, 100, 50));

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

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

javax.swing.BoxLayout

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);

The layout manager object is an implementation of which container?

layout manager interface

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

lblUser.setText("Enter User Name");

The main method declaration contains the keyword void to indicate the main method _____ returns a value.

never

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()

In the code below, how can the method quote be called from the method main? class price { int quote(int x, int y) { return x+y; } public static void main(String[]args) { //call quote } }

price p = new price(); p.quote(2,3);

Which of the method signatures is NOT valid for a static method?

public int action()

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

The main function declaration is: public _____ void main(String[] args).

static

The println method in Java _____.

terminates the line

The main method is called from _____ after your Java program is loaded into memory.

the Java Virtual Machine

What does this method return? public void subtractNumbers (int m, int n) { System.println (p); p = m - n; }

the method does not return a value

Given a class Example with static method called action with no parameters, which of the following is never a correct call for the static method ?

this.action();

The Scanner class (package java.util.Scanner) is a text scanner that breaks up input into _____.

tokens

What JTextFields method is used for managing action events?

void addActionListener()

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

while (!enterQty.hasNextInt()) { System.out.println("Enter integer"); enterQty.next(); }

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

Licensing

Which of these is not a method for drawing shapes?

fillLine

The top, abstract class in Java to represent an input stream of bytes is _____.

InputStream.

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.

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

It serves as the base container.

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

ItemListener

The following are examples of GUI classes in Java EXCEPT?

JButtonChecker

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 serves as a foundation, a palate on which to add elements?

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);

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()

Which of the following creates a JLabel with text?

JLabel jl = new JLabel("New Label");

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

JPanel and content panes

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 of the following is NOT true about a method in Java?

Java methods can return more than one value

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

Javadocs


Kaugnay na mga set ng pag-aaral

DECA Hospitality and Tourism Cluster Practice Exam

View Set

Chapter 1 Introduction to Nursing

View Set

Chapter 3: Molecules, Compounds, and Chemical Equations

View Set

Chapter 4: Supply Chain Planning

View Set

Chapter 10 Shoulder Joint Kinesiology

View Set

Chapter 3 - Health Policy and the Delivery System

View Set

OB EXAM PRACTICE QUESTIONS PART 2

View Set

AP Calculus Derivative and Integral Formulas

View Set