Part-11 exceptions and exception handlinggt create a java

Assignment Help JAVA Programming
Reference no: EM13350361

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

Questions Cloud

Objective1 to give students practice in calling and writing : objective1. to give students practice in calling and writing their own functions.2. to give students practice in
You have to review vhhr and fill me in with suggestions : you have to review vhhr and fill me in with suggestions based on your views on the feedback and website based on
Question 1 companies and business planningfwpl acquired the : question 1 companies and business planningfwpl acquired the winery business in 1981 from francesca and angelo galli.
This paper is called a jury paper this is related to : this paper is called a jury paper. this is related to experimental psychology. this paper needs to be 8-10 pages
Part-11 exceptions and exception handlinggt create a java : part-11 exceptions and exception handlinggt create a java class called samearraysexception that extends the exception
1 linked listsin this problem you will write a class that : 1 linked listsin this problem you will write a class that implements an ordered list of strings. your class will able
Going live is not the end of the erp journeythe benefits : going live is not the end of the erp journeythe benefits companies expect from their erp systems often occur over a
Part-1inheritance write code using eclipse and output : part-1inheritance write code using eclipse and output screenimplement a subclass square that extends the rectangle
Write the code with comment and output resultinterface and : write the code with comment and output resultinterface and polymorphismimplement a class quiz that implements the

Reviews

Write a Review

JAVA Programming Questions & Answers

  Check wether two appointments overlap

in a scheduling program, we want to check wether two appointments overlap. For simplicity, appointments start at a full hour,

  Design a course registration system

Create an application which represents a simplified course registration system using ArrayLists and HashMaps.

  A this adds storage of the maindata as an external random

a. this adds storage of the maindata as an external random access file with id as key to allow listall and query

  Define render a model scene in java

Render a Model Scene in Java - Imagine you are prototyping animation for a Jurassic Park Movie

  Create a file that contains your favorite movie quote

Create a file that contains your favorite movie quote. Use a text editor such as Notepad, and save the file as quote.txt. Copy the file contents,

  The program should ask the user to enter the student'' answer

Your program should store these correct answers in an array. (Store each question's correct answer in an element of a string array.) the program should ask the user to enter the student's answers for each of the 20 questions, which should be stored i..

  Write a restful web service demo example using spring mvc

Write a restful web service demo example using spring mvc

  Develop a java program

Develop a Java program which, given the width, length and depth (in metres), of a swimming pool, determines and outputs.

  Give an implementation of the queue adt using an array

Give an implementation of the Deque ADT using an array, so that each of the update methods run in O(1) time. Program has to be written in Java.

  Tic-tac-toe game assignment

Assignment 1(Java): Tic-Tac-Toe Game (Assignment 1 is attached),  Use the concepts and scenario from Assignment 1 and continue with the tic-tac-toe game design and development.  Section 1: Java Program File, The following method, numPaths, is suppos..

  Prepare address book java application

Prepare an application that reads the contents of your address book file and prepare a user guide that includes a description of the functionality of your overall address book system.

  T an array using insertion sort and track the number of swap

How to sort an array using insertion sort and track teh number of swaps during the sorting

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