Unit 3 · 12 min

3.2 Impact of Program Design

Good program design includes thinking about who the program might fail, harm or copy from.

Summary, objectives and course and exam description (CED) codes

System reliability means a program performs its tasks as expected under stated conditions without failure, so programmers test it with a variety of conditions. Programs affect society, the economy and culture in good and harmful ways, sometimes beyond their intended use. Reusing code raises legal and intellectual property questions: open source code is free to use, other code needs permission and often payment.

By the end of this session you can

  • 3.2.A Explain the social and ethical implications of computing systems.

3.2.A3.2.A.13.2.A.23.2.A.3

Reviewed against the CED on

Know this already? Jump to the checkpoint.

1LearnThe notes, the traps and how to remember them

1. System reliability: test with many conditions

System reliability means the program can perform its tasks as expected under stated conditions without failure 3.2.A.1. Programmers should try to maximize reliability by testing the program with a variety of conditions 3.2.A.1.

Here is a method that turns a quiz score into a percent. It works on the first test, so it looks finished.

public class QuizScore
{
    public static int percent(int correct, int total)
    {
        return correct * 100 / total;
    }
}
System.out.println(QuizScore.percent(18, 20));
System.out.println(QuizScore.percent(0, 20));
System.out.println(QuizScore.percent(5, 0));

Output:

90
0
Exception in thread "main" java.lang.ArithmeticException: / by zero

The third test, a quiz with no questions yet, makes the program fail with a run-time error. A good test plan includes:

Kind of test Example input Why
Typical value 18 out of 20 The normal case works.
Boundary value 0 out of 20, 20 out of 20 The smallest and largest results are correct.
Unusual value 5 out of 0 The program does not crash on input it did not expect.

The improved version states its behavior for the unusual case, so it works as expected under all stated conditions:

public class QuizScore
{
    /** Returns the percent correct, or 0 when total is 0 */
    public static int percent(int correct, int total)
    {
        if (total == 0)
        {
            return 0;
        }
        return correct * 100 / total;
    }
}
System.out.println(QuizScore.percent(18, 20));
System.out.println(QuizScore.percent(20, 20));
System.out.println(QuizScore.percent(5, 0));

Output:

90
100
0

2. Programs have beneficial and harmful impacts

Creating a program has impacts on society, the economy and culture, and these impacts can be both beneficial and harmful 3.2.A.2. A program meant to fill a need or solve a problem can have unintended harmful effects beyond its intended use 3.2.A.2.

Program Beneficial impact Possible harmful impact
A route planner Drivers save time and fuel (economy). It sends heavy traffic through quiet streets next to a school (society).
A music recommendation app Listeners discover new artists (culture). It keeps showing the same popular songs, so small artists are heard less (culture, economy).
An online grade portal Students see their progress quickly (society). Students without home internet see it later than others (society).

The route planner problem can start with one design choice in the code. This method only looks at travel time:

public class RoutePlanner
{
    public static String choose(int mainRoadMinutes, int sideStreetMinutes)
    {
        if (sideStreetMinutes < mainRoadMinutes)
        {
            return "side street";
        }
        return "main road";
    }
}
System.out.println(RoutePlanner.choose(14, 12));

Output:

side street

Every user gets the same answer, so thousands of cars go down the side street. A more careful design adds a condition the designers care about, such as avoiding a school zone during school hours:

public class RoutePlanner
{
    public static String choose(int mainRoadMinutes, int sideStreetMinutes,
                                boolean schoolHours)
    {
        if (sideStreetMinutes < mainRoadMinutes && !schoolHours)
        {
            return "side street";
        }
        return "main road";
    }
}
System.out.println(RoutePlanner.choose(14, 12, true));
System.out.println(RoutePlanner.choose(14, 12, false));

Output:

main road
side street

Watch out: on the AP® exam, an “impact” answer should name who is affected and how. “It is bad for people” is too vague; “it increases traffic danger near a school” is specific.

Code is intellectual property: it belongs to the person or company that wrote it. Legal issues and intellectual property concerns arise when you create programs 3.2.A.3.

  • Programmers often reuse code written by others that is published as open source and free to use 3.2.A.3. Open source code comes with a license that says what you may do with it, for example that you must keep the author’s name and the license text.
  • To include code that is not published as open source, the programmer must obtain permission and often purchase the code before putting it in their program 3.2.A.3.

A good habit is to record where reused code came from, right in a comment:

public class TextUtils
{
    // The method below is adapted from an open source utility library.
    // It is free to use under that library's license, which asks us
    // to keep this notice and credit the original authors.
    public static String initials(String first, String last)
    {
        return first.substring(0, 1) + last.substring(0, 1);
    }
}
System.out.println(TextUtils.initials("Sam", "Rivera"));
System.out.println(TextUtils.initials("Lee", "Chen"));

Output:

SR
LC
Situation Can you use the code?
Open source library, free to use, you follow its license Yes 3.2.A.3
A company’s code you found in a leaked file No: it is not open source and you have no permission.
A paid library you have not bought or licensed Only after you obtain permission, which often means buying it 3.2.A.3

Lock it in: memory hooks

  • ReliabilityReliable = works as expected, under the stated conditions, without failure. Test normal, edge and odd.
  • ImpactsS.E.C.: society, economy, culture. Each one can gain or lose.
  • Reusing codeOpen source: use it under its license. Not open source: ask, and usually pay.

Common misconceptions

  • "If a program works on the example input, it is reliable."

    Not quite. Reliability means it works as expected under all the stated conditions. Test typical values, boundary values (like 0 or the largest allowed value) and unusual cases, not just one example.

  • "Code I find online is free to copy into my program."

    Not quite. Code is intellectual property. Open source code published as free to use can be reused under its license terms. Code that is not open source needs the owner's permission, and often you must buy it.

  • "A program built to help people cannot cause harm."

    Not quite. Programs made to fill a need or solve a problem can still have unintended harmful effects beyond their intended use.

Exam traps

  • Reliability is about working as expected under the stated conditions, not about running fast.
  • An unintended harmful effect still counts as an impact of the program, even though the programmer did not plan it.
  • Code that is not open source cannot just be credited and used: the programmer must obtain permission and often purchase it.

2PracticeRecall it, then check yourself

In 30 seconds

  1. System reliability: the program performs its tasks as expected under stated conditions without failure.
  2. Maximize reliability by testing with a variety of conditions: typical, boundary and unusual inputs.
  3. Programs impact society, the economy and culture; the impacts can be beneficial and harmful.
  4. A program meant to solve a problem can have unintended harmful effects beyond its intended use.
  5. Open source code published as free to use can be reused; other code needs permission and often a purchase.

Cover this list, say the points out loud, then take the checkpoint without scrolling back up.

Checkpoint · 4 questions

Checkpoint: Impact of Program Design

Pick an answer to mark it. Every answer is explained, and you can try any question again. Your saved score counts first tries only, and stays in this browser.

  1. 1 Consider the following method, which is intended to return the average number of points per game. A programmer tests it only with averagePoints(30, 3), which returns 10. Which additional test call would best help improve the reliability of the method? 3.2.A.1
    public static int averagePoints(int totalPoints, int games)
    {
        return totalPoints / games;
    }
    Show answer

    Answer: C. Reliability improves when the program is tested with a variety of conditions, including unusual ones. A call with 0 games causes an ArithmeticException (division by zero), which shows the method does not yet handle a player who has not played. The other three calls are typical cases very similar to the first test, so they would all return 10 and reveal nothing new.

  2. 2 A city releases an app that lets residents report broken streetlights by taking a photo. Repairs in neighborhoods with many app users become faster, while repairs in neighborhoods where fewer residents own smartphones become slower. Which of the following best describes this situation? 3.2.A.2
    Show answer

    Answer: A. The app was built to solve a real problem, but it shifted repair work toward areas with more smartphone users, an unintended harmful effect on society. Nothing says the app crashes or fails, so reliability is not the issue. Nothing is copied, so intellectual property is not involved, and good intentions do not prevent harmful impacts.

  3. 3 A programmer wants to add a chart-drawing library to a game. The library is sold by a company and is not published as open source. Which of the following must the programmer do before including the library's code in the game? 3.2.A.3
    Show answer

    Answer: D. Code that is not published as open source requires the programmer to obtain permission and often purchase it before integrating it. A credit comment is good practice but does not give permission. Leaving the code unchanged or renaming its variables does not change who owns it.

  4. 4 Consider the following class. The code segment below the class appears in a method in another class. What is printed as a result of executing the code segment? 3.2.A.1
    public class Ticket
    {
        /** Returns the price; children under 12 pay half */
        public static int price(int fullPrice, int age)
        {
            if (age < 12)
            {
                return fullPrice / 2;
            }
            return fullPrice;
        }
    }
    
    System.out.print(Ticket.price(15, 11) + " ");
    System.out.print(Ticket.price(15, 12) + " ");
    System.out.print(Ticket.price(15, 0));
    Show answer

    Answer: A. Testing the boundary (ages 11 and 12) and an extreme value (age 0) is how reliability is checked. Age 11 is under 12, so the result is 15 / 2, which is 7 with integer division. Age 12 is not under 12, so it pays 15. Age 0 is under 12, so it pays 7. The option with 7.5 forgets that int division drops the decimal part, and 7 7 7 treats age 12 as a child.

3PrevailLock it in for exam day

By the numbers

Name each list from memory, then reveal it to check. Each list shows how many items to recall.

  • Areas that programs impact three areas CED 3.2.A.2
    1. society
    2. the economy
    3. culture
  • Ways to reuse code legally two ways CED 3.2.A.3
    1. use code published as open source and free to use
    2. obtain permission (and often purchase) for code that is not open source

Key terms: flip the cards

Read the term, say the definition out loud, then flip to check. Struggling a little to remember is what makes it stick.

  • System reliabilitytap to flip

    A program's ability to perform its tasks as expected under stated conditions without failure.

    Example and CED codes
  • Intellectual propertytap to flip

    Creations of the mind, such as program code, that belong to their authors; reusing code raises legal and licensing questions.

    Example and CED codes
  • Open sourcetap to flip

    Code that its authors publish for others to use, study and reuse, under a license that states the conditions.

    Example and CED codes
  • Program designtap to flip

    Planning a program's classes, with each class's attributes and behaviors, in natural language or a diagram before writing code.

    Example and CED codes
  • Methodtap to flip

    A named block of code that only runs when it is called.

    Example and CED codes

Questions students ask

What is system reliability in AP® Computer Science A?

System reliability means the program can perform its tasks as expected under stated conditions without failure. Programmers improve it by testing the program with a wide variety of conditions.

Can I use code from the internet in my program?

Only if you are allowed to. Open source code published as free to use can be reused by following its license. For code that is not open source, you need permission from the owner and often have to buy it.

What is an unintended harmful effect of a program?

It is harm the program causes that its designers did not plan, often when the program is used beyond its intended purpose, such as a route app that sends heavy traffic through quiet streets.

Was this page helpful?

No names are ever shown, and every public comment is checked by us first. Please do not include personal details. To get a reply, email [email protected].

↑ Top

Enlarged view of the selected figure