LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 725 users online 230802 members 974 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
Jack Kahuna
I haven't filled out my profile...
Days Active: 1
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
4 online / 46 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

Does this look Right to you
Replies: 11Last Post Feb. 7 3:00am by JamesBrauman
Welcome to LiveWire!
We're Stronger Together.
Join the Community
Single page for this topic Email Print Favorite
( King Kong )


Welsh Hero

Patron
Reply
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


2:16 am on Jan. 25, 2010 | Joined: Feb. 2006 | Days Active: 1,195
Join to learn more about King Kong Wales | Straight Male | Posts: 28,953 | Points: 41,596
LiveWire Humor
JamesBrauman


Visionary
Reply
Is this c# or java, they both look the same lmao

3:13 am on Jan. 25, 2010 | Joined: Nov. 2005 | Days Active: 211
Join to learn more about JamesBrauman Australia | Straight Male | Posts: 6,103 | Points: 8,096
( King Kong )


Welsh Hero

Patron
Reply
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

3:13 am on Jan. 25, 2010 | Joined: Feb. 2006 | Days Active: 1,195
Join to learn more about King Kong Wales | Straight Male | Posts: 28,953 | Points: 41,596
JamesBrauman


Visionary
Reply
You're not declaring newentry anywhere, and you are just assigning to newentry. So when you call your method 'add', it isn't actually adding anything to the array of Entry (Entry[] theDirectory).

To be honest that class doesn't make any sense to me, its really incomplete and the code doesn't make sense.

Are you just a beginner, or maybe you copy and pasted incorrectly? I mean I've never programmed in Java but the code is not doing anything really.

I can post some code in C# showing how I would do it if you like.


3:22 am on Jan. 25, 2010 | Joined: Nov. 2005 | Days Active: 211
Join to learn more about JamesBrauman Australia | Straight Male | Posts: 6,103 | Points: 8,096
( King Kong )


Welsh Hero

Patron
Reply
Quote: from JamesBrauman at 11:22 am on Jan. 25, 2010

You're not declaring newentry anywhere, and you are just assigning to newentry. So when you call your method 'add', it isn't actually adding anything to the array of Entry (Entry[] theDirectory).

To be honest that class doesn't make any sense to me, its really incomplete and the code doesn't make sense.  

Are you just a beginner, or maybe you copy and pasted incorrectly? I mean I've never programmed in Java but the code is not doing anything really.

I can post some code in C# showing how I would do it if you like.


my lecturer gave us the layout, we got to add to it. then the next exercise is to create a test class

-------
Pandora didn't think outside the box


3:23 am on Jan. 25, 2010 | Joined: Feb. 2006 | Days Active: 1,195
Join to learn more about King Kong Wales | Straight Male | Posts: 28,953 | Points: 41,596
JamesBrauman


Visionary
Reply
To be honest I'm not sure I can help you, anything I write might be too complicated for you (no offense intended). You just don't seem to have grasped the basics yet.

Perhaps you should ask your classmates to explain how they did it to you.

BTW, what course are you doing? I've just found out I got into a Diploma of Software Development (which is awesome, because I didn't even finish school) and I'm extremely excited.

Hope they don't make us program in Java though, yuck :P


3:32 am on Jan. 25, 2010 | Joined: Nov. 2005 | Days Active: 211
Join to learn more about JamesBrauman Australia | Straight Male | Posts: 6,103 | Points: 8,096
( King Kong )


Welsh Hero

Patron
Reply
Quote: from JamesBrauman at 11:32 am on Jan. 25, 2010

To be honest I'm not sure I can help you, anything I write might be too complicated for you (no offense intended). You just don't seem to have grasped the basics yet.

Perhaps you should ask your classmates to explain how they did it to you.

BTW, what course are you doing? I've just found out I got into a Diploma of Software Development (which is awesome, because I didn't even finish school) and I'm extremely excited.

Hope they don't make us program in Java though, yuck :P



you do know what a class is (no offense intended)

-------
Pandora didn't think outside the box

3:37 am on Jan. 25, 2010 | Joined: Feb. 2006 | Days Active: 1,195
Join to learn more about King Kong Wales | Straight Male | Posts: 28,953 | Points: 41,596
JamesBrauman


Visionary
Reply
lol. Don't give me a hard time because I'm trying to help you.

I'll write something up in C# but you might not know wtf is going on, hold on. I'll try to comment it as best I can.

Going to go for a smoke though, I'll try to post back within 15 mins.


3:39 am on Jan. 25, 2010 | Joined: Nov. 2005 | Days Active: 211
Join to learn more about JamesBrauman Australia | Straight Male | Posts: 6,103 | Points: 8,096
JamesBrauman


Visionary
Reply
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;
       }
   }


3:54 am on Jan. 25, 2010 | Joined: Nov. 2005 | Days Active: 211
Join to learn more about JamesBrauman Australia | Straight Male | Posts: 6,103 | Points: 8,096
JamesBrauman


Visionary
Reply
does that help

4:02 am on Jan. 25, 2010 | Joined: Nov. 2005 | Days Active: 211
Join to learn more about JamesBrauman Australia | Straight Male | Posts: 6,103 | Points: 8,096
Yaycakebanana


Wealthy Hobo
Reply
Quote: from JamesBrauman at 4:02 am on Jan. 25, 2010

does that help

I'm sad to see code to go waste ;_;
He didn't even respond. :P

I'm currently learning C#! :D


5:02 am on Jan. 30, 2010 | Joined: Oct. 2006 | Days Active: 419
Join to learn more about Yaycakebanana California, United States | GLBT Ally Male | Posts: 1,704 | Points: 5,884
JamesBrauman


Visionary
Reply
Quote: from Yaycakebanana at 5:02 am on Jan. 30, 2010

Quote: from JamesBrauman at 4:02 am on Jan. 25, 2010

does that help

I'm sad to see code to go waste ;_;  
He didn't even respond. :P

I'm currently learning C#! :D



Yeah, I commented it well and everything :(

C# rocks!


3:00 am on Feb. 7, 2010 | Joined: Nov. 2005 | Days Active: 211
Join to learn more about JamesBrauman Australia | Straight Male | Posts: 6,103 | Points: 8,096
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic