Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

email address through a substring

Options
  • 26-02-2008 4:18pm
    #1
    Closed Accounts Posts: 20


    this is recking my head
    public abstract class Person
    {
    //Private Variables
    protected String firstName;
    protected String lastName;
    protected int credits;
    protected int status;
    private String initials;

    //Default Constuctor
    public Person()
    {
    firstName = "Joe";
    lastName = "Duffy";
    }

    // Construct for a Person
    public Person(String firstname, String lastname)
    {
    this.firstName=firstName;
    this.lastName=lastName;
    }
    //Getter method for first name
    public String getFirstName()
    {
    return firstName;
    }

    // Setter method for color
    public void setFirstName(String firstName)
    {
    this.firstName = firstName;
    }


    //Getter method for last name
    public String getLastName()
    {
    return lastName;
    }

    // Setter method for last name
    public void setLastName(String lastName)
    {
    this.lastName = lastName;
    }



    public String showInitials(String fname,String lname)
    {
    String initials = fname.substring(0, 1)
    + lname.substring(0, 1);

    }
    // Abstract method
    public abstract String makeEmail();


    }

    //public String toString()
    //{
    // return "name is " + name + "balance is " + balance;
    //}




    public class Student extends Person
    {

    private int credits;
    private int status;

    //Default Constuctor
    public Student()
    {
    this("Joe","Duffy",21,1);
    }

    // Construct Student with specified credits and status
    public Student(int credits,int status)
    {
    super("Joe","Duffy");
    this.credits=credits;
    this.status=status;
    }

    // Construct a Student object with specified firstname,lastname, credits and status
    public Student(String first, String last,int credits,int status)
    {
    super(first, last);
    this.credits = credits;
    this.status = status;
    }

    public int getCredits()
    {
    return credits;
    }

    public void setCredits()
    {
    this.credits=credits;
    }

    public void addCredits(int additionalPoints)
    {
    credits = credits + additionalPoints;
    }


    public int getStatus()
    {
    return status;
    }
    help if you can


Comments

  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    What exactly is it your trying to do? Have a read of this too, it will help a lot.

    I understand that when starting to code its frustrating and difficult but you won't learn anything unless you make the effort yourself. You need to read the link above if you don't want future threads locked.


  • Closed Accounts Posts: 198 ✭✭sh_o


    Your assignment in the constructor looks incorrect for a start, also revise how assigning variables works


  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    also have a look at your setter (setCredits()) method.


  • Registered Users Posts: 1,322 ✭✭✭Mad_Max


    Very odd.

    Someone who doesn't seem to understand parameters and variable assignment but yet seems to be using protected variables and abstract classes/methods ok. Smells like some ctrl-a -> ctrl-v. :D


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Yeah I know its a duplicate thread everyone but I'm going to allow as the op is new to programming.

    heavy482 it would probably be better if you kept to the one thread for the one problem. Makes it easier for people to follow what your doing.


  • Advertisement
  • Registered Users Posts: 1,322 ✭✭✭Mad_Max


    Ok here's a few helping points:

    1:
    The second Person constructor. Your parameters here are called "firstname" and "lastname". These are the values that are passed into the constructor when you call it.
    e.g. Person paul = new Person("Paul","Simpson");
    What this will do then is assign these values to the instance variables you have called firstName and lastName

    public Person(String firstname, String lastname)
    {
    this.firstName=firstname;
    this.lastName=lastname;
    }

    This would be correct, it was only a small typo but would cause logical problems.

    2:
    Your showInitials method wont compile as you haven't specified what to return. So "return initials;" would be needed as you have saved them to the variable initials.

    3:
    In the Person class, your setCredits method needs a parameter too. Treat it as shown above.

    Hope this helps you understand the basic errors.


Advertisement