4 Replies - 295 Views - Last Post: 07 October 2012 - 05:09 PM Rate Topic: -----

#1 dicoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-September 12

Java Directory Problem/Task question

Posted 05 October 2012 - 07:26 AM

Hello, I am student and new to Java. I have a project due and I am looking for directions or examples that will allow me to complete the assignment. I am enjoying learning about programing and want to make it a career. With that said I place my code below which has four classes Directory, Persons,Students, Staff & Faculty. Students, Staff, and Faculty extends Persons.

***The objectives are to :add a person, print all people (alphabetically by name), print just Students, remove a person & retrieve a person. Classes should overload the toString()method to produce appropriate String to be used as the directory list. The listing should be produced be iterating through the Collections of entries, using the toString()method to print each entry..For remove and retrieve methods add getter method to the Persons class to return the key of the object.

I am not asking for any to do my work and I apologize if this is posted in the incorrect area. I have not been able to progress due to information overload and possibly following back examples...What I seek is a program or instruction similar to the task before me, so that I can examine it and then implement the correct coding for my project.
Errors at getKey in Directory, boolean in Faculty...

Thank you in advance, Dicoder.

This post has been edited by pbl: 08 October 2012 - 01:41 PM
Reason for edit:: Correctly tagged code post below


Is This A Good Question/Topic? 0
  • +

Replies To: Java Directory Problem/Task question

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3553
  • View blog
  • Posts: 11,014
  • Joined: 05-May 12

Re: Java Directory Problem/Task question

Posted 05 October 2012 - 07:31 AM

Well, posting in the C# forum isn't going to help you much... Moving to Java...
Was This Post Helpful? 0
  • +
  • -

#3 dicoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-September 12

Re: Java Directory Problem/Task question

Posted 05 October 2012 - 10:50 AM

Sorry and thank you.
Was This Post Helpful? 0
  • +
  • -

#4 Kinaces  Icon User is offline

  • D.I.C Head

Reputation: 78
  • View blog
  • Posts: 230
  • Joined: 04-October 12

Re: Java Directory Problem/Task question

Posted 05 October 2012 - 10:55 AM

I will be glad to help out, but first I must ask that you put code tags around your code.
Was This Post Helpful? 0
  • +
  • -

#5 dicoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-September 12

Re: Java Directory Problem/Task question

Posted 07 October 2012 - 05:09 PM

View PostKinaces, on 05 October 2012 - 10:55 AM, said:

I will be glad to help out, but first I must ask that you put code tags around your code.


Thank you, I guess I did it incorrectly. I made changes and this is what I have; far from complete.
public class Directory
{
    // instance variables 
    private ArrayList<Persons> persons;
        
    /**
     * Construct Person list.
     */
    public Directory()
    {
        persons = new ArrayList<Persons>();
    }
           
    /**
     * Add a person to Directory.
     * 
     * @param persons Add new person.
     */
    public void addPerson(Persons newPerson)
    {
       persons.add(newPerson);
    }
       
     /**
     * Currently: print the Person details
     * to the terminal.
     */
    public void show()
    {
        // display all posts
        for(Persons person : persons) {
            
            System.out.println();   // empty line between posts
        }
    }
}
public class Persons
{
   // Persons fullName first and last
   public String fullName;
   // Persons e-mail address
   public String emailAddress;
   // Persons office (if any)
   public String officeNum;
    
  
   private ArrayList<String> persons;
   /**
   * Constructor for objects of class Person
   */
    public Persons(String person, String email, String office)
   {
       fullName = person;
       emailAddress = email;
       officeNum = office;

       persons = new ArrayList<String>();
   }
   
   /**
     * Adds new persons to directory.
     * 
     * @param text  New person to add.
     */
    public void addPerson(String person)
    {
        persons.add(person);
    }
      
   public String getKey(Persons newPersons)
   {
        return fullName;
   }
}
public class Students extends Persons
{
    private String classGrade;
    
    public  Students (String person, String email, String office, String status)
    {
            super(person, email, office);
            classGrade = status;
    }
    
    public String getStatus()
    {
        return classGrade;
    }
             
    public void printStatus ()
    {
        System.out.println ("Name: " + fullName  + " Email: " + emailAddress + " Office: " + officeNum + " Class: " + classGrade);
    }
}

public class Staff extends Persons
{
    // courtesy tile Mr., Ms., or Mrs...
    private String honorific; 
    public Staff (String person, String email, String office, String title)
    {
        super(person, email, office);
        honorific = title;
    }
    
    public String getTitle()//Mr. Mrs. Dr. or Prof.
    {
           return honorific;
     }
     
     public void display ()
     {
         System.out.println( honorific);
        }
 }
public class Faculty extends Persons 
{
   private boolean facultyMemberTenured;     
   
  public Faculty (String person, String email, String office,boolean tenured)
  {   
        super(person, email, office);
        facultyMemberTenured = tenured;
  }
 
  public void setTenured (boolean tenured)
  {
      this.facultyMemberTenured = tenured;
  }
    
  public boolean getTenured ()
  {
    return facultyMemberTenured; 
  }
      
    public void display()
  {
        System.out.println("faculty member is tenured: " + facultyMemberTenured);
  }
 }



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1