Java | JSP | JSF Answers

Questions answered by Experts: 3 611

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

6. In Java, __ is the only type of exception that is NOT checked. Please select the correct option "A, B, C, D, or E"


A. The Exception class.

B. The RunTimeException class and its subclasses.

C. The IOException class and its subclasses.

D. The ArithmeticException class only.

E. The Throwable class only. 


5. Which method of the "Exception" class prints a list of methods that were called before the exception was thrown? Please select the correct option "A, B, C, D, or E"


A. printErrors()

B. getMessage()

C. printStackTrace()

D. traceStack()

E. toString()


4. Which method of the "Exception" class returns a message string? Please select the correct option "A, B, C, D, or E"


A. getError()

B. getMessage()

C. printMessage()

D. traceMessage()

E. toString()


2. A programmer carelessly assigned a negative value as index of an array. Which type of exception will be raised during execution? Please select the correct option "A, B, C, D, or E"


A. An IndexOutOfBoundsException is thrown.

B. A NumberFormatException is thrown.

C. The first slot of the array is used.

D. This is an Error, so the program immediately terminates no matter what.

E. The last slot of the array is used


1. The following code will cause a(n) ___ exception. Please select the correct option "A, B, C, D, or E"


class Sample

{

public static void main(String[] args)

{

int x = 0;

int y = 10;

int z = y/x;

}

}


A. ArithmeticException

B. ArrayIndexOutOfBoundsException

C. StringIndexOutOfBoundsException

D. NullPointerException

E. ClassNotFoundException


Write Java codes that use the “Scanner” class to ask the user to enter a number. Then, store the given number in a variable of double type named “n”. If n is a negative number, use the “throw” keyword to throw a message, “Java does not provide mechanism to find the squared root of a negative number...”. Then, use the “Exception” class to catch the thrown exception and display the message. If n is a positive number or zero, display the result of Math.sqrt(n). 


Make sure the output looks similar to the following.

C:\test>java Sample

Enter a number: -5.1

Java does not provide mechanism to find the squared root of a negative number...


C:\test>java Sample

Enter a number: 5.1

2.2583179370125386


C:\test>java Sample

Enter a number: 0

0.0 


 A garden watering valve can measure the volume of water coming out of a hose. A user fixed the valve to allow only 0.015 gallon of water. Create a Java exception class named “UnmatchedVolumeException” which will pass the following messages to a numerical controller.


Table:

Condition: volume > 0.015 ------- Message: Excessive volume.

Condition: volume < 0.015 ------- Message: Insufficient volume.


In the “main” method, take an input of volume. Write a proper Java exception handling code to throw an appropriate exception message. Make sure the output looks similar to the following. [Note: Be sure to use input and output dialog boxes]. Please have the input box ask "Enter the volume:" and have the output box give an output of "Excessive volume."



write a java program that assigns grades


An estate agency sells and rents out properties. Each property listed at the company has a property code and is assigned to an estate agent. The property code consists of 10 digits e.g. 1312122019. The first digit indicates whether the property is for sale (1) or available for renting (2). The second digit indicates whether it is a business property (> 2) or a residential property (<= 2). Properties that are for sale has a selling price while properties to be rented out has a rent amount (per month) and a value that indicates the duration of the contract


 



What is the output of the following code?


import java.lang. Math. *;


class Main


public static void main(String args[])


System.out.println(Math.round(-7.5));


System.out.println(Math.abs(-7.5));


System.out.println(Math.ceil(-7.5)); System.out.println(Math.floor(-7.5));


}


}


LATEST TUTORIALS
APPROVED BY CLIENTS