I have several commands created to ask a user to add numbers to an array. I now need to be able to have the user select a specific element in the array and place an * on the selected element when printed out. I have the program separated into two classes: one class for storing and managing the array and the other handles user input and output.
For example here is the code in the class that handles input/output:
else if (cmd.equals("add"))
{
// add x command
int x = input.nextInt();
list.add(x);
list.print();
}
and here is the part in the class that deals with the array:
public void add(int x)
{
// Expand the list capacity if necessary
if (count >= list.length)
{
// Allocate a new longer list
int[] newList = new int[list.length + 5];
// Copy existing numbers to new list
for (int i = 0; i < list.length; i++)
{
newList[i] = list[i];
}
// Reassign the list to be the new one
list = newList;
}
// Add x to the end of the list
list[count] = x;
count++;
}
This is the command created to add entries to the array(and enlarge the array if necessary), now I just need help creating a command to allow a user to select a specific entry in the array and place an * in front of it.
intarray, you're not going to be able to add a "" in front of anything. You could keep track of the selected index and when required to print it, insert the "" into the output