Write a static method to check the string

Assignment Help JAVA Programming
Reference no: EM13941076

P1. Write a static method that checks if a String represents a valid integer value and returns true if valid, or false if not. For example, "123", "-45", and "0" are valid integers, but "x7" and "3.14" are not. Use java.lang.Integer.parseInt() to perform the actual validity checking inside your method. Your method should also return false if the parameter String is null or empty.

It should NOT throw any exceptions back to the caller (but may use exceptions internally).

Use the following prototype for your method:

public static boolean isValidInt(String testIntval)

Show example output for the following values entered:
"42"
"-123"
"12-34"
"10.5"
"x7"
"" (length 0 string)
null (pass a Java null reference in a hardcoded call to isValidInt)

--------------------------------------------------------------------
P2. Write a Java method that returns the largest value passed to it.
Use the following prototype:

public static int max(int val1, int val2, int val3) {
// return the largest of the three values...
}

For example, the following call of your method sets 'n' to 30:

int n = max(20, 30, 10);

Note that any three values can be passed to this method.

The following would also set 'n' to 30:

int n = max(30, 30, 10);

Write a main() method to test your max method. It should input three values, call your max method, and then print the three values and returned max value as output, eg:

Input values: 30 20 10 - max value is 30

The max() method cannot read any input values, nor print any output values. All input and printing is done by the main() method that calls max().

Paste in both your source code for your max() method, and the runtime output showing the parameter values and returned maximum value for the following sample input values:

a) 30, 30, 30
b) 10, -10, 20
c) 40, 60, 50
d) 90, 70, 80
e) 50, 50, 25
f) 50, 50, 75
g) 200, 100, 200
h) 200, 400, 200
i) 300, 500, 500
j) 700, 500, 500

Reference no: EM13941076

Questions Cloud

Marketing strategies for your new product : Using Boston Consulting Group Matrix (BCG), outline, appropriate marketing strategies for your new product at each stage of its life-cycle.
Write ethics essay on the prison system : Write a 6 page ethics essay on the Prison system
Importance to consumer behaviour and marketing : Discuss the concept of perceived value and its importance to consumer behaviour and marketing.
Culture and leadership of the organisation : A critical review of the culture and leadership of the organisation. You should review these factors and consider their impact on the strategic decisions made. Your review may include consideration of the history of the organisation, its mission a..
Write a static method to check the string : The max() method cannot read any input values, nor print any output values. All input and printing is done by the main() method that calls max().
Where does liability lie for the managed care organization : Discuss the options, if any, MCO or PPO plan members have when denied coverage for medically necessary care.
Does junes camera shop appear to have grown in size : Does June's Camera Shop appear to have grown in size during the past two years? How long should it take June's Camera Shop to pay back the $125,000?
Market entry strategies that ikea adopt : Describe the market entry strategies that IKEA adopt in China and Japan respectively.
Requirements for packaging and stowage : Determine packaging and stowage requirements (3.1, 3.2, 3.3, 3.4) Analyse and determine the best options and requirements for packaging and stowage of your product.Research and document/ record the suitability and availability of the packaging and..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Implementation of tru file system

Design and implement TFS. It is a file system that can be used on a standalone machine. There are several simplifying assumptions such as a single application is accessing the file system at any given time.

  Discuss the pros and cons of compilers and interpreter

Pick a problematic situation that you think a Java program can solve or make easier.

  Write a class named test scores

Write a class named TestScores.The class constructor should accept an array of test scores as an argument.The class should have a method that returns the average of the test scores.

  Write program in java to calculate interest

Write a program in java to do the following : the following data is stored for each customer in the bank: account number,average balance and number of transaction for each customer it is required to calculate the interest earn

  Write a server for multiple clients

Write a server for multiple clients. The client sends loan information (annual interest rate, number of years, and loan amount) to the server. The server computes monthly payment and total payment and sends them back to the client.

  Carry out additions and subtraction

You are to design a Java application to carry out additions and subtractions for numbers of any length. A number is represented as an object which includes a sign and two strings for the whole and decimal parts of the number.

  Write a java program and pseudocode to read a number

Write a java program and pseudocode to read a number up to 15 digits long or a date (dd/mm/yyyy). The program should distinguish numbers from input date, and prints them in alphabetic spelling form

  Write the code and output result1 real cash register can

write the code and output result.1. real cash register can handle both bills and coins. design a single class that

  Implement a set as a new class that is derived

A set is like a bag, except that a set does not allow multiple copies of any element. If you try to insert a new copy of an item that is already present in a set, then the set simply remains unchanged.

  Create a login form

In this week's lab, we will create a login form, validate a user based on their login name and password, and allow them to access the system or not

  Determine the percentage of vowels

Create a Java program that asks the user to input a sentence in any language, counts the number of vowels in the sentence, divides it by the total number of characters in the sentence.

  Implement an intrusion detection system in java

You are to implement an intrusion detection system in java. Calculate a threshold for detecting an intrusion. The threshold is 2*(Sums of weights).

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd