0% found this document useful (0 votes)
24 views2 pages

Activity #6 Practical Exam (Implementing Inheritance, Polymorphism, Abstract Classes)

Uploaded by

Erika Episcope
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Activity #6 Practical Exam (Implementing Inheritance, Polymorphism, Abstract Classes)

Uploaded by

Erika Episcope
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

ACTIVITY #6 PRACTICAL EXAM (IMPLEMENTING INHERITANCE, POLYMORPHISM,

ABSTRACT CLASSES)

public abstract class Student  { public class Bsit extends Student  {


  private String name;
private double labHours;
public Student(String name)  { private double labFee;
      setName(name); private double tuition;
   }
  public String getName()  { public Bsit(String name, double tuition, double
      return new String(name); labHours, double labFee)  {
   }       super(name);
        setTuition(tuition);
  private void setName(String name)  {       setLabHours(labHours);
      this.name = new String(name); setLabFee(labFee);
   }    }
   
public void setTuition(double tuition)  {
public String toString()  {       this.tuition = tuition;
      return "name is " + name;    }
   } public void setLabHours(double labHours)  {
      this.labHours = labHours;
  public abstract double computePay();    }
  public void setLabFee(double labFee){
} this.labFee = labFee;

public double getTuition()  {
      return tuition;
   }
public double getLabHours()  {
public class NotIT extends Student  {       return labHours;
   }
  double miscFee; public double getLabFee(){
  
return labFee;
}
public NotIT(String name, double
 
miscFee)  {
public String toString()  {
      super(name);
      return super.toString() + " (tuition is "
      setmiscFee(miscFee);
+ tuition + " lab hours are " + labHours + "
   }
lab fee is " + labFee + ')';
 
}
   public void setmiscFee(double
}
miscFee)  {
      this.miscFee = miscFee;
   }
 
   public double getmiscFee()  {
      return miscFee;
   }
     
   public String toString()  {
      return super.toString() + "
(miscFee is " + miscFee + ")";
   }  
}
ANSWER THE FOLLOWING QUESTIONS
1)For both subclasses create an implementation method of the abstract method computePay. The method pay should compute the
payment to be paid by a student during registration. NonIT students will pay the same amount as their miscellaneous fee. BSIT
students will pay the total of their tuition fee and laboratory fee. The laboratory fee is computed by labHours times labFee (10 pts)
2)Explain how the method toString works.(10 pts)
3)Explain how each constructor of the subclasses works.(10 pts)
4)Create a class that will implement the given classes above including the methods that you created in item 1. You can apply any
output enhancements like using JOptionPane, etc. Your practical exam grade will depend on your output on this activity.(20 pts)

EXAMPLE:

public class Test {


   public static final int MAX_STUDENTS = 1000;
   public static void main(String[] args)  {
      Student[] students = new Student[MAX_STUDENTS];
 
      int stud = 0;
     students [stud ++] = new Bsit("George Jones", 3075.00, 2.5,300);
students [stud ++] = new NonIT("Dolly Parton", 500);
  }
}
SAMPLE EXPECTED OUTPUT:

MENU: MENU:
[A]ADD [A]ADD
[D]DISPLAY [D]DISPLAY
[E]EXIT [E]EXIT
A A

CHOOSE EMPLOYEE TYPE CHOOSE EMPLOYEE TYPE


[B]BSIT [B]BSIT
[N]NonIT [N]NonIT
B N

HOW MANY ENTRIES? : HOW MANY ENTRIES? :


2 1

Enter name: Emp Anada Enter name: Pan Desali


Enter tuition: 1000 Enter misc Fee: 1000
Enter labFee: 100
Enter labHours: 2.5
MENU:
Enter name: Pan Decoco [A]ADD
Enter tuition: 3000 [D]DISPLAY
Enter labFee: 200 [E]EXIT
Enter labHours: 2.5 D

MENU: NAME PAYMENT AMOUNT


[A]ADD Emp Anada 1250
[D]DISPLAY Pan Decoco 3500
[E]EXIT Pan Desali 1000
D
MENU:
  NAME PAYMENT AMOUNT [A]ADD
Emp Anada 1250 [D]DISPLAY
Pan Decoco 3500 [E]EXIT
E

You might also like