Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Kindly follow the instruction and fill the missing codes and make it to work tha

ID: 3761543 • Letter: K

Question

Kindly follow the instruction and fill the missing codes and make it to work thanks

public class Rental
{
   private Rental[] rentals;

   /**
   * Constructor sets the size of the array.
   */
   public Rental(int numRentals)
   {
       rentals = new Rental[numRentals];
   }

   /**
   * setRental stores a reference to a Rental object
   * at the specified index.
   * @param rental The rental object to put in the array
   * @param index the position in the array to place the object
   */
   public void setRental(Rental rental, int index)
   {
       this.rentals[index] = rental;
   }

   /**
   * Return array of rentals
   * @return Rental[] array of rentals
   */
   public Rental[] getRentals()
   {
       return this.rentals;
   }

   /**
   * Iterate through the rental array and calculate
   * the total amount of late fees.
   */
   public double lateFeesOwed()
   {
       //need to complete this method
   }

   /** ======================
   *    main method.
   *    In main we simply create some sample movies and output the late fees.
   * ======================
   */
   public static void main(String[] args)
   {
       ActionMovie killbill2 = new ActionMovie(0, "Kill Bill: Volume 2", "R");
       ComedyMovie meangirls = new ComedyMovie(1, "Mean Girls", "PG-13");
       DramaMovie mystic = new DramaMovie(2, "Mystic River", "R");

       Question3Rental JoesRentals = new Question3Rental(3); // Joe is ID #1
       Rental rental1 = new Rental(killbill2, 1);
       Rental rental2 = new Rental(meangirls, 1);
       Rental rental3 = new Rental(mystic, 1);
       JoesRentals.setRental(rental1, 0);   // Add rentals to array
       JoesRentals.setRental(rental2, 1);
       JoesRentals.setRental(rental3, 2);
       // Make each movie 2 days late
       rental1.setDaysLate(2);
       rental2.setDaysLate(2);
       rental3.setDaysLate(2);
       // Calculate late fees
       System.out.println("With each movie 2 days late the late fees are " +
           JoesRentals.lateFeesOwed());
   }
}

Explanation / Answer

public class Rental
{
   private Rental[] rentals;

   /**
   * Constructor sets the size of the array.
   */
   public Rental(int numRentals)
   {
       rentals = new Rental[numRentals];
   }

   /**
   * setRental stores a reference to a Rental object
   * at the specified index.
   * @param rental The rental object to put in the array
   * @param index the position in the array to place the object
   */
   public void setRental(Rental rental, int index)
   {
       this.rentals[index] = rental;
   }

   /**
   * Return array of rentals
   * @return Rental[] array of rentals
   */
   public Rental[] getRentals()
   {
       return this.rentals;
   }

   /**
   * Iterate through the rental array and calculate
   * the total amount of late fees.
   */
   public double lateFeesOwed()
   {

   double sum = 0;
       for(int i = 0 ; i < rentals.length(); i++)

       sum += rentals[i].lateFees;

   return sum;
   }

   /** ======================
   *    main method.
   *    In main we simply create some sample movies and output the late fees.
   * ======================
   */
   public static void main(String[] args)
   {
       ActionMovie killbill2 = new ActionMovie(0, "Kill Bill: Volume 2", "R");
       ComedyMovie meangirls = new ComedyMovie(1, "Mean Girls", "PG-13");
       DramaMovie mystic = new DramaMovie(2, "Mystic River", "R");

       Question3Rental JoesRentals = new Question3Rental(3); // Joe is ID #1
       Rental rental1 = new Rental(killbill2, 1);
       Rental rental2 = new Rental(meangirls, 1);
       Rental rental3 = new Rental(mystic, 1);
       JoesRentals.setRental(rental1, 0);   // Add rentals to array
       JoesRentals.setRental(rental2, 1);
       JoesRentals.setRental(rental3, 2);
       // Make each movie 2 days late
       rental1.setDaysLate(2);
       rental2.setDaysLate(2);
       rental3.setDaysLate(2);
       // Calculate late fees
       System.out.println("With each movie 2 days late the late fees are " +
           JoesRentals.lateFeesOwed());
   }
}