0

Hi every1, i have trouble doing my homework. Could anyone help. the probelm is everytime when i set the degree and it prints out the last degree i entered. when i use the default constructor (withour entering any infomation) to create the UndergradStudent instance, it doesn't allow me to set the degree. :-|

Here are my codes:

public class UndergradStudent extends CollegeStudent
{   
    public UndergradStudent()
    {
        super();
    }

    public UndergradStudent(String studentName, String studentId,
                          int graduationYear, String degreeSought)
    {
        super(studentName, studentId, graduationYear, degreeSought); // must be first
    } // end constructor

   public void setDegree(String degreeSought)
    {   if (degree=="BA")
          { degree = degreeSought;
            System.out.println("This studet has assigned to a BA degree.");

        }
         else if (degree == "BS")
               {degree = degreeSought;
                System.out.println("This studet has assigned to a BS degree.");
            }
           else
            {   degree="";
                System.out.println("Undergraduate student could only assign to a BA or BS degree");
             }
    }       

     public String getDegree()
    {
        return degree;
    }// end getDegree

}

If you need to see my superclass code, please check my attachment

Edited by pyTony: fixed formatting

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by masijade
0

I've not really looked at you code, but for string comparisons it would be better to use the string.compare() method instead of the == operator.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.