Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
Gwen Smith
Greenhorn
+ Follow
5
Posts
2
Threads
0
Cows
since Jan 23, 2011
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
Ranch Hand Scavenger Hunt
Number Posts (5/100)
Number Threads Started (2/100)
Number Cows Received (0/5)
Number Likes Received (0/10)
Number Likes Granted (0/20)
Set bumper stickers in profile (0/3)
Report a post to the moderators (0/1)
Edit a wiki page (0/1)
Create a post with an image (0/2)
Greenhorn Scavenger Hunt
First Post
Number Posts (5/10)
Number Threads Started (2/10)
Number Likes Received (0/3)
Number Likes Granted (0/3)
Set bumper stickers in profile (0/1)
Set signature in profile
Search for a post/thread (0/3)
Set a watch on a thread
Save thread as a bookmark
Create a post with an image (0/1)
Recent posts by Gwen Smith
using toString()
theList is an array of objects (Contact[])
public class ContactList { private int MAX_ENTRIES; private Contact[] theList; private String phoneNumber; private int count; private String name; /* * Create a new ContactList that uses filename for storage. * If filename exists, populate the list with the contacts * stored in the file. */ public ContactList (String filename) { int MAX_ENTRIES=100; theList = new Contact[MAX_ENTRIES]; int count=0; } /* * Save the current contact list to the file. Return true * if successful, false if an error occurs. */ public boolean save() { /*fix later */ return false; } /* * Add a new contact * * No checking is done to see if the name is already in the * contact list. Adding the same name twice results in * undefined behavior when search for that contact later. * * Return true if the contact was added, false otherwise. */ public boolean add(String name, String phone) { Contact[] thelist = new Contact[count]; count++; return true; } /* * Print the current contacts on stdout. */ public void list() { theList.toString(); } /* * Remove the contact passed as the parameter name. * * If the contact is not currently in the contact list, return * false. * Return true if the contact is removed. */ public boolean remove(String name) { /* fix later */ return false; } /* * Print the contact information for name on stdout. * * Return false if the contact is not found, true otherwise. */ public boolean lookup(String name) { /* fix later */ return false; } }
show more
13 years ago
Beginning Java
using toString()
I'm trying to print out an array (theList) of objects, and I keep getting something like this: [LContact;@1389e4
I have a toString() method:
public String toString() { return name+" "+phoneNumber; }
and the bit that should print it out
public void list() { System.out.println(theList.toString()); }
I think it's the second part that's wrong, but I'm not sure why, or how to make it right.
show more
13 years ago
Beginning Java
i don't know what i'm doing
thanks!
i
show more
13 years ago
Beginning Java
i don't know what i'm doing
okay, so I don't know what that was.
what I want to do is make it so the add() will take a name and phone number and add it to theList, which is an instance of Contact()
public class Contact { private String name; private String phoneNumber; /* * Create a new contact with name and phoneNumber */ public Contact (String name, String phoneNumber) { name=name; phoneNumber=phoneNumber; } }
/* * ContactList.java * * This class implements a list of contacts. * */ import java.io.*; public class ContactList { private static final int MAX_ENTRIES = 100; private Contact[] theList; private int count; private String phoneNumber; private String name; /* * Create a new ContactList that uses filename for storage. * If filename exists, populate the list with the contacts * stored in the file. */ public ContactList (String filename) { count = 0; theList = new Contact[MAX_ENTRIES]; } /* * Save the current contact list to the file. Return true * if successful, false if an error occurs. */ public boolean save() { /* XXX Fix me */ return false; } /* * Add a new contact * * No checking is done to see if the name is already in the * contact list. Adding the same name twice results in * undefined behavior when search for that contact later. * * Return true if the contact was added, false otherwise. */ public boolean add(String name, String phone) { theList=new Contact(name, phone); return true; } /* * Print the current contacts on stdout. */ public void list() { /* XXX Fix me */ } /* * Remove the contact passed as the parameter name. * * If the contact is not currently in the contact list, return * false. * * Return true if the contact is removed. */ public boolean remove(String name) { /* XXX Fix me */ return false; } /* * Print the contact information for name on stdout. * * Return false if the contact is not found, true otherwise. */ public boolean lookup(String name) { /* XXX Fix me */ return false; } }
and thanks for the welcome!
show more
13 years ago
Beginning Java
i don't know what i'm doing
i'm working on a program that takes a name and phone number, and creates a contact list. When I try and compile this program, I get this error
ContactList.java:57: ')' expected
Contact theContact= new Contact(theList[count]=theContact: name, phone);
and I'm not quite sure what it means.
public boolean add(String name, String phone) { /*add contact to list */ Contact theContact= new Contact(theList[count]=theContact: name, phone); count++; return true; }
show more
13 years ago
Beginning Java