I have a homework question that I'm a little thrown off by. Mostly because we haven't messed with strings much in class. Any help would be greatly appreciated.

Using the UML class diagram as a reference, complete the Student class declaration. (fill in the blanks)

class Person {
public String firstName;
public String lastName ;

public _____() { // constructor
lastName = "";
}

public void PayFees(double fee) {
/* ... */
}
} // end Person

class Student _________ __________ {
public String __________ ;

public void ChangeMajor(String major) { 
__Major___ = major;
/* ... */
}

public void PayFees(double fee) {
/* … */ 
}
} // end 

UML Diagram:
Person
______
firstName : String
lastName : String
_______
PayFees(double)
^
|
|
Student
______
major : String
_________
ChangeMajor(String)
PayFees(double)

What I need is the blanks filled in the Java code above. Thanks for your help

Err... How about you do it yourself first? And then ask us whether or not it is correct. I am not going to do your homework for you but I could help you correct it.

Ok, here's my guess. I didn't think that you would know what I was trying to do if I had my blanks filled in... Thanks

class Person {
  public String firstName;
  public String lastName ;

  public __void___() { // constructor
    lastName = "";
  }

  public void PayFees(double fee) {
      /* ...  */
  }
}  // end Person

class Student ____extends__    ____Person {
  public String ____Major______ ;

  public void ChangeMajor(String major) {         
   __this.Major___ = major;
     /* ... */
  }

   public void PayFees(double fee) {
    /* …  */ 
   }
}  // end 

You need to check the syntax for a constructor...

Ok how about now?

class Person {
  public String firstName;
  public String lastName ;
  public __Person___() { // constructor
    lastName = "";
  }
  public void PayFees(double fee) {
      /* ...  */
  }
}  // end Person
class Student ____extends__    ____Person {
  public String ____Major______ ;
  public void ChangeMajor(String major) {         
   __this.Major___ = major;
     /* ... */
  }
   public void PayFees(double fee) {
    /* …  */ 
   }
}  // end 

That looks good. :) You could remove all underscores (_) from the line though.

Thanks for all of your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.