Java | JSP | JSF Answers

Questions: 4 418

Answers by our Experts: 3 943

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 & Filtering

Create a static method

public static int pow(int base, int exp)

that returns the power value of base raised to its exponent. Use this method in a program that first asks for a base value and an exponent value, calls pow() and then prints the result.


Sample output:

Enter the base: 2

Enter the exponent: 3

The power value is 8




Write a program that uses a static method called printMessage that takes a string and an integer as parameters. The string and integer parameters represent a person’s name and age. When printMessage is called with arguments “Joan” and 18, the method prints “Joan, you are 18 years old”.


Sample output:

Enter your name: Joan

Enter your age: 18

Joan, you are 18 years old




Create a program that will calculate a student's total payment fee after a scholarship has been applied. Scholarship.java will contain two methods: setGrade() and getScholarship(). The setGrade() will process the scholarship application, and will set new amount to be paid, while getScholarship() will only return the new amount after being called.

GPAs ranging from 1.76 to 5.00 will not be eligible for a scholarship and must pay the full tuition. GPAs ranging from 1.46 to 1.75 will receive a partial scholarship. GPAs ranging from 1.00 to 1.45 will receive a full scholarship. Out-of-range GPAs are invalid.

In the main class (SurnameScholarship.java), the user will be asked to enter his/her GPA, tuition fee, and miscellaneous fee.


Create a java program which allows the user to enter two values (Using JOptionPane) to be divided. The program catches an exception if either of the entered values is not an integer.

 

Declare three integers—two to be input by the user and a third to hold the result after dividing the first two. The numerator and denominator variables must be assigned starting values because their values will be entered within a try block. Also declare an input String to hold the return value of the JOptionPane showInputDialog() method.int numerator = 0, denominator = 0, result; String display;

 

 

 

Add a try block that prompts the user for two values, converts each entered String to an integer, and divides the values, producing result(Cast the result to a double).

 

Add a catch block that catches an Arithmetic Exception object if division by 0 is attempted. If this block executes, display an error message, and force result to 0.


The program shall:

• generate a random number from 1 to 50 for a player to guess;

• display a message that indicates whether the player's guess is correct, too low, or too high; • prompt the user to keep on guessing until the correct value is entered

4. Create a try-catch structure that will handle two (2) exceptions. These are when the user inputs the following:

• a number that is out of range (1 - 50) a letter or any non-numeric character

5. Prompt the user so that he can guess again if an exception is thrown.

6. Display the number of total guesses.

Note: An invalid input (when an exception is thrown) is not considered a valid guess or attempt. 


Write a static method called dollarToPeso that takes a dollar amount as parameter and returns its equivalent in pesos. Assume that the conversion rate is 1 dollar = 48.45 pesos. Use this method in the program.



Sample output:


Enter dollar amount: 50


$ 50 = P 2,422.5



Write a Java program to produce the following GUI calculator. Use exception-handling to catch any exceptions (divide by zero, or non-integer input). Display any errors in a JOptionPane message dialogue box.


Write a program that meets the following requirements:

Create an array with 10 String elements.

Create a Gui with a text field to enter an array index value and another text field to display the array element value.

Create Show Element button to cause the array element to be displayed. If the specified index is out of bounds, display an appropriate message using a JOptionpane method.


Write a Python program which iterates the integers from 1 to 50. For multiples of two print “even”, for multiples of three print “multipleOf3”, and for numbers which are multiples of both two and three print “evenmultipleOf3”, otherwise print the number. Hint: Use a loop for this problem.

Sample Output:

 

Sample Input

Sample Output

1

1

2

even

3

multipleOf3

4

even

5

5

6

evenmultipleOf3

14

even

15

multipleOf3

   Sample Input and Output

​​


In physics, an object that is in motion is said to have kinetic energy. The following formula can be used to determine a moving object’s kinetic energy:

KE=1/2mv2

The variables in the formula are as follows: KE is the kinetic energy, m is the object’s mass in kilograms, and v is the object’s velocity in meters per second.

 

1. Write a function named kinetic_energy that accepts an object’s mass (in kilograms) and velocity (in meters per second) as arguments. The function should return the amount of kinetic energy that the object has. 

 

2. Write a statement that calls the kinetic_energy function to get and display the kinetic energy of an object with the mass of 5 kilograms and velocity of 20 meters per second

 


LATEST TUTORIALS
APPROVED BY CLIENTS