Question
/WRITE AN APPLICATION CLASS HIGHARRAYAPP.JAVA TO TEST ALL METHODS DEFINED IN HIGHARRAY.JAVA CLASS. THE APPLICATION SHOULD ALLOW THE USER TO DECIDE THE LENGTH OF THE
/WRITE AN APPLICATION CLASS HIGHARRAYAPP.JAVA TO TEST ALL METHODS DEFINED IN HIGHARRAY.JAVA CLASS. THE APPLICATION SHOULD ALLOW THE USER TO DECIDE THE LENGTH OF THE ARRAY ( ASK FOR USER INPUT AND USE THAT VALUE WHILE INSTANTIATE THE OBJECT OF HIGHARRAY). YOUR PROGRAM SHOULD PROVIDE A MENU OF OPERATIONS. USE JAVA "SWITCH" STATEMENT TO BRANCH TO THE DIFFERENT OPERATIONS.
I'M HAVING A HARD TIME TO LET THE USER INPUT THE ARRAY. COULD YOU PLEASE HELP ME OUT ( I ONLY TRIED FOR CASE 1). THANK YOU
public class highArray
{
private long [] a;
private int nElems;
public highArray (int max)
{
a = new long [max];
nElems= 0;
}
public boolean find (long searchKey)
{
int j;
for(j=0; j if (a[j] == searchKey) break; if (j == nElems) return false; else return true; } public void insert (long value) { a[nElems]= value; nElems++; } public boolean detele ( long value) { int j; for (j=0; j if (value == a[j]) break; if (j==nElems) return false; else { for (int k=j; k a[k]= a[k+1]; nElems--; return true; } } public String toString() { String ReturnList = "Your Data entered is: "; for (int j=0; j { ReturnList += a[j]+ " "; } return ReturnList; } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// import java.util.Scanner; public class HighArrayApp { public static void main( String [] args ) { Scanner scan = new Scanner( System.in ); int length= scan.nextInt(); char option; highArray arr; arr = new highArray(length); String menu = "\t1) Insert a Data:"; menu += " \t2) Remove a Data:"; menu += " \t3) Search a Data:"; menu += " \t4) Display all Data"; menu += " \t5) Quit "; System.out.println( "\"Please select one of the following option " ); System.out.println( menu ); // print the menu System.out.print( "Make a selection " + "or \"5\" to quit > " ); option = scan.next( ).charAt( 0 ); while ( option != '5') { switch ( option ) { case '1': System.out.print( "Please insert your data:" ); length= scan.nextInt(); arr.insert(length); break; case '2': System.out.print( "Please insert data to be removed: " ); break; case '3': System.out.print( "Please select the data you would like to search " ); break; case '4': System.out.print( "Displaying Data entered:" ); break; default: System.out.println( "Please select a correct option" ); } System.out.print("Make a selection " + "or \"5\" to quit > "); option = scan.next( ).charAt( 0 ); } System.out.println( "Thank you, Goodbye" ); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started