Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

P1. Make a static method that checks if a String represents a valid integer value and returns true if valid, or false if not. For

P1. Make 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. Make 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);

Compose 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions