Question

Some java questions:

18. Consider the following class definitions public class TestAB public static void main (String args) A bl new B() в ь2 -newor wholly in uppercase letters. They 20. JPEG file names end in .jpg, -.jpeg or any of these two partially consist of the23. Which of the following statements shows a small message or input dialog? A. JPopUp (File restored, RestoreWare); B. J

18. Consider the following class definitions public class TestAB public static void main (String args) A bl new B() в ь2 -new B() ; b1.х, А.у, Ь2.х, в.у); System.out.printf ("%d, Sd, %d, d\n", class A public int x = 2; public static int y = 4; public A () ( X=y- class Bextends A public int x = 32; public static int y = 45; public B ( x ++y What is the result of attempting to compile and run the above program? A. 3, 2, 46, 47 B. 4, 2, 47,47 C. 4, 6, 44, 43 D. 4, 2, 46, 47 Е. 5,6, 44, 43 19. Consider the regular expression given by the Java string "[A-Z (5,8)\\s?\\d{3}" Which of the following strings matches this expression? (Note: Do not assume that the matching method will automatically add a^ and a $) X. "COMP-SCI 314? is cool!" Y. "COMPSYS 89X is full" Z. "LAW 101 is not needed for COMPSCI" A. X and Y only B. Xand Z only C. Y and Z only D.All of X, Y, and Z E. None, or only one of X, Y, and Z
or wholly in uppercase letters. They 20. JPEG file names end in ".jpg", "-.jpeg" or any of these two partially consist of the file name extension only. Which of the following lines of Java code could you use to check whether a string fileName contains the file name of a JPEG file? never X if (fileName.matches (".+\. [jJ] [pP] [eE] ? [gG]")) .. Y. if (fileName.matches ("\\w+\ . [jJ] [pP] [eE] ? [gG] ") ) { Z. if (fileName.matches ("\\w+\\ . [jJ] [pP] [eE] ? [gG]")) { A. X and Y only B. X and Z only C. Yand Zonly D. All of X, Y, and Z E. None, or only of X, Y, and Z one 21. An IPv6 address (an IP Internet address in IP version 6) is a 128 bit value. A full IP 6 address is written as of 8 groups of 4 hexadecimal digits each. A hexadecimal digit can have any value from 0 to 9 or A to F, with lowercase "a" to "f" permitted in place of uppercase digits. The groups are permitted formats: a string separated by colons ("."). Examples of o 2001:0db8:85a3:0000:0000:8a2e:0370:7334 o 2001:0DB8:85A3:0000:0000:8A2E:0370:7334 o FE80:0000:0000:0000:01FF:fe23:4567:890a Which of the following regular expressions matches a full IPv6 address? Note: This question asks for the regular expression only, not for its representation as adds and $if these are not specified. a Java String and may not necessarily be used with a method that X. a-fA-F0-9] (4 } : ) (8) $ Y. A-Fa-f0-9] (4:) (8) $ Z. 0-9a-fA-F) 4):) (8)$ A. X and Y only B. X and Z only C. Y and Z only D. All of X, Y, and Z E. None, or only one of X, Y, and Z 22. Consider the following code double interestRate In Percent) public double compute Interest (double accountBalance, /Compute the interest (positive) account balance. on a if (accountBalance < 0) throw new NegativeAccountBalanceException (accountBalance) ; interestRate In Percent 100.0 return accountBalance This does not compile. What could contribute to the problem? A. The custom exception is not caught in the method B. The return statement cannot contain a formula C. The return statement is unre achable code. D. We cannot divide by 100.0, it should be 100 E. The account balance is a double and should be compared to 0.0 rather than just 0
23. Which of the following statements shows a small message or input dialog? A. JPopUp ("File restored", "RestoreWare"); B. JMessage.show (null, "File restored", C. JPanel.showMessageDialoq ("File restored", "RestoreWare") ; "RestoreWare") ; D. JPanel.showInputDialog ("Please enter your car registration plate"); E. JOptionPane.show Input Dialog ("What is your cat's name ?"); 24. If you wanted to align multiple similar GUI JCheckBoxes vertically in a column on a JPanel, how would you proceed? A. Set the layout manager of the JPanel to a new GridBagLayout instance. Instantiate a GridBagConstraints object with a common gridx value for the components, a gridy value of GridBagConstraints.VERTICAL and an anchor of GridBagConstraints.LEFT, then pass the object to the setLayout () methods of the JCheckBoxes you want to add. B. Choose a GridBagLayout for the JPanel, with GridBagConstraints set to a common gridx value for the components, a gridy value of GridBagConstraints.COLUMN and an anchor of GridBagConstraints.WEST, then pass the GridBagConstraints to the setLayoutConstraints ( method of the JPanel before adding each JCheckBox C. Set the layout manager of the JPanel to a new GridBag Layout instance. Instantiate a GridBagConstraints object with a common gridx value for the components, a gridy value of GridBagConstraints.COLUMN and an anchor of GridBagConstraints.LEFT, then pass the object to the setLayout () methods of the JCheckBoxes you want to add D. Choose a GridBagLayout for the JPanel, with GridBagConstraints set to a common gridx value for the components, a gridy value of GridBagConstraints.RELATIVE and an anchor of GridBagConstraints.WEST, then pass the GridBagConstraints to the add () method of the JPanel together with each JCheckBox reference. E. Choose a ColumnLayout for the JPanel then add (O the JCheckBoxes to the JPanel. 25. What is the purpose of setting the model of a JComboBox to a model that implements the MutableComboBoxModel interface? A. The MutableComboBoxModel interface lets us select of multiple items in the JComboBox simultaneously B. The MutableComboBoxModel interface lets us resize the JComboBox. C. The MutableComboBoxModel interface lets us modify the list of items in the JComboBox during the execution of our application D. The MutableComboBoxModel interface limits the visible JComboBox list to the items that fit onto the screen and provides a scrollbar for the rest. E. The MutableComboBoxModel interface lets us change the JComboBoxModel during the execution of the program
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1(18) : The answer is B (4, 2, 47, 47) when we compile and run the program.

Answer 2(19) : None of the expressions matches the string (Answer is E), since all of the strings contain small case characters. And the expression doesn't include small case characters ("[A-Z]{5,8}\\s?\\d{3}").

Answer 3(20) : Only Z statement is correct since the use of only a single backward slash after the "+" sign gives invalid sequence error. And the Z statement checks all the criteria necessary for the jpeg/jpg filename to be valid. Hence answer is E.

Answer 4(21) : The correct expression of regex for verifying an ipv6 address is "^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$". The last statement in the regex part which is "[0-9a-fA-F]{1,4}$" cannot be grouped to the first statement because of syntax and logical errors. Since the statement mentioned isn't an option in the question. But in the question it is asked that only regular expression is needed, not the java string. So the answer is D (all of X,Y,Z). But if the java string is needed, then the answer is E because the correct expression is not provided in X,Y and Z.

First 4 questions have been answered.

Add a comment
Know the answer?
Add Answer to:
Some java questions: 18. Consider the following class definitions public class TestAB public static void main (String a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Revision Question Consider the following Java class: { public static void main (String [ ] args)...

    Revision Question Consider the following Java class: { public static void main (String [ ] args) { ArrayQueue<Integer> queue; queue = new ArrayQueue<Integer> () ; Integer x, y ; x = 3; y = 6; queue.offer (x) ; queue.offer (12) ; queue.offer (y) ; y = queue.peek () ; queue.poll () ; queue. offer (x - 2) ; queue.offer (x) ; queue.offer (y + 4) ; System.out.println ("Queue Elements: ") ; while (! queue.empty() ) System.out.print (queue.poll () + "...

  • import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y,...

    import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y, z; double average; Scanner scan = new Scanner(System.in); System.out.println("Enter an integer value"); x = scan.nextInt( ); System.out.println("Enter another integer value"); y = scan.nextInt( ); System.out.println("Enter a third integer value"); z = scan.nextInt( ); average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } What is output if x = 0, y = 1 and...

  • Need Help....Java MyProgram.java: public class MyProgram { public static void main(String[] args) { } } House.java:...

    Need Help....Java MyProgram.java: public class MyProgram { public static void main(String[] args) { } } House.java: public class House { private String address; private double cost; private double interst; private int mortgageTime; private double monthPayment; } As you consider your life before you, one thing you may consider is buying a house in the future. In this assignment, you will explore concepts of this amazing opportunity and create a program that may be of benefit to you in the future!...

  • Simple java questions Q2.java: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Q2 extends JFrame { public static void createAndShowGUI() { JFrame frame = new JFrame(&#3...

    Simple java questions Q2.java: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Q2 extends JFrame { public static void createAndShowGUI() { JFrame frame = new JFrame("Lab"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("Sans-serif", Font.BOLD, 20); JLabel label = new JLabel("Enter a word"); label.setFont(font); JTextField textField = new JTextField(10); textField.setFont(font); JButton button = new JButton("Enter"); button.setFont(font); Font font1 = new Font("Sans-serif", Font.BOLD, 30); JCheckBox sansSerif = new JCheckBox("Sans-serif"); sansSerif.setFont(font1); JCheckBox serif= new JCheckBox("Serif"); serif.setFont(font1); Font font2 = new Font("Sans-serif", Font.ITALIC, 15); JRadioButton...

  • Question 28 public class Main public static void main(String args[]) { Iparentp=new Child (1.2); p.printo: interface...

    Question 28 public class Main public static void main(String args[]) { Iparentp=new Child (1.2); p.printo: interface Iparent public int x = 1; public void printo: class Child implements Iparent private int y public Child(int a, int b) y b: public void printot System.out.print("Child"-yl: Child 2 public int x = 1; public void print(); class Child implements Iparent! private int y public Child(int a, in lb) y=b; public vold print! System.out.pnt("Child"+y): Child 2 1 None of the above • Previous

  • Find the following java program's 9 syntax errors. public class Parameters { public static void main()...

    Find the following java program's 9 syntax errors. public class Parameters { public static void main() { double bubble = 867.5309; double x = 10.01; printer(double x, double y); printer(x); printer("barack", "obama"); System.out.println("z = " + z); } public static void printer(x, y double) { int z = 5; System.out.println("x = " + double x + " and y = " + y); System.out.println("The value from main is: " + bubble); }

  • For Java please.Artwork. javaimport java.util.Scanner;public class ArtworkLabel {public static void main(String[] args)...

     Given main(). define the Artist class (in file Artist java) with constructors to initialize an artist's information, get methods, and a printlnfo() method. The default constructor should initialize the artist's name to "None' and the years of birth and death to 0. printinfo() should display Artist Name, born XXXX if the year of death is -1 or Artist Name (XXXX-YYYY) otherwise. Define the Artwork class (in file Artwork.java) with constructors to initialize an artwork's information, get methods, and a printinfo() method. The constructor should...

  • This is for a java program public class Calculation {    public static void main(String[] args)...

    This is for a java program public class Calculation {    public static void main(String[] args) { int num; // the number to calculate the sum of squares double x; // the variable of height double v; // the variable of velocity double t; // the variable of time System.out.println("**************************"); System.out.println(" Task 1: Sum of Squares"); System.out.println("**************************"); //Step 1: Create a Scanner object    //Task 1. Write your code here //Print the prompt and ask the user to enter an...

  • What output is produced by the following program? public class MysteryNums public static void main(String[] args)...

    What output is produced by the following program? public class MysteryNums public static void main(String[] args) - int x = 12; int y = x - 3; 3, sentence (y, x + y); . public static void sentence (int numi, int num2) { 4: System.out.println(num1 + " + num2);

  • Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args)...

    Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); final int maxSize = 128; String[] titles = new String[maxSize]; int[] lengths = new int[maxSize]; int numDVDs = 0; String op; op = menu(stdIn); System.out.println(); while (!op.equalsIgnoreCase("q")) { if (op.equalsIgnoreCase("a")) { if (numDVDs < maxSize) numDVDs = addDVD(titles, lengths, numDVDs, stdIn); } else if (op.equalsIgnoreCase("t")) searchByTitle(titles, lengths, numDVDs, stdIn);    else if (op.equalsIgnoreCase("l")) searchByLength(titles, lengths, numDVDs, stdIn); System.out.println('\n');...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT