-1

So I have a class called student and one of the variables is tuition rate, i want to set the tuition in the other class but i dont want to make the variable public, is there a way to do it?

Heres my first part of code from the abstract class Student

public abstract void setTuition(double rateIn);


public abstract double getTuition();

abstract String Display()

now heres where im trying to override the tuition in the Undergraduate class

@Override
  public void setTuition(double rateIn){
       rateIn=200*super.getHours();

  }
  
 
          
  
  @Override
  public String Display(){
    
      
      
              
      return("name "+super.getLastName()+", "+super.getFirstName()+"\n"+
                         "ID "+super.getStudentId()+"\n"+
                         "Enrollment "+super.getHours()+"\n"+
                         "tuition $"+());
      //Here i need the variable so i can print it out
      
  }
  

(I know there isnt a get method but i have added one i just forgot to put it in)

All i need is a way to print out the variable

1 Answers1

0

You do not need to expose the tuition var, just call the Student(parent class) setTuition method:

@Override
public void setTuition(double rateIn){
    rateIn=200*super.getHours();
    super.setTuition(rateIn);
}

Then just use getTuition provided by Student:

@Override
  public String Display(){              
      return("name "+super.getLastName()+", "+super.getFirstName()+"\n"+
                         "ID "+super.getStudentId()+"\n"+
                         "Enrollment "+super.getHours()+"\n"+
                         "tuition $"+ super.getTuition);
      
  }
marcellorvalle
  • 1,631
  • 3
  • 17
  • 30