Question

In: Computer Science

Give an example of how to build an array of objects of a super class with...

Give an example of how to build an array of objects of a super class with its subclass objects. As well as, use an enhanced for-loop to traverse through the array while calling a static method(superclass x). Finally, create a static method for the class that has the parent class reference variable.

Solutions

Expert Solution

​
public class Colleges

    {

    private static Teacher[] teachers;

    public Colleges()

    {

    teachers= new Teacher[]{new Dean("Sapo",10000),new Teacher("James",5000),new Teacher("Jessie",5001)};

    }

    public static void main(String[] args)

    {

        Colleges colleges= new Colleges();

        teachers[0].setBonus(50);

        System.out.println(teachers[0].getBonus());   

    }

    }

 

public class Teacher extends Person
{

 int salary;
public Teacher(String name,int salary) {
    super(name);
    setSalary(salary);

    // TODO Auto-generated constructor stub
}

public void setSalary(int salary)
{

    this.salary= salary;
}

public int getSalary()
{

    return salary;
}

}

 

public class Dean extends Teacher {
  private final int bonus;

 
  public Dean(String name, int salary, int bonus) {
    super(name, salary);
    this.bonus = bonus;
  }


 
  @Override
  int getSalary() {
    return super.getSalary() + bonus;
  }


​

Related Solutions

Programming Questions: 1) How do you build an array of objects of a superclass with its...
Programming Questions: 1) How do you build an array of objects of a superclass with its subclass objects? 2) How do you use an enhanced for-loop to traverse through an array while calling a static method(superclass x)? 3) How do you create a static method for a class that has the parent class reference variable? **Include java coding examples for each question if possible
Javascript array of objects: I'm trying to get the input into an array of objects, and...
Javascript array of objects: I'm trying to get the input into an array of objects, and then display the information in a table using a for loop, but I don't think my path is right <!DOCTYPE html> <head> <title>Form</title> <meta charset="utf-8" /> <style media="screen"> h1 { text-align: center; } div { background-color: #pink; border: 2px solid green; padding: 15px; margin: 65px; } </style> <script> var list = []; total = 0; text = ""; function Product(item, quantity, costs){ this.item =...
How to build the dual model of the creek company's example and give a explaination of...
How to build the dual model of the creek company's example and give a explaination of the dual model and shadow prices of the problem, and how to get it.
For this assignment you will implement a dynamic array. You are to build a class called...
For this assignment you will implement a dynamic array. You are to build a class called MyDynamicArray. Your dynamic array class should manage the storage of an array that can grow and shrink. The public methods of your class should be the following: MyDynamicArray(); Default Constructor. The array should be of size 2. MyDynamicArray(int s); For this constructor the array should be of size s. ~MyDynamicArray(); Destructor for the class. int& operator[](int i); Traditional [] operator. Should print a message...
Learning Outcomes Using Java, maintain a collection of objects using an array. Construct a class that...
Learning Outcomes Using Java, maintain a collection of objects using an array. Construct a class that contains an array as a private instance variable. Construct methods with arrays as parameters and return values. Use partially filled arrays to implement a class where objects can be dynamically added. Implement searching and sorting algorithms. Instructions For this assignment you will be implementing an application that manages a music collection. The application will allow the user to add albums to the collection and...
please use C++ Create a class named Byte that encapsulates an array of 8 Bit objects....
please use C++ Create a class named Byte that encapsulates an array of 8 Bit objects. The Byte class will provide the following member functions: Byte - word: Bit[8] static Bit array defaults to all Bits false + BITS_PER_BYTE: Integer16 Size of a byte constant in Bits; 8 + Byte() default constructor + Byte(Byte) copy constructor + set(Integer): void sets Bit to true + clear(): void sets to 0 + load(Byte): void sets Byte to the passed Byte + read():...
Define parallel arrays, tell how the data in each array is accessed and give an example...
Define parallel arrays, tell how the data in each array is accessed and give an example of parallel arrays.
What does the super keyword represents and where can it be used? Give an example of...
What does the super keyword represents and where can it be used? Give an example of a superclass and subclass. Be sure to make all the instances variables of the super class private. Include at least one constructor in each class and ensure that the constructor of the subclass calls the constructor of the superclass. Also include a toString method in both classes that returns the values of the instance variables with appropriate labels. Ensure that the toString method of...
Give an example of an inner and outer class. (Java)
Give an example of an inner and outer class. (Java)
1. Give an example of the 4 steps of the scientific method as applied to objects in motion
    1. Give an example of the 4 steps of the scientific method as applied to objects in motion 2.  A mass of 10 Kg is accelerating at 3 m/s2. What is the applied net force? 2. A mass of 10 Kg is accelerating at 3 m/s2. What is the applied net force?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT