Ask Programming Language Expert

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

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91357299
  • Price:- $35

Guranteed 24 Hours Delivery, In Price:- $35

Have any Question?


Related Questions in Programming Language

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As