COMPUTER SCIENCE AP EXAM 2020

(COVID-19 ABBREVIATED EXAM)

 

 

CAMPEAU’S ATTEMPT AT QUESTION 2

 

I don’t have a clue what this question is about.  I am nervous!  J

 

FIFTEEN MINUTES STARTING…WHAT?  ONLY FIFTEEN?  HOLY SMOKERS!!!  …NOW

 

CAMPEAU’S SOLUTIONS

 

PART A)


//TIME STAMP: 2:56PM

//TIME STAMP: 3:03PM just figured it out!  ahh!

   

public boolean isValid(int numWithCheckDigit)

{

    String n = "" + numWithCheckDigit;

    String n1 = n.substring(0,n.length()-1);

    String n2 = n.substring(n.length()-1,n.length());

    int num1 = Integer.parseInt(n1);

    int num2 = Integer.parseInt(n2);

    return getCheck(num1) == num2;

}

 

//TIME STAMP: Done at 3:07PM

//Note: method signature = method prototype

 

PART B)

 

I would include a private instance variable in the class CheckDigit called falseCount.

 

private int falseCount;

 

I would include a get method for that instance variable.

 

I would alter the end of my isValid method to include an if statement.  If the check is valid, return true.  Otherwise, increase falseCount by 1 and return false.

 

//TIME STAMP: Done at 3:11PM

 

 

 

POST-QUESTION COMMMENTS

 

First things first, I would not write paragraphs in an IDE.  Its messy and it did bother me when I was writing my answer.  Now for the coding, the IDE was useful.  So I think I would have both an IDE file and a Google doc file ready to use.

 

Second, my thought is this is an easy question that is confusing to understand.  Perhaps the stress of the 15 minute deadline was a lot.  I know when I read it initially, I was questioning if I lacked knowledge about check digits.  Once I understood how things worked, then it was quite easy.

 

CRITIQUE OF ANSWER A

 

I think one way of getting the rightmost digit is to MOD by 10.  And we could simply divide by 10 to get the rest of the number.

 

So, my first five lines of code could be replaced by

 

   int num1 = numWithCheckDigit / 10;   //all but rightmost digit

   int num2 = numWithCheckDigit % 10;   //rightmost digit

 

That would be a three-line answer which would be nice.

 

CRITIQUE OF ANSWER B

 

I could clearly have added details here.  I think I would have used an extra minute to read over this content and add a few extras.

 

Also, I incorrectly wrote n2 instead of num2.  I have indicated corrected that above (in yellow).

 

THOUGHTS ON THE QUESTION

 

Fifteen minutes goes by too fast!  I do feel that question was needlessly confusing.  Better examples would make a big difference.  I did expect more advanced concepts to come up in this question but that was not the case.