Write the definition of a class named SQRTException whose objects are created by specifying the original negative value that caused the problem in the first place: new SQRTException(originalArgument).

java

LANGUAGE: JAVA CHALLENGE: The argument to a square root method (sqrt) in general should not be negative. Write the definition of a class named SQRTException whose objects are created by specifying the original negative value that caused the problem in the first place: new SQRTException(originalArgument). The associated message for this Exception should be “Bad argument to…

Read More

Write some code that invokes the process method provided by the object associated with processor and arrange matters so that if any exception is thrown success to be set to false but otherwise it is set to true

java

LANGUAGE: Java CHALLENGE: Assume that success is a variable of type boolean that has been declared. Assume that processor refers to an object that provides a void method named process that takes no arguments. As it happens, the process method may throw one of several exceptions. Write some code that invokes the process method provided…

Read More

Define a class, Window, that implements the GUIComponent interface, and has the following members

java

LANGUAGE: Java CHALLENGE: Assume the existence of an interface, GUIComponent with the following methods: – open and close: no parameters, returns boolean – move and resize: accepts two integer parameters and returns void Define a class, Window, that implements the GUIComponent interface, and has the following members: – width, height, xPos, and yPos integer instance…

Read More

Come up with a recursive definition and use it to guide you to write a method definition for a double -valued method named harmonic that accepts an int parameters n and recursively calculates and returns the nth harmonic number.

java

LANGUAGE: Java CHALLENGE: The nth harmonic number is defined non-recursively as: 1 +1/2 + 1/3 + 1/4 + … + 1/n. Come up with a recursive definition and use it to guide you to write a method definition for a double -valued method named harmonic that accepts an int parameters n and recursively calculates and…

Read More

A palindrome is a string that reads the same forwards or backwards; for example dad, mom, deed (i.e., reversing a palindrome produces the same string )

java

LANGUAGE: Java CHALLENGE: A palindrome is a string that reads the same forwards or backwards; for example dad, mom, deed (i.e., reversing a palindrome produces the same string ). Write a recursive, boolean -valued method, isPalindrome that accepts a string and returns whether the string is a palindrome. A string , s, is a palindrome…

Read More

Assume the existence of a Window class with methods getWidth and getHeight, and a subclass TitledWindow, with a constructor accepts a string corresponding to the title of the window.

java

LANGUAGE: Java CHALLENGE: Assume the existence of a Window class with methods getWidth and getHeight, and a subclass TitledWindow, with a constructor accepts a string corresponding to the title of the window. Declare a variable , tWindow, of type TitledWindow variable , and initialize it to a TitledWindow object with a title of “My Title”.…

Read More

You are given two int variables j and k, an int array zipcodeList that has been declared and initialized, and an boolean variable duplicates.

java

LANGUAGE: Java CHALLENGE: You are given two int variables j and k, an int array zipcodeList that has been declared and initialized, and an boolean variable duplicates. Write some code that assigns true to duplicates if any two elements in the array have the same value , and that assigns false to duplicates otherwise. Use…

Read More

The method shown below, makeJunk generates compile-time error: “unreported exception java.io.IOException; must be caught or declared to be thrown”.

java

LANGUAGE: Java CHALLENGE: The method shown below, makeJunk generates compile-time error: “unreported exception java.io.IOException; must be caught or declared to be thrown”. Without changing the behavior (any part of the method body ) and without changing the number of arguments the function takes or its visibility, add the necessary code that will permit this code…

Read More

Write a static method, getBigWords, that gets a single String parameter and returns an array whose elements are the words in the parameter that contain more than 5 letters. (A word is defined as a contiguous sequence of letters.)

java

LANGUAGE: JAVA CHALLENGE: Write a static method, getBigWords, that gets a single String parameter and returns an array whose elements are the words in the parameter that contain more than 5 letters. (A word is defined as a contiguous sequence of letters.) EXAMPLE: So, if the String argument passed to the method was “There are…

Read More

Assume the existence of a Widget class that implements the Comparable interface and thus has a compareTo method that accepts an Object parameter and returns an int.

java

LANGUAGE: JAVA CHALLENGE: Assume the existence of a Widget class that implements the Comparable interface and thus has a compareTo method that accepts an Object parameter and returns an int. Write an efficient static method, getWidgetMatch, that has two parameters. The first parameter is a reference to a Widget object. The second parameter is a…

Read More