Create a java class called samearraysexception

Assignment Help JAVA Programming
Reference no: EM134316

Part-1

1: Exceptions and Exception Handling

> Create a Java class called SameArraysException that extends the Exception class. Your class must have a public constructor that has one input argument, a String.

> Create a Java class called SameArraysSizeMismatchException that extends your SameArraysException class. Your class must have a public constructor that has one input argument, a String.

> Complete the code in the SameArrays class that is provided. Do not change any actual lines of code in the method in the class. Instead, you must add code (either a single line or a block of code) in four places (each denoted by the \: : : " shown below). You can add additional catch blocks if you wish. In particular, you need to complete the following method in the class:

public static boolean sameArrays(Object[] arrayOne, Object[] arrayTwo)
throws SameArraysSizeMismatchException, SameArraysException
{
boolean answer = true;
try{
int n = Math.max(arrayOne.length, arrayTwo.length);
for(int i=0; i<n; i+=1){
if( !arrayOne[i].equals(arrayTwo[i] )
answer = false;
}
}catch(...){ <--- Replace the four "..." with your own code
... <--- Do not change anything else in the method/class
}catch(...){ <---
... <--- You may add addition catch blocks though
}
return answer;
}

You are not allowed to change this method except for replacing each \..." with appropriate code. (Again, you may add additional catch blocks to di erentiate di erent exception/erros if you wish.) Your task is to catch exceptions or errors (that might be thrown when running the method) and deal with them appropriately. When a certain exception is thrown (by the JVM) as a consequence of the arrays being di erent lengths, you must catch it and then throw a SameArraysSizeMismatchException object. Any other exception or error that is thrown (by the JVM) must be caught and dealt with (by throwing a SameArraysException object).

The message in your SameArraysException objects (the input String to the constructor) should be concise and descriptive of the problems that occurred. The message in your SameArraysSizeMismatchException objects should be one of two strings: \ rst array is longer than the second" or \second array is longer than the rst", depending on which array is actually longer. Static constants are provided for the actual strings to use.

Your SameArrays class should have no other methods (and no other attributes).

Part-2

Recursion I

> Create a Java class called Pals. The class should have the following method:

public static boolean isPalindrome(String word)
// Input : word is a non-null string
// Output: true if the input string is a palindrome*
// false otherwise
//
// * A palindrome is a sequence of characters that is the
// same when read forward and backwards.
//
// * For this question we will ignore whitespace
// when determining if a string is a palindrome or not.
//
// Examples: Pals.isPalindrome("a") => true
// Pals.isPalindrome("cat") => false
// Pals.isPalindrome("w o w") => true
// Pals.isPalindrome(" a ") => true
// Pals.isPalindrome("mom!") => false
Your isPalindrome() method must use recursion. You will receive zero correctness marks if you do not use recursion in this problem.

Part-3
> Create a Java class called DNA. The class should have two methods:

public static String compress(String dna)
// input: a non-null string consisting only of the letters G,A,T and C.
// (this is the long form representation)
// (they may be upper, lower, or mixed case)
// output: a string that represents a condensed version of the input string.
// o) Each occurrence of a single letter (its neighbours are different)
// is copied to the new string.
// o) Each occurrence of a sequence of a single letter that
// is repeated two or more times is replaced by
// that letter and number of occurrences in the new string
// All letters in the output should be capitalized.
// Example: DNA.compress("GGCcCTtttTT") => "G2C3T6"
// DNA.compress("Cat") => "CAT"
// DNA.compress("") => ""
public static String expand(String dna)
// input: a non-null string that represents a compressed sequence of DNA
// (the same form as the output of compress() except mixed-case is allowed)
// (it consists only of G,A,T,C and the digits 0,1,..,9)
// output: the long form sequence of DNA that the input represented.
// All letters in the output should be capitalized.
// Examples: DNA.expand("G2T5") => "GGTTTTT"
// DNA.expand("cat") => "CAT"
// DNA.expand("") => ""

For this question you will need to be able to access individual elements of a string, concatenate strings, convert (sub)strings to numbers and convert numbers to strings.

Your compress() and expand() methods must use recursion1

. You will receive zero
correctness marks if you do not use recursion in this problem. We will only test your methods with valid input.

You may create helper recursive methods if you nd the single input methods given are too restrictive. For example, you might have private compressHelper() method that your compress() method calls. In this case compress would not be recursive, but compressHelper would. This is OK if you approach it this way. We will only call compress and expand when testing so make sure they call your helper methods.

Part-4

Exceptions and Exception Handling II

This is a bonus problem and is not required.

Now let's assume that we do not honour the preconditions for the methods in the DNA class from the previous problem.

> Create three Java classes: MoreDNA, DNABadInput, and TestMoreDNA.

The DNABadInput class must extend the Exception class. It must have a constructor with a single (String) input argument (just as in Problem 1). The exception should be thrown when there is bad input into either of the methods in MoreDNA.

The MoreDNA class should be almost identical to the DNA class from the previous problem except that both methods must throw a DNAException object when their input is bad. The message in the exception should indicate which method threw the exception and what sort of bad data was involved. The message should be a simple string concatenation of the name of the method with one of the 3 kinds of bad input data (these 3 strings are given in the skeleton code provided).

The TestMoreDNA class should be a testing class for your MoreDNA class. This class should be a runnable program. It should have 5 tests for each method in MoreDNA. For each method, 3 tests should be for good data and 2 for bad data (the tests need to be di erent). You do
not need to document your testing program. Be sure that the outout of the program is easy to follow/understand (simple is good here). Your testing program should not crash when a exception is thrown when testing.

Reference no: EM134316

Questions Cloud

Give students practice in writing and calling their function : To give students practice in writing and calling their own functions. To give students practice in implementing and planning complex programs.
You have to review vhhr site : You have to review vhhr and fill me in with suggestions based on your views on the feedback and website based on general comments on trip advisors, orbits and some other website comments on other sites.
Differences between a company and a partnership : What are some of the key differences between a company and a partnership What decisions must be made, and what steps have to be taken, to incorporate the new company?
Write a paper on experimental psychology : Write a paper on Experimental psychology. This paper is called a Jury paper
Create a java class called samearraysexception : Create a Java class called SameArraysException that extends the Exception class.
Write a class that implements an ordered list of strings : In this problem you will write a class that implements an ordered list of Strings.
What are the potential benefits of each stage : Why an ERP systems journey may never end What are the possible stages in an ERP systems journey? What are the potential benefits of each stage?
Determine the decision of java : Determine the decision of Java as the platform to develop this program. Identify the Java-based technologies utilized in this project and analyze each of them. Then, provide discussion on the purpose of each of the Java-based technologies utiliz..
Implement a class quiz : Implement a class Quiz that implements the Measurable interface.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a program that shows the current time and date

Write a program that shows the current time and date

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Implement the lexical and syntactic analysis

Implement the lexical and syntactic analysis of Minifun programming language.

  Compute area and perimeter of a polygon

Create a project that would let a user compute area and perimeter of a polygon

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Record managing system application

Build a student record managing system application

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Enterprise java beans (ejb) in software development

Enterprise Java Beans (EJB) in software development, EJB technology, EJB application, Stateless Session Beans (SLSB), Stateful Session Beans (SFSB), Message Driven Bean (MDB), Entity Bean

  Implement avl tree

Implement AVL trees that allows both iterative traversal and recursive traversal.

  Rock-paper-scissors :- java problem

Design decision marks are based on how you implemented our programs/classes.

  Design and implement a small and simple email server

Design and implement a small and simple email server using the concept of web based information system (WBIS).

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