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
You have been tasked to design a COVID-19 screening application for your campus. The guards at each gate will screen the students and enter their details on the application.It should include the following functions:
1. A screening survey which will allow guards to record the students’ screening data.
2. Searching for a student’s details and status.
Technical Requirements:
1. The application should make use of Parallel arrays that will hold the details of the student as it is entered along with their status (admitted/not admitted). No more than 300 students will be allowed on a campus at any given day and time.
2. No student should be allowed access to the campus after 12h00 in the afternoons.
3.Each main task that the application should perform should be contained in a module and should be called from the mainline logic.
1.1 Write the pseudocode that will accurately represent the application you are designing.
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));
}
}
Disadvantages of using microservices
Write a Java code that creates a variable of int type named 'mode' and sets its initial value to 12. Create a method named 'setTime()' of void type that take four parameters: (1) one int parameter named 'h', (2) one int parameter named “m”, (3) one int parameter named “s”, and (4) one char parameter named 'ap'. In the body of the “setTime()” method, use an if statement to check whether or not the value of “h” is greater than or equal to 12. If so, subtract 12 from 'h'. Then, assign 12 as value to the 'mode' variable. Display the value of hour, minute, second, and AM/PM being set as well as the mode. Create another form of 'setTime()' method of void type that take only three parameters: (1) one int parameter named 'h', (2) one int parameter named 'm', and (3) one int parameter named 's'. In the body of the 2nd form of 'setTime()' method, assign 24 as value to the 'mode' variable. Display the value of hour, minute, and second being set as well as the mode.
Create Java program that has “supporting class” named “Point3D” which contains:
(a) three class variables, x, y, and z. (b) a default constructor that automatically set the point to be (0, 0, 0). (c) create another form of the default constructor that allows the user to set the three coordinates, such as (126, 44, 39) (d) create method named “distance” that calculates the distance between (0, 0, 0) and another point such as (31, 127, 86); and create another form of the “distance” method that calculates the distance between one “Point3D” object and another “Point3D” object.
In the man() method create three instances of the “Point3D” class: p1, p2, and p3. Let p1 be (0, 0, 0), p2 be (126, 44, 39), and p3 be (25, 219, 74). Ask the user to enter three integers, and then use them to create another Point3D object named “p4”. Calculate the distance between p1 and p2, p1 and (31, 127, 86), p2 and p3 as well as p3 and p4.