Question

duction For this assignment, you are to develop a SmartString class that supports inserting into a string, deleting a substring from a string, and an undo method. For example, say you have a starting Smart String Now, insert to the end of this String I am doing great! such that you now have Next, after I, delete the space and the a so you have Now, insert an apostrophe to get Now undo twice so you end up with the Smart String Hello, how are you today? Hello, how are you today? I am doing great! Hello, how are you today? Im doing great! Hello, how are you today? Im doing great! Hello, how are you today? I am doing great! ons: rogram Ins Download SmartStringADT.java, SmartStringDriver.java, InvalidSmartStringException.java, and SmartStringTest.java from Blackboard. These four files are to help with the SmartString class you are to write for program 2 (you may add additional classes - see below - to be used in your SmartString, but this class is the minimum) SmartStringADT.java Your SmartString class must implement this ADT and therefore implement the following methods: public interface SmartStringADT public void insert (int pos, String sstring); public void delete (int pos, int count); public void undo ); public String toString ); Note: the last method, toString, should simply return the SmartString and nothing else! SmartStringDriver.java A driver class that lve provided for you to run quick tests on your SmartString class. InvalidSmartStringException.java The Exception that should be thrown should you encounter an invalid Smart String action such as trying to delete on an empty string

in JAVA -- need to use an arraystack for this and can only manipulate smartstring.java aka the one that says :

              public class SmartString implements SmartStringADT at the beginning

//for SmartStringTest.java:

import static org.junit.Assert.*;

import org.junit.Test;

public class SmartStringTest {
   //Test insert method
   @Test
   public void testinsert1() {
       SmartString evaluator = new SmartString();
       evaluator.insert(0, "Hello");
       evaluator.insert(4, ", how are you?");
       assertEquals("Hello, how are you?", evaluator.toString());
   }


   @Test
   public void testinsert3() {
       SmartString evaluator = new SmartString("Hello, Goodbye");
       assertEquals("Hello, Goodbye", evaluator.toString());

   }  
  
  
   @Test(expected = InvalidSmartStringException.class)
   public void testinsert5() {
       SmartString evaluator = new SmartString("Hi");
       evaluator.insert(-1, ", how are you?");
       fail("Invalid Smart String action not detected");
   }
  
   // Test delete method

   @Test
   public void testdelete4() {
       SmartString evaluator = new SmartString("Hello, Goodbye");
       evaluator.delete(5, 20);
       assertEquals("Hello", evaluator.toString());

   }  
  
   @Test
   public void testdelete6() {
       SmartString evaluator = new SmartString("Hello, Goodbye");
       evaluator.delete(0, 20);
       assertEquals("", evaluator.toString());

   }  
   @Test(expected = InvalidSmartStringException.class)
   public void testdelete7() {
       SmartString evaluator = new SmartString("Hello, Goodbye");
       evaluator.delete(20, 25);
       fail("Invalid Smart String action not detected");

   }  
  
   @Test(expected = InvalidSmartStringException.class)
   public void testdelete10() {
       SmartString evaluator = new SmartString("Good morning.");
       evaluator.delete(-1, 1);
       fail("Invalid Smart String action not detected");
   }  

   //Test insert and delete
  
   public void testinsertAndDelete2() {
       SmartString evaluator = new SmartString();
       evaluator.insert(0, "Hello, how are you?");
       evaluator.delete(5, 14);
       assertEquals("Hello", evaluator.toString());
   }  
  
   //Test undo methods

   @Test
   public void undo3() {
       SmartString evaluator = new SmartString("Hello, Goodbye");
       evaluator.delete(7, 7);
       evaluator.insert(6, "how are you?");
       evaluator.insert(18, " I am great!");
       evaluator.delete(21,2);
       evaluator.insert(20, "'");
       evaluator.undo();
       evaluator.undo();
       evaluator.undo();
       assertEquals("Hello, how are you?", evaluator.toString());
   }  
  

   @Test(expected = InvalidSmartStringException.class)
   public void undo5() {
       SmartString evaluator = new SmartString();
       evaluator.undo();
       fail("Invalid Smart String action not detected");
   }

}

//next class- SmartStringDriver.java

import java.util.InputMismatchException;
import java.util.Scanner;

public class SmartStringDriver {

   public static void main(String[] args) {
       //Declare variables and objects
       Scanner scan = new Scanner(System.in);
       int action = 1, start = 0, count = 0;
       String menu = "\n(1) insert\n(2) delete\n(3) Undo\n(4) Quit";
       SmartString str;
       String insertS = "";


       System.out.println("Enter your initial Smart String:");
       str = new SmartString(scan.nextLine());
       try{
          do{
               //Prompt for an action - Insert, Delete, Undo, Quit
               System.out.println("Your smart string is: \n\t" + str + " \n\t(indexing from 0 to " + (str.toString().length()-1) + " - length of " + str.toString().length() + ")");
               System.out.println(menu);
               System.out.println("Enter an action");
              
               action = scan.nextInt();
               scan.nextLine();
              
               //Determine which action and prompt for necessary input
               switch (action) {
               case 1:
                   System.out.println("Enter the position (begin counting at 0) of the letter after which to insert " + insertS);
                   start = scan.nextInt();
                   scan.nextLine();
                  
                   System.out.println("Enter the string to insert");
                   insertS = scan.nextLine();

                   //Invoke SmartString insert method
                   str.insert(start, insertS);
                   break;
               case 2:
                   System.out.println("Enter the position (begin counting at 0) of the first letter to delete");
                   start = scan.nextInt();              
                  
                   System.out.println("Enter the number of letters to delete (count)");
                   count = scan.nextInt();
                  
                   //Invoke SmartString delete method
                   str.delete(start, count);
                   break;
                  
               case 3:
                   //Invoke SmartString undo method
                   str.undo();              
                   break;
               }

          }while (action != 4);
       }
       catch(InputMismatchException e) {
           System.out.println("Entry must be numeric!");
       }
       System.out.println("\n Your final Smart String is " + str);

   }

}

//next class - SmartStringException


public class InvalidSmartStringException extends RuntimeException {
    public InvalidSmartStringException()
    {
        super("Unable to change Smart String!!\n");
    }
}

//next class -- SmartString.java

public class SmartString<T> implements SmartStringADT<T>              
   {          
       ArrayStack<Changes> stack1 = new ArrayStack<Changes>();      
        StringBuilder string;           
                  
        public SmartString(String s){          
           string = new StringBuilder(s);      
        }          
              
       "public void insert(int pos, String sstring){"      
              
           "string.insert(pos, sstring);"  
           "Changes n = new Changes(pos, pos+sstring.length(), string,""ins"");"  
           stack1.push(n);  
       }      
              
       "public void delete(int pos, int count){"      
           "StringBuilder temp = new StringBuilder(string.substring(pos, pos+count));"  
           "string.delete(pos, pos + count);"  
           "Changes n = new Changes(pos, count, temp,""del"");"  
           stack1.push(n);  
       }      
              
       public String toString(){      
           return string.toString();  
       }      
              
       public void undo() {      
           Changes n = astack.pop();  
           String type = n.getType();  
              
           "if(type.equals(""ins"")){"  
               "string.delete(n.getBegin(), n.getEnd());"
           }  
           else{  
               "string.insert(n.getBegin(), n.getStr());"
           }  
       }      
   }           

//last class - SmartStringADT.java


public interface SmartStringADT {
   public void insert(int pos, String sstring);
   public void delete(int pos, int count);
   public void undo();
   public String toString();
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • testcase01.c

    #include <stdio.h>
    #include <string.h>
    #include "SmartArray.h"
    
    int main(void)
    {
            int i; char buffer[32];
    
            SmartArray *smarty1 = createSmartArray(-1);
            SmartArray *smarty2 = createSmartArray(-1);
    
            FILE *ifp = fopen("names.txt", "rb");
    
            // Read all names from the file and add them to smarty1.
            while (fscanf(ifp, "%s", buffer) != EOF)
                    put(smarty1, buffer);
    
            // Add the names to smarty2 in reverse order.
            for (i = getSize(smarty1) - 1; i >= 0; i--)
                    put(smarty2, get(smarty1, i));
    
            // Print the contents of smarty1.
            printf("\n-- SMART ARRAY 1: --\n");
            printSmartArray(smarty1);
    
            // Print the contents of smarty2.
            printf("\n-- SMART ARRAY 2 (First Names): --\n");
            printSmartArray(smarty2);
    
            // Swap last names with first names in smarty2.
            for (i = 0; i < getSize(smarty2); i++)
            {
                    if (strcmp(get(smarty2, i), "Andres") == 0)
                            set(smarty2, i, "Posadas");
                    else if (strcmp(get(smarty2, i), "Christopher") == 0)
                            set(smarty2, i, "Sipes");
                    else if (strcmp(get(smarty2, i), "Hanna") == 0)
                            set(smarty2, i, "Reed");
                    else if (strcmp(get(smarty2, i), "John") == 0)
                            set(smarty2, i, "Lien");
                    else if (strcmp(get(smarty2, i), "Kexin") == 0)
                            set(smarty2, i, "Liao");
                    else if (strcmp(get(smarty2, i), "Mohammad") == 0)
                            set(smarty2, i, "Ahmadian");
                    else if (strcmp(get(smarty2, i), "Richie") == 0)
                            set(smarty2, i, "Wales");
                    else if (strcmp(get(smarty2, i), "Sandesh") == 0)
                            set(smarty2, i, "Sharma");
            }
    
            // Print the contents of smarty2.
            printf("\n-- SMART ARRAY 2 (Last Names): --\n");
            printSmartArray(smarty2);
    
            // Print smarty1 (in reverse order) and smarty2, to match up first and last
            // names.
            printf("\n-- COMBINED ARRAYS (First and Last Names): --\n");
            for (i = 0; i < getSize(smarty2); i++)
                    printf("%s %s\n", get(smarty1, getSize(smarty1) - 1 - i), get(smarty2, i));
    
            // Add elements from smarty1 to the end of smarty1 (in reverse order).
            printf("\n");
            for (i = getSize(smarty1) - 1; i >= 0; i--)
                    printf("Adding %s to smarty1 ...\n", put(smarty1, get(smarty1, i)));
    
            // Print the contents of smarty1.
            printf("\n-- SMART ARRAY 1: --\n");
            printSmartArray(smarty1);
    
            // Insert a string at the beginning of array smarty1.
            insertElement(smarty1, 0, "List of Names:");
    
            // Print the contents of smarty1.
            printf("\n-- SMART ARRAY 1: --\n");
            printSmartArray(smarty1);
    
            // Remove all elements from smarty1.
            while (getSize(smarty1))
                    removeElement(smarty1, 0);
    
            // Print smarty1, which is now an empty array.
            printf("\n-- SMART ARRAY 1: --\n");
            printSmartArray(smarty1);
    
            // Destroy our smart arrays.
            smarty1 = destroySmartArray(smarty1);
            smarty2 = destroySmartArray(smarty2);
    
            // Make sure smarty1 is good and destroyed (and that destroySmartArray
            // doesn't segfault when passed a NULL pointer).
            smarty1 = destroySmartArray(smarty1);
    
            // Print the empty arrays one last time.
            printf("\n-- SMART ARRAY 1: --\n");
            printSmartArray(smarty1);
    
            printf("\n-- SMART ARRAY 2: --\n");
            printSmartArray(smarty2);
    
            return 0;
    }
    

    ================================================================================

    //SmartArray.c

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "SmartArray.h"
    
    
    SmartArray *createSmartArray(int length) { int n=0, i, capacity; // Dynamically allocate space for a new SmartArray SmartArray *smarty; char **temp; temp = NULL; smarty = malloc(sizeof(SmartArray)); if(smarty==NULL) return NULL; smarty->size = 0; // Initialize its internal array to be of length length or // DEFAULT_INIT_LEN if(length <= DEFAULT_INIT_LEN) { temp = malloc(sizeof(char * ) * DEFAULT_INIT_LEN); n = DEFAULT_INIT_LEN; } else if (length > DEFAULT_INIT_LEN ) { temp = malloc(sizeof(char * ) * length); n = length; } smarty->capacity = n; if (temp == NULL) return NULL; smarty->array=temp; // initialize pointers in the array to NULL for (i=0; i<n; i++) smarty->array[i] = NULL; printf("-> Created new SmartArray of size %d.\n", n ); return smarty; } // this function should print the contents of array // if the array is empty it prints empty array void printSmartArray(SmartArray *smarty) { int i, siz, capacity, n; if(smarty==NULL) { printf("(empty array)\n"); return; } siz = smarty->size; capacity = smarty->capacity; if (smarty->array==NULL) { printf("(empty array)\n"); return; } else if(smarty->array[0]==NULL) { printf("(empty array)\n"); return; } else if(smarty->array!=NULL) { for(i=0; i<capacity; i++) { if(smarty->array[i]!=NULL) printf("%s\n", smarty -> array[i]); } } } // free the smart array in reverse order of allocation // must free the memory in order to avoid leaks SmartArray *destroySmartArray(SmartArray *smarty) { int i, j; if(smarty==NULL) return NULL; // if smarty still exists but the array is null // must delete smarty and lurking array if(smarty->array==NULL) { free(smarty->array); free(smarty); return NULL; } for(i=0; i<smarty->capacity; i++) { free(smarty->array[i]); } free(smarty->array); free(smarty); return NULL; } char *put(SmartArray *smarty, char *str) { // use strlen to find string length // insert copy of str in next unused cell int slen , size, capacity; char *tempVar; // may want to create a temp variable to store str tempVar=NULL; if(smarty==NULL) return NULL; if(str==NULL) return NULL; size = smarty->size; capacity = smarty->capacity; slen = strlen(str); // expands the array if full // but really just creates an array of capacity*2 +1 and destroys old if (size==capacity) { expandSmartArray( smarty, (capacity * 2 + 1)); } tempVar = malloc(sizeof(char) * (slen+1)); if(tempVar==NULL) return NULL; strcpy(tempVar, str); smarty->array[size] = tempVar; if (str== NULL||smarty->array== NULL||smarty==NULL) return NULL; smarty->size = size + 1; // return the contents of string pointer return smarty->array[size]; } // expands smartArray to size of length SmartArray *expandSmartArray(SmartArray *smarty, int length) { int i, cap, si; char **tempArray; if(smarty==NULL) return NULL; if(smarty->array==NULL) return NULL; tempArray=NULL; si = smarty->size; cap = smarty->capacity; if(length <= cap) { return NULL; } if(cap<length){ // Initialize its internal array to be of length length or DEFAULT_INIT_LEN tempArray = malloc(sizeof(char * ) * length); if(tempArray == NULL) return NULL; // next copy the old addresses to the temp for(i=0; i<si; i++) { // array is basically temp variable tempArray[i] = smarty->array[i]; } for (i=si; i<length; i++) { tempArray[i]= NULL; } // erase the old smarty array free(smarty->array); // copies the temp array address to the old array smarty->array = tempArray; smarty->capacity = length; printf("-> Expanded SmartArray to size %d.\n", length); } else { return NULL; } return smarty; } // returns the element at the index // this function protects the user from going out of bounds with the array char *get(SmartArray *smarty, int index) { // if index was out of bounds or if the smarty pointer was null if((index < 0) || (index > smarty->capacity)|| smarty==NULL) return NULL; return smarty->array[index]; } // sets a string at the index indicated // if no string null; if it does replace char *set(SmartArray *smarty, int index, char *str) { char *tempVar; int slen, size; if((index < 0) || (index > smarty->capacity)|| smarty==NULL||str==NULL) return NULL; size = smarty->size; tempVar=NULL; slen = strlen(str); if(smarty->array[index]==NULL) return NULL; tempVar = malloc(sizeof(char) * (slen+1)); if(tempVar==NULL) return NULL; strcpy(tempVar, str); free(smarty->array[index]); smarty->array[index]=tempVar; if(smarty->array[index] != tempVar) return NULL; return smarty->array[index]; } // insert copy of str at the specified index // shift all others to the left char *insertElement(SmartArray *smarty, int index, char *str) { // use strlen to find string length // insert copy of str in next unused cell int slen , size, capacity, i; char *tempVar; char **tempArray; if((index < 0) || smarty==NULL||str==NULL) return NULL; size = smarty->size; capacity = smarty->capacity; slen = strlen(str); tempVar = NULL; tempArray=NULL; tempVar = malloc(sizeof(char) * (slen+1)); if(tempVar==NULL) return NULL; strcpy(tempVar, str); if (size==capacity) { expandSmartArray( smarty, (capacity * 2 + 1)); } if (index>=size) { smarty->array[size]=tempVar; if(smarty->array[size] != tempVar) return NULL; smarty->size= size +1; } else if(index<size) { tempArray = malloc(sizeof(char * ) * capacity); if(tempArray == NULL) return NULL; if(index>0) { for(i=0; i<index; i++) tempArray[i]=smarty->array[i]; } tempArray[index]=tempVar; // next copy the old addresses to the temp for(i=index; i<size; i++) { tempArray[i+1] = smarty->array[i]; } for (i=size+1; i<capacity; i++) { tempArray[i]= NULL; } // copies the temp array address to the old array smarty->array = tempArray; smarty->size= size +1; } // elements are shifted to the right one space if(smarty->array[index]==tempVar) return smarty->array[index]; return NULL; } // remove the string at the specified index in array // no gaps left int removeElement(SmartArray *smarty, int index) { int i, capacity, size; if (index<0 || smarty==NULL) return 0; size = smarty->size; capacity = smarty->capacity; if(size<=index) return 0; if(smarty->array==NULL) return 0; if(smarty->array[index]==NULL) return 0; smarty->array[index]= NULL; size = smarty->size; for(i=index;i<size; i++) { smarty->array[i]=smarty->array[i+1]; } for(i=size;i<capacity;i++) { smarty->array[i]=NULL; } smarty->size = size-1; return 1; } int getSize(SmartArray *smarty) { int size; if(smarty==NULL) return -1; size = smarty->size; if(smarty->capacity==0) return size; if(smarty->array!=NULL) return size; return -1; } // trim any extra nodes from the array SmartArray *trimSmartArray(SmartArray *smarty) { int capacity, size, i; char **tempArray; tempArray=NULL; if(smarty==NULL) return NULL; size = smarty->size; capacity = smarty ->capacity; if(capacity==0) return NULL; // what happens if the size is zero if (size == 0) { for(i=0; i<capacity; i++) free(smarty->array[i]); free(smarty->array); smarty->array=NULL; smarty->capacity=0; } else if (capacity>size) { tempArray=malloc(sizeof(char*)*size); if(tempArray == NULL) return NULL; smarty->capacity = size; for(i=0; i<size; i++) { tempArray[i] = smarty->array[i]; } free(smarty->array); smarty->array=tempArray; } // output if length trimmed printf("-> Trimmed SmartArray to size %d.\n", size); return smarty; } double difficultyRating(void) { return 5.0; } double hoursSpent(void) { return 40.0; } ===================================================================================== 
    

    //SmartArray.h

    #ifndef __SMART_ARRAY_H
    #define __SMART_ARRAY_H
    
    // Default capacity for new SmartArrays
    #define DEFAULT_INIT_LEN 10
    
    typedef struct SmartArray
    {
            // We will store an array of strings (i.e., an array of char arrays)
            char **array;
    
            // Size of array (i.e., number of elements that have been added to the array)
            int size;
    
            // Length of the array (i.e., the array's current maximum capacity)
            int capacity;
    
    } SmartArray;
    
    
    // Functional Prototypes
    
    SmartArray *createSmartArray(int length);
    
    SmartArray *destroySmartArray(SmartArray *smarty);
    
    SmartArray *expandSmartArray(SmartArray *smarty, int length);
    
    SmartArray *trimSmartArray(SmartArray *smarty);
    
    char *put(SmartArray *smarty, char *str);
    
    char *get(SmartArray *smarty, int index);
    
    char *set(SmartArray *smarty, int index, char *str);
    
    char *insertElement(SmartArray *smarty, int index, char *str);
    
    int removeElement(SmartArray *smarty, int index);
    
    int getSize(SmartArray *smarty);
    
    void printSmartArray(SmartArray *smarty);
    
    double difficultyRating(void);
    
    double hoursSpent(void);
    
    
    #endif
    
Add a comment
Know the answer?
Add Answer to:
in JAVA -- need to use an arraystack for this and can only manipulate smartstring.java aka...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Doubly Linked List The assignment is to modify the below code in any way (like changing the method of a function). Time...

    Doubly Linked List The assignment is to modify the below code in any way (like changing the method of a function). Time complexity is omitted. Any methods/functions below could be changed into something different. I was thinking of changing the method of getting size of list and maybe change from numbers to letters for nodes. import java.util.Scanner; /* Class Node */ class Node { protected int data; protected Node next, prev; /* Constructor */ public Node() { next = null;...

  • Doubly Linked List Is there a way to further modify/simplify/improve this program? I was thinking of maybe changing how...

    Doubly Linked List Is there a way to further modify/simplify/improve this program? I was thinking of maybe changing how to get size. I'm not sure. import java.util.Scanner; /* Class Node */ class Node { protected int data; protected Node next, prev; /* Constructor */ public Node() { next = null; prev = null; data = 0; } /* Constructor */ public Node(int d, Node n, Node p) { data = d; next = n; prev = p; } /* Function...

  • *JAVA* Can somebody take a look at my current challenge? I need to throw a different...

    *JAVA* Can somebody take a look at my current challenge? I need to throw a different exception when a)(b is entered. It should throw "Correct number of parenthesis but incorrect syntax" The code is as follows. Stack class: public class ArrayStack<E> {    private int top, size;    private E arrS[];    private static final int MAX_STACK_SIZE = 10;    public ArrayStack() {        this.arrS = (E[]) new Object[MAX_STACK_SIZE];        this.top = size;        this.size = 0;...

  • You will write a single java program called MadLibs. java.

    You will write a single java program called MadLibs. java. This file will hold and allow access to the values needed to handle the details for a "MadLibs" game. This class will not contain a maino method. It will not ask the user for any input, nor will it display (via System.out.print/In()) information to the user. The job of this class is to manage information, not to interact with the user.I am providing a MadLibsDriver.java e^{*} program that you can...

  • Person Name: John Doe Person Birth Year: 1960 Person Name: Emily Zhang Person Birth Year: 2007...

    Person Name: John Doe Person Birth Year: 1960 Person Name: Emily Zhang Person Birth Year: 2007 Student Major: Finance Person Name: Paul zhang Person Birth Year: 1970 Instructor Salary: $50,000.00 Exception in thread "main" java.util.InputMismatchException at java.base/java.util.Scanner.throwFor(Scanner.java:939) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at PersonTest.main(PersonTest.java:47) import java.util.Scanner; public class PersonTest { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Person Name: "); String student_name = scan.nextLine(); System.out.print("Person Birth Year: "); int student_yearOfBirth = scan.nextInt(); Person p =...

  • My Question is: I have to modify this program, even a small modification is fine. Can...

    My Question is: I have to modify this program, even a small modification is fine. Can anyone give any suggestion and solution? Thanks in Advanced. import java.util.*; class arrayQueue { protected int Queue[]; protected int front, rear, size, len; public arrayQueue(int n) { size = n; len = 0; Queue = new int[size]; front = -1; rear = -1; } public boolean isEmpty() { return front == -1; } public boolean isFull() { return front == 0 && rear ==size...

  • Hello! I have a problem in my code please I need help, I don't know How I can wright precondition, so I need help about assertion of pre_condition of peek. Java OOP Task is! Improve the circular a...

    Hello! I have a problem in my code please I need help, I don't know How I can wright precondition, so I need help about assertion of pre_condition of peek. Java OOP Task is! Improve the circular array implementation of the bounded queue by growing the elements array when the queue is full. Add assertions to check all preconditions of the methods of the bounded queue implementation. My code is! public class MessageQueue{ public MessageQueue(int capacity){ elements = new Message[capacity];...

  • JAVA- Complete the code by following guidelines in comments. class CircularList { private Link current; private...

    JAVA- Complete the code by following guidelines in comments. class CircularList { private Link current; private Link prev; public CircularList() { // implement: set both current and prev to null } public boolean isEmpty() { // implement return true; } public void insert(int id) { // implement: insert the new node behind the current node } public Link delete() { // implement: delete the node referred by current return null; } public Link delete(int id) { // implement: delete the...

  • Complete the following Java program by writing the missing methods. public class 02 { public static...

    Complete the following Java program by writing the missing methods. public class 02 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a number: int n = scan.nextInt(); if (isOdd (n)) { //Print n to 1 System.out.println("Print all numbers from "+n+" to 1"); printNumToOne (n); } else { System.out.println(n + " is //End of main()

  • Can Anyone help me to convert Below code to C++! Thanks For example, in C++, the...

    Can Anyone help me to convert Below code to C++! Thanks For example, in C++, the function headers would be the following: class MaxHeap { vector<int> data; public: MaxHeap() { // ... } int size() { // ... } int maxLookup() { // ... } void extractMax() { // ... } void insert(int data) { // ... } void remove(int index) { // ... } }; ======================== import java.util.Arrays; import java.util.Scanner; public class MaxHeap { Integer[] a; int size; //...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT