Files
abap-llm/tasks_gen/eval/G0186/spec.md

16 lines
2.7 KiB
Markdown

Hello, please create the class {{P}}COURSE_BOOKING in package $TMP. The class is public, final, and has a public constructor without parameters. The class has these public types. TY_COURSE_ID has type C and length 10. TY_CATEGORY has type C and length 10. TY_COURSE_INFO is a structure with components COURSE_ID type TY_COURSE_ID, TITLE type C length 40, and FREE_SEATS type I. TT_COURSE_INFO is a standard table of TY_COURSE_INFO with an empty key. The class has these public methods. GET_FREE_SEATS imports IV_COURSE_ID type TY_COURSE_ID and returns RV_FREE_SEATS type I. IS_BOOKABLE imports IV_COURSE_ID type TY_COURSE_ID and IV_SEATS type I and returns RV_BOOKABLE type ABAP_BOOL. LIST_BOOKABLE_COURSES imports IV_CATEGORY type TY_CATEGORY and IV_SEATS type I and returns RT_COURSES type TT_COURSE_INFO. Do not add other public methods.
The database table {{P}}COURSE exists in package $TMP. It has columns MANDT (client), COURSE_ID (CHAR 10, key), CATEGORY (CHAR 10), TITLE (CHAR 40), CAPACITY (INT4), and BOOKED (INT4). CAPACITY is the number of seats of the course. BOOKED is the number of seats that are already sold. The class {{P}}SEED_COURSES fills the table with example data. It is active.
The booking program needs one service that answers three questions. How many seats are free in a course? Can we book a given number of seats in a course? Which courses of a category still have enough free seats? There are no open questions.
When you calculate free seats, read the course with the course ID. If the table has no course with this ID, the free seats are 0. The free seats are the capacity minus the booked seats. If the capacity minus the booked seats is less than 0, the free seats are 0. GET_FREE_SEATS returns the free seats of the course.
When you check IS_BOOKABLE, if IV_SEATS is less than 1, the result is false. If the table has no course with this ID, the result is false. The result is true if IV_SEATS is less than or equal to the free seats of the course. Else the result is false.
When you list bookable courses, read all courses with the category IV_CATEGORY. Use only the courses whose free seats are greater than or equal to IV_SEATS. Sort the result in ascending order by COURSE_ID. Each result row has the COURSE_ID, the TITLE and the free seats of the course. If no course matches, the result is empty.
The release target is 8.16. Use Clean ABAP coding standards. Keep each method below 40 statements. Do not use global variables. Do not write a comment that restates the code. Do not change the table {{P}}COURSE and the class {{P}}SEED_COURSES.
The class must be active and have no syntax error. The hidden tests must pass. Write your own ABAP Unit tests for the class.