IBDP Computer Science B2.3 Programming constructs SL Paper 2 - New Syllabus

Question 

(a) (i) The following code fragment has been written to count and output the number of civil lawyers and company lawyers that the law firm has:

int x = 0;
int countA = 0;

while (x > 20)
{
    if(allLawyers[x].getLawyerType().equals("civil"))
        countA++;

    else if(allLawyers[x].getLawyerType().equals("company"))
        countB++;
}

System.out.println("civil: " + countA + " company: " + countB);

Identify three reasons why this code does not work as expected. [3]

(a) (ii) Construct a method, displayClientName(), to display all client names of company lawyers who are judgment based on the case. Assume that there will always be at least one such client. The method must:
  • search the allLawyers[] array for lawyers whose type is “company”;
  • search the lawyerCases[] array for judgmentGiven is ‘A’;
  • output the client’s name.

[7]

The law firm is considering the use of open source software as part of its software development process.

(b) Discuss the impact of the open source movement on the software industry. [5]

Most-appropriate topic code

• B2.3: Programming constructs — part (a)
• A3.3: Software development — part (b)
▶️ Answer/Explanation

(a) (i)
Award [3 max]

  • The condition for the while loop is incorrect. It should be x < 20, otherwise the loop will never execute when x starts at 0.
  • The value of x is never incremented, so even with a corrected condition the loop would not progress through the allLawyers[] array.
  • The variable countB has not been declared, causing a compile-time error because it is unknown.

(a) (ii)
Award [7 max]

The method should search all lawyers, select those whose type is "company", then search each lawyer’s cases. A null check is required before accessing a case.

public static void displayClientName()
{
    for(int i = 0; i < 20; i++)
    {
        if(allLawyers[i].getLawyerType().equals("company"))
        {
            for(int j = 0; j < 15; j++)
            {
                if(allLawyers[i].getLawyerCases()[j] != null)
                {
                    Case C = allLawyers[i].getLawyerCases()[j];

                    if(C.getJudgementGiven() == 'A')
                    {
                        String cName = C.getCaseClient();
                        System.out.println(cName);
                    }
                }
            }
        }
    }
}

This earns marks for the outer loop through allLawyers[], checking for "company", looping through the lawyer’s cases, checking for null, accessing the case correctly, checking whether judgementGiven is 'A', and outputting the client’s name.

(b)
Award [5 max]

Advantages:

  • Collaboration: open source software provides a collaborative and transparent approach because developers can inspect, modify and contribute to the source code.
  • Lower cost: software can be freely available, allowing organizations to develop more affordable and cost-effective solutions.
  • Flexibility: source code can be modified and adapted to meet specific needs, potentially improving the quality and functionality of software.

Disadvantages:

  • Open source software may not always use the best security practices, potentially creating security vulnerabilities.
  • Incorrect use or modification of open source software can result in licensing violations and other intellectual-property issues.

Conclusion: The open source movement has had a significant positive impact by encouraging collaboration, reducing software costs and increasing flexibility, although organizations must manage security and licensing risks carefully.

Scroll to Top