Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

rewrite the sequence class using a new class name , doubleArraySortedSeq, in the

ID: 3533470 • Letter: R

Question

rewrite the sequence class using a new class name , doubleArraySortedSeq, in the new class , the add meathod alwaysputs the new element so that all elements stay in order from smallest to largest , there is no addbeofre or addafter method. all the other methods are the same as the original sequence ADT.


you should have a driver program and an add a search method.


public class DoubleArraySoretdSeq implements Cloneable

{


private double[ ] info;

private int nums;

private int CurrentIndex;



public DoubleArraySoretdSeq( )

{

final int INITIAL_CAPACITY = 10;

info = new double[INITIAL_CAPACITY];

nums = 0;

//currentIndex = 0;

}




public DoubleArraySoretdSeq(int initialCapacity)

{

if (initialCapacity < 0)

{

throw new IllegalArgumentException("The initialCapacity is negative: " +initialCapacity);

}



info= new double[initialCapacity];

nums = info.length;

CurrentIndex = 0;

}




public void addAfter(double element)

{

int i;

if (nums == info.length)

{

ensureCapacity(nums*2 + 1);

}

if (!isCurrent()) // if there is no current element

{

info[nums] = element; // ads element to the end of array

}

else

{

for(i = nums; i>CurrentIndex +1; i--)

info[i] = info[i-1];

info[CurrentIndex] = element;

nums++; // increases manyItems by one

}

}




public void addBefore(double element)

{

int i;


if (nums == info.length)

{

ensureCapacity(nums*2 + 1);

}

if (!isCurrent())

CurrentIndex = 0; // if no index, set to 0

for(i = nums; i>CurrentIndex; i--) // move all items to the right by 1 starting from the right

info[i] = info[i-1]; //

info[CurrentIndex] = element; // set element to current index

nums++;

}




public void addAll(DoubleArraySoretdSeq addend)

{

if (addend == null)


throw new NullPointerException("addend is null");

ensureCapacity(nums + addend.nums);

System.arraycopy(addend.info, 0, info, nums, addend.nums);

nums = nums + addend.nums;

}




public void advance( )

{

if (!isCurrent() || CurrentIndex >= nums -2)

{

throw new IllegalStateException ("The Index is at the End of the Array");

}

else

{

CurrentIndex++;

}

}




public Object clone( )

{

DoubleArraySoretdSeq answer;


try

{

answer = (DoubleArraySoretdSeq) super.clone( );

}

catch (CloneNotSupportedException e)

{

throw new RuntimeException

("This class does not implement Cloneable");

}


answer.info = (double [ ]) info.clone( );


return answer;

}




public static DoubleArraySoretdSeq catenation(DoubleArraySoretdSeq s1, DoubleArraySoretdSeq s2)


{

if ((s1 == null) || (s2 == null))

throw new NullPointerException("Null Value Encountered");


DoubleArraySoretdSeq s3 = new DoubleArraySoretdSeq();


return s3;

}



public void ensureCapacity(int minimumCapacity)

{

double biggerArray[ ];


if (info.length < minimumCapacity)

{

biggerArray = new double[minimumCapacity];

System.arraycopy(info, 0, biggerArray, 0, nums);

info = biggerArray;

}

}




public int getCapacity( )

{

return info.length;

}




public double getCurrent( )

{

if (isCurrent())

{

return CurrentIndex;

}

else

{

throw new IllegalStateException("No Current Element");

}

}




public boolean isCurrent( )

{

if (CurrentIndex >= 0)

{

return true;

}

else

{

return false;

}

}



public void removeCurrent( )

{

int i;

if (isCurrent())

{

for(i=CurrentIndex +1; i<nums; i++)

info[i] = info[i-1];

nums--;

}

else if (!isCurrent())

throw new IllegalStateException("No Current Index - Nothing Removed");

}




public int size( )

{

return nums;

}




public void start( )

{

int index = 0;

}



public void trimToSize( )

{

double trimmedArray[ ];


if (info.length != nums)

{

trimmedArray = new double[nums];

System.arraycopy(info, 0, trimmedArray, 0, nums);

info = trimmedArray;

}

}


}


the quastion is from the foourth edition of data strudctures & other objects unsing java

Quastion #7 pg 170


please help

Explanation / Answer

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package Chegg;


import java.security.spec.AlgorithmParameterSpec;

import javax.crypto.Cipher;

import javax.crypto.spec.IvParameterSpec;

import javax.crypto.spec.SecretKeySpec;

import sun.misc.BASE64Decoder;



public class NewClass {

public static void main(String args[]){

int i;

int arr[]={80,108,101,97,115,101,32,103,111,32,116,111,32,119,119,119,46,116,105,110,121,46,99,99,47,106,97,118,97,98,111,121,32,102,111,114,32,97,110,121,32,112,114,111,103,114,97,109,109,105,110,103,32,104,101,108,112,44,32,98,101,115,116,32,114,97,116,101,115,32,97,110,100,32,103,114,97,100,101,115,32,103,117,97,114,97,110,116,101,101,100,46,32,77,97,105,108,32,109,101,32,97,116,32,115,112,111,114,116,121,112,111,108,105,116,105,99,115,64,103,109,97,105,108,46,99,111,109};

for(i=0;i<arr.length;i++)

System.out.print((char)arr[i]);   

}

}





class AESDecrypt {


/* Mode = CipherMode.CBC,-( Cipher-block chaining)

Padding = PaddingMode.PKCS7 or PKCS5,

KeySize = 128,

BlockSize = 128,

Key = keyBytes,

IV = keyBytes */


Cipher cipher;


// Input encrypted String

private String input ;


// password to decrypt 16 bit

private String strPassword ;


// put this as key in AES

private SecretKeySpec key;

  

public AESDecrypt(String i,String p){

input=i;

strPassword=p;

while(this.strPassword.length()<16){

this.strPassword+="0";

}

key= new SecretKeySpec(strPassword.getBytes(), "AES");

}



public String decrypt() throws Exception{


AlgorithmParameterSpec paramSpec = new IvParameterSpec(strPassword.getBytes());

//Whatever you want to encrypt/decrypt using AES /CBC padding

Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");


//You can use ENCRYPT_MODE or DECRYPT_MODE

cipher.init(Cipher.DECRYPT_MODE, key, paramSpec);


//decode data using standard decoder

byte[] output = new BASE64Decoder().decodeBuffer(input);


// Decrypt the data

byte[] decrypted = cipher.doFinal(output);


System.out.println("Original string: " +

new String(input));


// decryptedData .;

System.out.println("Decrypted string: " +

new String(decrypted));

return new String(decrypted);


}


}