0

Today my teacher told me that I did my Student class wrong. I made it my main class, but he said it wasn't supposed to be the main class--so yes, this is a homework question. I would like to know what I should add to do to my subclass make the Student class, I suppose, connect (for a lack of a better word--I'm tired I guess) the three other classes to Student (I don't know if that made sense, just keep going and hopefully it starts making more sense).

Here are the specifics: I created three student instances, each student from different schools, with different grade levels, different social security numbers, etc. I did the same for all of them, so here is the class for a student from Colorado College:

public class UCCSStudent {

    String firstName;
    String lastName;
    String gradeLevel;
    int age;
    private int ssNum;
    private static int numOfObj;
    private String campus;

    UCCSStudent(){
        firstName = "Jane";
        lastName = "Lo";
        gradeLevel = "Junior";
        age = 22;
        ssNum = 90123456;
        campus = "The University of Colorado at Colorado Springs";
        numOfObj++;
    }

        int getssNum(){
    return ssNum;
}

void getssNum(int thenewSsnum){
    ssNum = thenewSsnum;
}

String getcampus(){
    return campus;
}

void setcampus(String anotherCampus){
    campus = anotherCampus;
}

static int getnumOfObj(){
    return numOfObj;
}

public String toString(){
        return "The first name of this student is: " + this.firstName + ", the "
                + "last name of this student is: " + this.lastName + ", the "
                + "student ID of this student is: " + this.getssNum() + ", the "
                + "grade level of the student is: " + this.gradeLevel + ", & the "
                + "campus this student goes to is: " + this.getcampus() + ".";
    }
}

And then this is my Student class. From what I understood, this class is the "recipe for creating instances"--this is what I have as of now:

public class Student {

    //declare variables
    String firstName;
    String lastName;
    String gradeLevel;
    int age;
    private int ssNum;
    private static int numOfObj;
    private String campus;

}

(I'm doing this so you guys don't think I haven't started or something)

I hope I was specific enough. So, anyways, in case my question was lost in all the action: What should I add to Student now? The purpose of the homework is to "design a hierarchy of classes and subclasses"

Please Note: I don't need the specific code, just what to do next. EDIT: The student class was the main class, but isn't anymore. I took out the public static void main(String[] args)

  • Not sure what you are asking: There is no relationship between the 2 classes you've shown... – John3136 Jun 30 '14 at 23:42
  • `UCCSStudent` is not a subclass of `Student`, if that's part of your homework. In Java, you should use the `extends` keyword to notify a class extends (is a subclass of) some class. – Luiggi Mendoza Jun 30 '14 at 23:42
  • By "a hierarchy of classes" your instructor expects you to implement an **inheritance** hierarchy. Official Oracle java inheritance tutorial page: http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html – Matt Coubrough Jun 30 '14 at 23:42
  • Okay, thanks, Matt C, I'll look at the tutorial page. I wasn't sure what my professor wanted. And to Luiggi M, thank you as well. To John, the Student class was originally my main class, and UCCSStudent was supposed to be the class after it. But the teacher said it was wrong, and said it was supposed to be the class that had three subclasses (in this case, the student objects), so I took out the public static void main(String[] args) part from Student –  Jun 30 '14 at 23:48
  • You also miss the concepts of what class and what objects is. The class is what you write. The object is what computer create after operator `new`. – Damian Leszczyński - Vash Jun 30 '14 at 23:52
  • Hi Vash, I created a new main(), that's where I created the objects. –  Jun 30 '14 at 23:54
  • finally, a honest student asking a honest question in stack overflow. – Leo Jul 01 '14 at 00:00
  • 1
    I think that if your professor has been unclear, then Stack Overflow isn't the best place to find out what he/she meant. We're a bit low on psychic powers around here. Go and talk to your professor - that's what you've paid him/her for. – Dawood ibn Kareem Jul 01 '14 at 00:19
  • Hi, David, I will be able to talk to my professor today--I did figure it out. The reason I was asking StackOverflow was because I thought I understood what the professor was saying, but realized my mistake later. By that time, my professor left the office so I decided to turn to Stack Overflow just to get a better idea, and to get a quicker answer. Yes I should've asked my professor, and I do talk to my professor, so it has nothing to do with the fact that I can't communicate with him. Yes, I paid for the class, but I see nothing wrong with consulting an outside source that is just as helpful –  Jul 02 '14 at 16:52
  • Oh, and sorry for the lack of clarity. I thought I made it clear enough, but I suppose I was just all over the place. This was simply concerning classes and subclasses. –  Jul 02 '14 at 16:59

1 Answers1

0

I would like to know what I should add to do to my subclass make the Student class

  • Here, you should not add anything to my subclass to make the Student class. Student class is the super class. So, all the parent implementations must be there. You should add extends to subclass to make it a child (subclass) of Student class. eg:

    public class UCCSStudent extends Student {

    // UCCSStudent logics

    }

I suppose, connect (for a lack of a better word--I'm tired I guess) the three other classes to Student

  • Here, the correct word is not extends not connect. You are extending the behaviour of the parent class by sub-classing it.

so here is the class for a student from Colorado College:

  • Here, until you dodn't extend it to Student it is not a Student class. (public class UCCSStudent extends Student). You should understand about the subclassing and the polymorphism. Just google, there's a ton.

References :

Community
  • 1
  • 1
ironwood
  • 8,936
  • 15
  • 65
  • 114
  • Thank you, Namalak! I was able to figure it out, so I'll see how the professor likes it today. –  Jul 02 '14 at 16:47