开发者

I need help on this homework/lab

I finished all the classes except for the student class. I don't understand how to approach it. Here is the prompt.

Extend the Person class developed in lab1 to derive classes for students, hourly employees, and full-time salaried employees. Determine an appropriate class inheritance hierarchy. These classes should have the following fields, necessary constructors, and appropriate access and modifier methods.

for all employees: *department

full-time employees: *salary

hourly employees: *hourly rate *number of hours worked each week(4weeks)

the hourly employee class should contain the necessary methods that will print the total hours (four- 开发者_StackOverflowweek total), average hours per week worked by each employee, and the total wages during a four-week period.

student: *classes taken and grades for each class (use an ArrayList)

The student class should contain the necessary methods to print the transcript for each student

(write a tester class to test your classes)

How should I use an arraylist for the student class?

I'm only going to post the relevant classes

public class Person { private String first; private String last; private static int idNumber = 1001; int Id ; private String full;


Person(){
     }

Person(String fn,String ln){
    first = fn;
    last = ln;
    Id = idNumber++;
    full = first +" "+ last;
    }


    static int getidNumber(){
        return idNumber;
    }

void setfirst(String fn) {
    first = fn;

}

String getfirst(){
    return first; }

void setlast(String ln){
    last = ln; }

String getlast(){
    return last; }


  @Override
    public String toString(){
        String blah = "First name: " +first+ "   Last Name:" +last+ "\tThe full name is: "+full+"  Id#"+Id;
        return blah;
    }


}


import java.util.*;


public class Student extends Person{

    Student (String fn, String ln){
        super(fn,ln);
    }



    }

Thank you in advance for all advices and suggestions.


I would use a map here, but since an ArrayList is required, I would do something like that:

public class Student extends Person {
    private List<ClassGrade> classes = new ArrayList<ClassGrade>();

    public List<ClassGrade> getClassGrades() {
        return new ArrayList<ClassGrade>(classes);
    }

    public void addClass(String clazz, int grade) {
        classes.add(new ClassGrade(clazz, grade));
    }

    public static class ClassGrade {
        String clazz;
        int grade;

        public ClassGrade(String clazz, int grade) {
            this.clazz = clazz;
            this.grade = grade;
        }

        public String getClazz() {
            return clazz;
        }

        public int getGrade() {
            return grade;
        }
    }
}


import static java.lang.System.*;
class Student extends Person
{
    protected int avMark;
        String classTaken

    public Student() 
    { 

    }
   public Student(String nameInput, int ageInput, String class) 
    { 
       super(nameInput, ageInput);
       classTaken = class;
     }

        public void setClasTaken(String className){
                classTaken = classname;
        }
        public String setClasTaken(){
                return classTaken;
        }
    public void register() 
    {
        super.register();
                out.println("Classes taken " +classTaken
        out.println("Average mark is   " + avMark);

    }
}

here is something to start you off this class inherits everything from the person class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜