IBDP Computer Science A1.2 Data representation and computer logic HL Paper 2 - New Syllabus

Question 

The system, which is designed to manage artworks, sales and customers, should have methods to find artworks that match a specific request made by a customer.

For example, a customer may want to find all artworks by Sebastián Müller.

(a) State the initial value of noOfArtworks for an artist.
(b) Construct the method sortArt() in the Artist class that will find the five most expensive artworks for a given artist.

You must make use of the selection sort algorithm.

Artists must pay a 15% commission to the shop for each of their artworks sold there.

The method commissionToPay calculates the commission to be paid by an artist on all sold artworks.

(c) Construct the method commissionToPay that will calculate and return the amount of commission to be paid by the artist to the shop.
(d) Outline why Unicode enables internationalization.

Most-appropriate topic code

B3.2: Fundamentals of OOP for multiple classes [HL only] — parts (a), (b) and (c)
A1.2: Data representation and computer logic — part (d)
▶️ Answer/Explanation

(a)

0

The initial value of noOfArtworks is 0 because an artist has no artworks stored in the array when the Artist object is first created.

(b)

The method uses selection sort to arrange the artworks in descending order of artworkPrice. The five most expensive artworks are then copied into a temporary array and returned.

public Artwork[] sortArt()
{
    for (int i = 0; i < noOfArtworks - 1; i++)
    {
        int max_index = i;

        for (int j = i + 1; j < noOfArtworks; j++)
        {
            if (theArtworks[j].getArtworkPrice() >
                theArtworks[max_index].getArtworkPrice())
            {
                max_index = j;
            }
        }

        Artwork temp = theArtworks[max_index];
        theArtworks[max_index] = theArtworks[i];
        theArtworks[i] = temp;
    }

    Artwork[] expensive = new Artwork[5];

    for (int i = 0; i < 5; i++)
    {
        expensive[i] = theArtworks[i];
    }

    return expensive;
}

Explanation: For each position, the algorithm searches the remaining artworks for the artwork with the highest price. It then swaps that artwork into the current position. After sorting, the first five elements contain the five most expensive artworks.

If there are fewer than five artworks, the loop should be adjusted so that it does not access positions beyond noOfArtworks.

(c)

The method must examine each artwork, identify those that have been sold, add their prices to a total, and then calculate 15% of the total.

public double commissionToPay()
{
    double total = 0;

    for (int i = 0; i < noOfArtworks; i++)
    {
        if (theArtworks[i].getIsSold() == true)
        {
            total = total + theArtworks[i].getArtworkPrice();
        }
    }

    double commission = total * 0.15;

    return commission;
}

Explanation: The loop checks every artwork in the artist’s collection. Only sold artworks are included in total. The commission is then calculated as \(15\%\) of the total value of the sold artworks:

\( \mathrm{commission} = \mathrm{total} \times 0.15 \)

(d)

Unicode provides a much larger character set than ASCII, with support for a very large number of characters and symbols from different languages.

This allows characters from different alphabets and languages to be represented and stored consistently, reducing language barriers and supporting internationalization.

Unicode uses more bits than basic ASCII and can represent approximately \(2^{16}\) characters in its original 16-bit representation, with modern Unicode supporting an even larger range of code points.

Scroll to Top