|
Until you sign up you can't do much. Yes, it's free.
|
|
|
|
|
|
|
 | / / / Viewing Topic
|  |
( King Kong )
Welsh Hero
Patron
|
| Code: | public class Directory { private static final int NO_ENTRIES = 100; Entry[] theDirectory = new Entry[NO_ENTRIES]; // add an entry to theDirectory // if theDirectory is full do not add the entry public void add(Entry anEntry) { newentry = (f,s,a,h); } // deletes an existing entry public void delete(String nameToDelete) { newentry = (); } // change the number of an existing entry public void change(String name, String newTelNo) { telNo = newTelNo } // finds and returns the number for the search name public String find(String searchName) { find = } // returns the entire directory as a String public String toString() { System.out.println(array } } | It's a class
------- Pandora didn't think outside the box
|
|
|
|
|
 LiveWire Humor
|
|
JamesBrauman
Visionary
|
Is this c# or java, they both look the same lmao
|
|
|
( King Kong )
Welsh Hero
Patron
|
Quote: from JamesBrauman at 11:13 am on Jan. 25, 2010
Is this c# or java, they both look the same lmao
Java
------- Pandora didn't think outside the box
|
|
|
|
|
|
|
|
|
|
|
|
|
JamesBrauman
Visionary
|
| Code: | public class Entry { public string Name; public string PhoneNumber; } public class Directory { private static int maximumEntries = 100; Entry[] theDirectory = new Entry[maximumEntries]; private int FindEntry(string entryName) { // This method will find an entry in the directory // with a name matching 'entryName' and return // it's index. // It does this by looping over every element in // the array 'theDirectory' and checking // if that name equals what we are looking for. for (int i = 0; i < theDirectory.Length; i++) { if (theDirectory.Name == entryName) { // We found the name we are looking for // return it. return i; } } // If we reached this point in the code, we didn't // find an entry that matched the name. Return -1 // to indicate this. return -1; } public void Add(Entry newEntry) { // Lets test to see if theDirectory contains less than // our maximum number of allowed entries. If it does // we are allowed to add an entry. // In java, the doing theDirectory.Length will // probably not work, you will need to find a method // of getting the number of elements in an array. if (theDirectory.Length < maximumEntries) { // We can add an entry. theDirectory[theDirectory.Length] = newEntry; } } public void Delete(string NameToDelete) { // Lets use the method 'FindEntry' to delete an // existing entry. int index = FindEntry(NameToDelete); if (index != -1) theDirectory[index] = null; } public void Change(string name, string newPhoneNumber) { // Lets use the method 'FIndEntry' to change the // number of an existing entry. int index = FindEntry(name); if (index != -1) { theDirectory[index].PhoneNumber = newPhoneNumber; } } public string ToString() { // Lets create a new string object to hold all the content // of the directory. string directoryContent = ""; // For each element in the directory, lets add the name // and phone number to the string, and also a new line. foreach (Entry e in theDirectory) { directoryContent += e.Name + ": " + e.PhoneNumber + "\n"; } // Lets return the string containing the directory content. return directoryContent; } } |
|
|
|
JamesBrauman
Visionary
|
does that help
|
|
|
|
|
|
|
|
| Looking for something else?
|
|
|
|
|
|
 | / / / Viewing Topic |  |
|