i need a copy of a java phonebook code that uses the listarraybased
and person class taking as parameters name and fon number. i need the
actual code. |
Request for Question Clarification by
secret901-ga
on
09 Mar 2003 23:36 PST
Hi ianra,
If you give more specific details of what you want, I think a
researcher might be able to help you:
1) Is it GUI-based?
2) How exactly are the data entered?
|
Clarification of Question by
ianra-ga
on
10 Mar 2003 07:26 PST
the program should loop a text menu asking ; add person/remove person/
get phone /displayall/quit.
|
Clarification of Question by
ianra-ga
on
10 Mar 2003 22:32 PST
I can post or email the code i have so far if this will be help. it is
a pretty simple java prog i just need assistance actually implementing
the array based list (that is already written) in my phonebook class
|
Request for Question Clarification by
secret901-ga
on
10 Mar 2003 23:01 PST
Hi ianra,
It's a good idea to post the relevant part of the code where you need
help, because currently your question is a bit vague, thus specifying
where you need help will aid researchers in helping you.
secret901-ga
|
Clarification of Question by
ianra-ga
on
11 Mar 2003 07:22 PST
here i have posted the most relevant parts of my code the one i need
to complete is the phonebook class.each entry must be a person.
this is the code from my listarraybased class
/*
* ListArrayBased.java
*
* Created on March 9, 2003, 2:15 PM
*/
/**
*
* @author fini1113
*/
public class ListArrayBased implements ListInterface {
private static final int MAX_LIST = 50;
private int maxList;
private Object[] items;
private int numItems;
/** Creates a new instance of ListArrayBased */
public ListArrayBased() {
items = new Object[MAX_LIST];
numItems = 0;
}
public boolean isEmpty() {
return (numItems == 0);
}
public int size() {
return numItems;
}
public void removeAll() {
items = new Object[MAX_LIST];
numItems = 0;
}
public void add(int index, Object item)
throws ListIndexOutofBoundsException {
if (numItems > MAX_LIST) {
throw new ListException("ListException on add");
}
if ((index >= 1) && (index <= (numItems + 1))) {
for (int pos = numItems; pos >= index; pos--) {
items[translate(pos + 1)] = items[translate(pos)];
}
}
}
public Object get(int index) throws ListIndexOutofBoundsException
{
if ((index >= 1) && (index >= numItems)) {
return items[translate(index)];
} else {
throw new ListIndexOutofBoundsException(
"ListIndexOutofBoundsException on get");
}
}
public void remove(int index) {
}
private int translate(int position) {
return position - 1;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
}
}
********************************************************************************
this is the code from my person class:
import java.io.*;
/*
* Person.java
*
* Created on March 9, 2003, 1:41 PM
*/
/**
*
* @author fini1113
*/
public class Person {
private String phone;
private String name;
/** Creates a new instance of Person */
public Person(String n, String p) {
name = n;
phone = p;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
}
public String getName() {
return name;
}
public String getNumber() {
return phone;
}
}
********************************************************************************
this is the actual phonebook class that i need to complete using
listarraybased commands
import java.io.*;
/*
* PhoneBook.java
*
* Created on March 9, 2003, 1:42 PM
*/
/**
*
* @author fini1113
*/
public class PhoneBook {
/** Creates a new instance of PhoneBook */
public PhoneBook() {
}
public static int menu() {
int choice = 1;
System.out.println("Add a new Person to the PhoneBook");
return choice;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ListArrayBased book = new ListArrayBased();
}
public static void add(Person p, ListArrayBased book) throws
ListException{
}
public static void remove(Person p, ListArrayBased book){
}
public static String get(String name, ListArrayBased book){
return name;
}
public static void display(ListArrayBased book){
if (book.isEmpty())
System.out.println("The Phone Book is empty");
else
for (int i = 1; i<= book.size(); i++){
System.out.println(((Person)book.get(i)).getName()
+ ((Person)book.get(i)).getNumber());
}
}
}
********************************************************************************
|
Request for Question Clarification by
googleexpert-ga
on
17 Mar 2003 10:59 PST
I tried compiling your code, but received error messages. Can you
post the code for that class?
|
Request for Question Clarification by
googleexpert-ga
on
23 Mar 2003 17:36 PST
I tried compiling your code, but received error messages. Can you
post the code for the "ListInterface" class?
|