Write a custom java exception class named badarrayexception

Assignment Help JAVA Programming
Reference no: EM13940767

Write a custom Java exception class named BadArrayException that has two constructors:

- A default constructor with no arguments.

- A constructor taking a String parameter (the exception message) that must be passed to the parent Exception(String) constructor.

Write a Java class named ArrayUtils that contains the following public methods. The class must implement all the search and copy logic for these methods. It can not use array methods from the Java API.

1. public static int minValue(int[] list)

This static method searches its parameter array to locate the minimum value, and returns it. Do not use sorting to find the minimum value in the array. The array may contain any negative, 0, and/or positive values. If the array parameter is length 0, it must throw a BadArrayException with the message "Array is empty".

2. public static int[] copyRange(int[] list, int startIndex)

This static method copies the specified range of elements from the parameter array into a new array, and returns it. The initial index of the range (startIndex) must lie between 0 and list.length, inclusive. The range is [startIndex, Index of last element in the list]. If the startIndex parameter is less than 0 or greater than list.length, it must throw an ArrayIndexOutOfBounds exception with startIndex as the exception object parameter.

3. public static int indexOf(int[] list, int searchValue)

This static method searches its parameter array to locate the first occurrence of the parameter searchValue, and returns its index position if found, or -1 if not found. If the array parameter is length 0, it must return -1.

4. public static int lastIndexOf(int[] list, int searchValue)

This static method searches its parameter array to locate the last occurrence of the parameter searchValue, and returns its index position if found, or -1 if not found. If the array parameter is length 0, it must return -1.

If the array parameter is null, methods must throw a BadArrayException with the message "Array is null". These methods should not catch the BadArrayException they throw due to a null or empty array parameter. The exception is thrown back to the calling code to handle.

Test the implementation of BadArrayException and ArrayUtils classes with the help of attached ArrayUtilsDemo class.

Attachment:- ArrayUtilsDemo.txt

Reference no: EM13940767

Questions Cloud

Calculate the maximum speed in km : Show that the car is likely to skid rather than overturn if the speed is excessive and calculate the maximum speed in km h 1 at which it can travel round the curve. What will be the reactions of the inner and outer wheels at this speed?
To what extent does leadership influence the market : To what extent does leadership influence the market performance of companies?
Travelled the city selling carpets : Lou Krantz started his carpet business Regal Carpets in Oakland, California in 1995 with a brainwave idea, "Why do customers need to travel to out of town stores in order to buy their carpets - why doesn't the store come to them" he thought. So hi..
What is abercrombie and fitchs receivables turnover : Using the balances reported on the balance sheets, what is Abercrombie & Fitch's receivables turnover for the year ended February 3, 2007?
Write a custom java exception class named badarrayexception : A constructor taking a String parameter (the exception message) that must be passed to the parent Exception(String) constructor.
Describe each team member personality type : Write a 350- to 700-word paper in which includes the following: Describe each team member's personality type Describe the advantages of working with those with differing personality types
What is the maximum speed at which a car can travel : What is minimum radius of level curve that the wagon can negotiate at this speed without overturning?
Passive and active investment management strategies : Explain how unpredictable market conditions and economies play a role in passive and active investment management strategies.
Firm current business strategy based on outcomes : Evaluate the suitability of the firm's current business strategy based on the outcomes of your analysis (e.g., the identification of the firm's current strategy and the most significant factors affecting the firm's performance,

Reviews

Write a Review

JAVA Programming Questions & Answers

  A recently formed committee to deal with numerous

Scenario: You are a member of a recently formed committee to deal with numerous complaints against police and correction officers in your town and are asked to determine if there is merit to these allegations and develop a protocol to address the cur..

  Complete the method named countoutofrange

The element is greater than or equal to min AND less than or equal to max. The method should return the new array -

  What are the main differences between javabeans and applets

What are the main differences between JavaBeans and applets? How do I use an applet that resides on a remote machine?

  That uses a library database of books

Write a Java program that uses a library database of books and patron data, as described in Exercise R22.2. Patrons should be able to check out and return books

  Write a friend function that can examine the elements

Write a friend function that can examine the elements directly, or pop the stacks and save the popped elements so that the stacks can be restored.

  Write a java application to display the following gui

Write a Java application to display the following GUI. At this point you are only implementing the display. We are not ready to make the calculator actually do any calculations

  How to link different classes forms

How to link different classes forms. When a person clicks on A, B, or C the program will go to the addEmployee form or Punch In/Out form in Java.

  Program to track hourly employee arrival and departure time

THE JAVA SOURCE CODEA company hires you to write a program to track hourly employee arrival and departure times from work. In essence, you are tasked to make an online time clock. The time clock shall keep a history of an employee’s hours for a two-w..

  Write a program to convert kilograms into pounds

Write a program that prompts the user to enter the mass of a person in kilograms and outputs the equivalent weight in pounds. Output both the mass and the weight rounded to two decimal places.

  Process of buying a soda from a soda machine

Please write a Java Program those steps through the process of buying a soda from a Soda Machine.  You must interact with the consumer. Each Soda is one dollar.

  Write a java program that simulates a small cpu vm

Design and implement a program to simulate the operation of the SIMMAC based - dumps the contents of all registers and memory and then prints an "End of Job" message.

  Create your own unique java application

Create your own unique Java application to read all data from the file echoing the data to standard output. After all data has been read, display how many data were read. For example, if 10 integers were read, the application should display all 10..

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