Write a main method to test your max method

Assignment Help Programming Languages
Reference no: EM13787194

1. How does Java support the concept of encapsulation?

2. Describe the difference between an object and a class.

3. What is the difference between the contents of a Java variable of a primitive type and a Java variable of a class type?

4. (a) How is a 'static' class method different from a regular (non-static) class method?

(b) How is a 'static' variable in a class different from a regular (instance) variable in a class?

5. What does the Java keyword 'this' refer to?

6. What does the Java 'new' operator do?

7. When does a class require an 'equals' method to be written?

8. What is method "overriding"? Why would you override a method?

9. What advantages does inheritance provide in Java?

10. What is dynamic binding? What advantage does it provide?

11. How is it possible for two String objects with identical values not to be equal when compared with the == operator?

12. Why can a class variable of a base type be set to reference an object of a derived type, eg: Shape s = new Circle("Blue", 1.0);

13. How can the methods of a derived class access private instance variables of its base class?

14. The following try/catch has code to explicitly handle any IllegalArgumentException thrown. Show the modified code that will also catch any other type of exception that could be thrown by code called within the try block.

try
{
... methods called here ...
...
}
catch (IllegalArgumentException e)
{
... code to handle IllegalArgumentException ...
}

15. How is the caller's flow of control (sequence of statement execution) different when an exception is thrown from a method that it calls, vs. when the method returns normally?

The following questions are 20 points each. Paste your source code below each question, and example input and output. Do not include
the code required to test the methods, etc.

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: EM13787194

Questions Cloud

Theories of morality values and consequences : In your discussion, be sure to address the following: theories of morality, values, and consequences and judicial ethics and responsibility and implications of judicial misconduct
Part of the accounting process : Bookkeeping differs from accounting in that bookkeeping primarily involves which part of the accounting process?
Write a script that calculates the squares and cubes : Write a script that calculates the squares and cubes of the numbers from 1 to 6 and outputs HTML5 text that displays the resulting values in an HTML5 table format, as shown below.
Implement a hash structure for the contributor data : At this point, you decide to implement a Hash structure for the contributor data to prepare for searches. You will read the contributor information from a file provided; it is a comma delimited (CSV) file. As each record is read, create a Hash tab..
Write a main method to test your max method : 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:
Describe about international business ethics : International business ethics.
Describe about human resource planning : Human Resource Planning.
Differences between allopathic pharmacists and professional : differences between allopathic pharmacists and professional herbalists.
Write a program that uses a recursive algorithm to compute : Write a program that uses a recursive algorithm to compute the determinant of a maxtrix. It should read a matrix, print it out, and compute and print the determinant.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a program that takes three command-linearguments

Write a program that takes three command-linearguments number operator number and performs the required operation and prints the result on a single complete line in standard output.

  Write recursive function to take list head pointer

Write down the recursive function which takes list head pointer as parameter and returns largest value in linked list. Recall that xy = (xy/2)2 if y is even. Use this to write function which calculates xy.

  Design and implement class instance data for title of book

Design and implement a class called Book that contains instance data for the title, author, publisher, and copyright date. Define the Book constructor to accept and initialize this data.

  What is the break -even point for upgrades

What is break -even point for the upgrades? that is , what price would we require to charge for CPU (or disk -change only one) so result was the same cost per 1% increase for both?

  Write pseudocode for procedure construct-optimal-bst

Write pseudocode for procedure Construct-Optimal-BST (root) which, table root, outputs structure of the optimal bimary search tree.

  Smallest number using class-friend function and overloading

C++program which can neither be two integers or two floating point number and output smallest number using class, friend function and overloading.

  Create structure chart-flowchart to store taxpayer-s name

Create the structure chart, also a flowchart and pseudocode, for following problem. Suppose that each input record contains taxpayer's name.

  Write the program which approximates pi using series

Your problem is to write the program which approximates pi using above series. Allow the user to specify the number, n, of terms to be used.

  Perl programming

Create a list of messages that you think would be necessary during server-client and client-client interactions. Do not rely on the implicit acknowledgement of Transmission Control Protocol (TCP) but provide a mechanism for an explicit acknowledgm..

  Non-negative positions in positions

Write a predicate pick(+From, +Positions, -Picked) that unifies Picked with an atom consisting of the characters in From at the zero-based, non-negative positions in Positions.

  Write parameterized function to play the game

Your program cannot use file level variables or constants; your program cannot use global variables or constants. The functions that you write exchange data by means of return statements and value parameters and reference parameters

  Write down two ways to execute the shell script

Write down two ways you can execute the shell script when you don't have executive access permission for file containing the script?

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