public void print(){
System.out.println("Address Book Contacts "+contacts[i]);
}
Where do you define 'i' at the above code? That is why you get the error.
Also you will have manyAddresses at your program. Meaning that you will have a collection of Addresses. So why do you put the printMenu and functionality in that class.
Have this:
public class Address{
//Declare variables
String first;
String last;
String homeadd;
String homeph;
String cellnum;
public Address(String firstName, String lastName, String homeAddress, String homePhone, String cellNumber){
first=firstName;
last=lastName;
homeadd=homeAddress;
homeph=homePhone;
cellnum=cellNumber;
}
public Address() {
}
// have methods for getting and setting the value of the class
In another class, in the main method you will have your menu and you will create instances of the class Address
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
Since you don't seem to get my suggestions I prepared this small document on how to proceed:
The Address class will have ONLY these:
class Address {
private String first = "";
// rest attributes last, homeadd ...
public Address() {
}
public String getFirst() {
return first;
}
public void setFirst(String first) {
this.first = first;
}
// rest methods for last, homeadd ...
}
Read the class Vector . Look at the methods add, get, size
class AddressBook {
public Vector addresses = new Vector();
public AddressBook() {
}
}
And in the main class
public class Main() {
public static void main(String [] args) {
Scanner scan = new Scanner(System.in);
AddressBook book = new AddressBook();
String choice = "";
// print menu
....
//
choice = scan.nextLine();
if (choice.equals("1") { // add contacts
Address ad = new Address();
// read the data from the keyboard (scan.nextLine())
// use the set methods (ad.setFirst(...)
book.addresses.add(ad);
} else if (.. "2") { // See if a person is in the address book
// read the name from the keyboard
// loop the Vector and take each Address. Then compare the name of each Address with the one given
} else if (.. "3") { // View contacts in the address book
// loop the Vector, take each Address and print its values
} else if (.. "4") { // Exit
} else {
System.out.println("Error choice");
}
}
}
You might want to put the part form the "print menu" till the "if statements" into a while loop in order to add multiple Addresses and repeat the proccess:
while (!choice.equals("4") {
}
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
can u give me some code that helping me making simple addressbook?
thats have output
attributes | description
name |
address |
telnum |
email add |
using util scanner
and provide nesscesarry accessor and mutator methods all the attributes
and creating object provide
add entry, delete entry view entries,, update entry
Start a new thread with your question and your code.
As far as your question:
since you posted in this thread, you should have read it and saw that your question has been answered. This thread has the code and examples that you need to get you started.
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
give me the source code to my e-mail id
Read the previous posts. Start a new thread.
And we don't give away homework or give code through emails or PMs. It is against the rules to post your email asking for help.
If you want help start a new thread with specific questions.
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
fgfgfgjgjdhtjghdhtjdgjgjghj
Start a new thread.
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448