1 з 20

Answering Questions

about Programming

CMPS 5J

January 23, 2019

2 з 20

Announcements

3 з 20

First external guest speaker confirmed (next Friday)

She will address some specific questions from L02:

  • Why are different (programming) languages better at different things?
  • How do you do projects that involve multiple languages?
  • What’s the difference between coding and programming?

Also, she will break down a programming project done for social activism, not for a job or for school.

4 з 20

Scoring for R05 (“Coding is not difficult”) will be slow

You only wrote two paragraphs,�but we now have 840 paragraphs to read.

Meanwhile, coding actually is difficult for most people most of the time if they keep advancing in the difficulty of projects they take on.

5 з 20

You don’t need to do all of Digital Information

You only need to do lessons 1-6 (the assignment on Canvas also mentions this).

When you get to 2.3.9 (Text to Binary) and you need to write a JavaScript program, feel free to use the code given on Canvas: https://canvas.ucsc.edu/courses/19599/discussion_topics/73151

6 з 20

Who is not on Piazza for this class? (163 of you?)

Click this link to sign up: https://piazza.com/ucsc/winter2019/cmps5j01

(this link can also be found on the syllabus and in a dedicated Canvas announcement)

7 з 20

Please fill out the course feedback form (just 5% have so far)

https://canvas.ucsc.edu/courses/19599/discussion_topics/72927

Some items for right now:

  • Clarify grading scale and assignment weights (See syllabus.)
  • Notifications for new assignments (Check your Canvas settings.)
  • “reading normal questions without attempts” (?)
  • Stop games in lab. (They are over now)
  • Stop children’s books. (Don’t worry, it was a one-off thing.)
  • College-specific meetups and concept lists. (You’ll see these next week.)
  • CodeHS points in Canvas. (You won’t see this until finals week, don’t wait.)

8 з 20

Current Events

9 з 20

Monday was MLKjr Day

The relevance of race and discrimination is sharply relevant to programming, particularly now in 2019.

10 з 20

11 з 20

12 з 20

Yesterday on Twitter

13 з 20

Answering Questions

about Programming

This is what you’ll need to do on the exams in this class.

You’ll need conceptual knowledge and practical skills.

14 з 20

Which for-loop headers will execute a block 8 times?

for(int i = 0; i < 8; i++) // ? times

for(int i = 1; i <= 8; i++) // ? times

for(int i = 1; i < 8; i++) // ? times

for(int i = 0; i < 80; i+=10) // ? times

for(int i = -4; i < 4; i++) // ? times

15 з 20

What kind of Java construct is each underlined term?

class MySolution extends Solution

{

public int roundToTens(int x)

{

return 10 * (( x + 5) / 10);

}

}

Options: class, type, method, variable, keyword

Extended options: function, procedure

Not an option: private void

16 з 20

Which programs result in equivalent behavior?

class A extends SuperKarel

{

public void run()

{

move();

move();

turnLeft();

move();

turnRight();

move();

move();

move();

turnLeft();

move();

turnRight();

move();

}

}

class B extends SuperKarel�{� public void run()� {� for(int i = 0; i < 8; i++)� {� move();� }� for(int i = 0; i < 2; i++)� {� turnLeft();� turnRight();� }� }

}

class C extends SuperKarel�{� public void run()� {� step();� step();� }�� private void step()� {� move();� move();� turnLeft();� move();� turnRight();� move();� }�}

17 з 20

Pick the appropriate data type

You are a developer at video streaming company Youku, and you are working on the Android mobile app. The app is mostly written in the Java programming language.

You know that popular shows like Love O2O (a show about programmers in college, and more) can have over 24 billion views.

Which of Java’s integer types could accurately represent video view counts in the mobile app? Reference: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

Options: byte, short, int, long, float, double, char, boolean

18 з 20

What does this method do?

int f(int a, int b) �{ � if (a == 0) { return b; } � if (b == 0) { return a; }� if (a == b) { return a; }� � if (a > b) {� return f(a-b, b);� } else {� return f(a, b-a); � }�}

Options:

  • f(a,b) computes a multiplied by b.
  • f(a,b) computes the maximum of a and b.
  • f(a,b) computes the greatest common denominator of a and b.
  • f(a,b) computes a to the b-th power.

19 з 20

What’s the biggest problem?

public int pow(int x, int y)�{� int result = x;� while(y > 1)� {� if (y % 2 = 0) // y is even� {� result *= result;� }� else� {� result *= result * x; � }� y /= 2;� }� return result;�}

Your friend is implementing a method that will compute x to the y-th power, but something is wrong. What the biggest problem?

Options:

  • “y > 1” should be “y > 0”
  • “y % 2 = 0” should be “y % 2 == 0”
  • “y /= 2” should be “y \= 2”
  • It produces incorrect results when y is less than 1.

20 з 20

Translate from Python (or another language with Java-like structures)

def countFactors(x, n):� num = 0� while x % n == 0:� num += 1� x /= n� return num��print(countFactors(518400,3))

Translate this simple program from Python into Java. What does it print?

Options: 8, 4, 0, 5