Trusted by Students Everywhere
Why Choose Us?
0% AI Guarantee

Human-written only.

24/7 Support

Anytime, anywhere.

Plagiarism Free

100% Original.

Expert Tutors

Masters & PhDs.

100% Confidential

Your privacy matters.

On-Time Delivery

Never miss a deadline.

program using a console application name it "DragonKiller"

Computer Science Feb 25, 2021

program using a console application name it "DragonKiller". The program should ask the user to enter is name and surname.

Use the emptySpace () method to remove space between the name and the surname. Count the number of characters within the newly created string (nameSurname).

The total number of characters (Name and Surname) should be the size of your arrayDragon (type integer). Populate your arrayDragon with a series of random number between 10 and 50.

Display all arrayDragon elements and they are corresponding indexes before executing the insertionSort method.

Allow the user to enter a value from the arrayDragon element to search for.

* Loop through the array until you find the value (Use the binarySearch to locate the value with in your array) and kill that value from the arrayDragon. By replacing the value findDragon with a Zero (0)

* Print out arrayDragon with the killed element.

 

Expert Solution

Answer:
import java.util.*;
public class DragonKiller {
    
    public static int emptySpace(String name){
        //replacing the " " with "" to remove empty space
        name=name.replace(" ","");
        
        //return the length of the name
        return name.length();
    }
    
    //method for insertion sort
    public static int[] insertionSort(int[] array){
        int n = array.length;  
        for (int j = 1; j < n; j++) {  
            int key = array[j];  
            int i = j-1;  
            while ( (i > -1) && ( array [i] > key ) ) {  
                array [i+1] = array [i];  
                i--;  
            }  
            array[i+1] = key;  
        }
        return array;
    }
    
    //method to find the element you want to search for
    public static int findDragon(int[] arr, int key){
        int first=0;
        int last=arr.length-1;
        int mid = (first + last)/2;  
        while( first <= last ){  
            if ( arr[mid] < key ){  
                first = mid + 1;     
            }else if ( arr[mid] == key ){  
                return mid;
            }else{  
                last = mid - 1;  
            } 
            
            mid = (first + last)/2;  
        }
        
        return -1;
    }
    
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        System.out.print("Enter your name(name and surname):");
        String name=sc.nextLine();
        
        //ge the size of the name string
        int size = emptySpace(name);
        
        int arrayDragon[]= new int[size];
        int low = 10;
        int high = 50;
        Random r = new Random();
        for(int i=0;i
Archived Solution
Unlocked Solution

You have full access to this solution. To save a copy with all formatting and attachments, use the button below.

Already a member? Sign In
Important Note: This solution is from our archive and has been purchased by others. Submitting it as-is may trigger plagiarism detection. Use it for reference only.

For ready-to-submit work, please order a fresh solution below.

Or get 100% fresh solution
Get Custom Quote
Secure Payment