COMPUTER SCIENCE AP EXAM 2020

(COVID-19 ABBREVIATED EXAM)

 

 

CAMPEAU’S ATTEMPT AT QUESTION 1

 

Full disclaimer: I read part of this question a week ago.  I don’t remember the content now but I’m sure it will comeback to me quickly once I start.  So I do have a time advantage here.

 

TWENTY FIVE MINUTES STARTING…NOW

 

CAMPEAU’S SOLUTIONS

 

PART A)


TIME STAMP: 12:41PM

 

public int countElectronicsByMaker(String maker)

{

   int count = 0;

   for(int i=0; i<purchases.size(); i++)

   {

      Gizmo g = purchases.get(i);

      if(g.getMaker().equals(maker) && g.isElectronic())

      {

         count++;

      }

   }

   return count;

}

 

TIME STAMP: 12:48PM

 

PART B)

 

/** Returns true if any pair of adjacent purchased Gizmo objects are equivalent, and

* false otherwise, as described in part (b).

*/

public boolean hasAdjacentEqualPair()

{

  

   for(int i=0; i<purchases.size()-1; i++)  //-1 is needed

   {

      if(purchases.get(i).equals(purchases.get(i+1))

      {

         return true;

      }

   }

   return false;

}

 

TIME STAMP: 12:52PM

 

PART C)

 

public Gizmo getCheapestGizmoByMaker(String maker)

{…}

 

To implement this, a few minor changes need to be done :

  • The Gizmo class requires an instance variable for price

    private double Gizmo;

 

  • The Gizmo class requires a get method for price :

    public double getPrice()
    {…}

 

We now have the ability to iterate over the ArrayList purchases and compare both maker and price to find the lowest price found so far of that maker.  This becomes a simple search for the minimum value problem.

 

We could also use the Comparable interface to compare Gizmo objects by price.  Having this implementation would allow us to easily sort the Arraylist by price.  Then, the implementation of the getCheapestGizmoByMaker method would simply need to search for the first occurrence of a Gizmo with the desired maker.

 

TIME STAMP: 1:05PM

 

 

 

POST-QUESTION COMMMENTS

 

I did not take the remaining two minutes to read over my answers.  I should have though as I would have changed a few things!

 

Working in Word is a pain.  I had to change some auto corrections several times – notably the capitalization of the first letter.  Also, my Word document was in French mode and that caused issues with typing certain symbols.  Overall, these were pains, but I was able to work through them with minor delays.

I also opted to use the font COURIER NEW for the coding as it is monospaced and allows for everything to line up nicely.

 

I will try the next question in Eclipse to see if it is easier to work in an IDE.

 

CRITIQUE OF ANSWER A

 

I made an important error.  I forgot to return the variable count.  I added the statement above and highlighted it in yellow.  Ouch!  L

 

CRITIQUE OF ANSWER B

 

I think this is correct.

 

CRITIQUE OF ANSWER C

 

It is hard to tell how much information we should include for this.  I think they are looking for evidence that you clearly understand what is going on and that you also clearly understand OOP concepts.

 

I do feel that my last paragraph lacks clarity.  I should certainly have elaborated more.  For example, I didn’t even mention which class (Gizmo) would implement Comparable.  That is an important omission.

 

THOUGHTS ON THE QUESTION

 

If time is not an issue, students should be able to answer all questions fairly easily.  But timing is a big deal.  So is the fact that you don’t have all implementations in front of you.