Need some help with a remove function

Design and code a program that will maintain a list of product names. Use a String type to represent the product name and an array of strings to implement the list. Your program must implement the following methods:

Add a product to the list

Remove a product from the list

Display then entire list

Find out if a particular product is on the list.

You need to create a command command loop with a menu() function. The program must continue asking for input until the user stops.

This is the assignment and this is what I have so far. I need some help writing the remove function.

Thanks

/*

* Title:SimpleSearchableList.java

* Description: this example will show a reasonably efficient and

* simple algorithm for rearranging the value in an array

* in ascending order.

*/

public class SimpleSearchableList {

private static String[] List = new String[25]; //These variables (field variables)

private static int Size; //are common to the entire class, but unavailable

//except to the methods of the class...

public static void main(String[] args)

{

String Cmd;

for(;;) {

Menu();

System.out.print("Command: ");

Cmd = SimpleIO.inputString();

if(Cmd.equals("Quit"))

break;

else if(Cmd.equals("Fill"))

FillList();

else if(Cmd.equals("Search"))

SearchList();

else if(Cmd.equals("Show"))

ShowList();

else if(Cmd.equals("Remove"))

Remove();

}

}

//Tells you what you can do...

public static void Menu()

{

System.out.println("Choices..................................");

System.out.println("\tFill to Enter Product");

System.out.println("\tShow to Show Products");

System.out.println("\tSearch to Search for Product");

System.out.println("\tRemove a Product");

System.out.println("\tQuit");

System.out.println(".........................................");

}

//This method will allow the user to fill an array with values...

public static void FillList()

{

int Count;

System.out.println("Type Stop to Stop");

for(Count = 0 ; Count < List.length ; Count++)

{

System.out.print("Enter Product: ");

List[Count] = SimpleIO.inputString();

if(List[Count].equals("Stop"))

break;

}

Size = Count;

}

//This method will rearrange the values in the array so that

// go from smallest to largest (ascending) order...

public static void SearchList()

{

String KeyValue;

boolean NotFoundFlag;

int Z;

System.out.println("Enter Product Names Below, Stop To Quit");

while(true)

{

System.out.print("Enter: ");

KeyValue = SimpleIO.inputString();

if(KeyValue.equals("Stop")) //Note the use of a method for testing

break;// for equality...

NotFoundFlag = true; //We'll assume the negative

for(Z = 0 ; Z < Size ; Z++)

if(List[Z].equals(KeyValue)) {

NotFoundFlag = false; //If we fine the name, we'll reset the flag

System.out.println(List[Z] + " was found");

}

if(NotFoundFlag)

System.out.println(KeyValue + " was not found");

}

}

//This method will display the contents of the array...

public static void ShowList()

{

int Z;

for(Z = 0 ; Z < Size ; Z++)

System.out.println("Product " + (Z+1) + " = " + List[Z]);

}

public static void Remove()

{

}

}

[3614 byte] By [javanoob21a] at [2007-11-27 11:20:51]
# 1

So what is your problem, besides not knowing what a "SSCCE" is and what [ code ] tags are good for?

And by the way, Java defines those things to be called "methods". And their names should begin with a lowercase letter, just like everything else except class names and constants (all caps).

CeciNEstPasUnProgrammeura at 2007-7-29 14:45:04 > top of Java-index,Java Essentials,Java Programming...
# 2

I need help removing a product from the array

Message was edited by:

javanoob21

javanoob21a at 2007-7-29 14:45:04 > top of Java-index,Java Essentials,Java Programming...
# 3

> I need help removing a product from the array

Yes. So what's your problem?

"Doctor, I need help."

"What's wrong?"

"I need help!"

Great.

By the way, you can't remove anything from an array. You'll have to copy the remaining stuff into a new one, or maybe maintain a list of "empty" slots. Or null the slots and handle that. The first way will be the easiest though.

CeciNEstPasUnProgrammeura at 2007-7-29 14:45:04 > top of Java-index,Java Essentials,Java Programming...
# 4

yikes, i gave the same advice in the new to java forum. Word of advice for you newbie:

DON'T CROSS POST!! It means that I do work to help you for no benefit since someone else already posted this information. I don't like wasting my time.

petes1234a at 2007-7-29 14:45:04 > top of Java-index,Java Essentials,Java Programming...