Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Build a Mini Library System | Organizing and Applying OOP in PHP
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Object-Oriented PHP

bookChallenge: Build a Mini Library System

Oppgave

Swipe to start coding

Create a class named Library with a method called borrowBook. This method should:

  • Accept the name of a book as a parameter.
  • Throw an Exception with a clear message if the requested book is not in the library's list of books.
  • If the book is available, remove it from the list (no need to return anything).

When calling the borrowBook method, catch the exception and print its message using echo.

Follow these steps:

  • Implement the borrowBook method inside the Library class.
  • In the provided code, try to borrow the book 'The Great Gatsby'.
  • Catch any exception and print its message.

Løsning

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 4
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

close

bookChallenge: Build a Mini Library System

Sveip for å vise menyen

Oppgave

Swipe to start coding

Create a class named Library with a method called borrowBook. This method should:

  • Accept the name of a book as a parameter.
  • Throw an Exception with a clear message if the requested book is not in the library's list of books.
  • If the book is available, remove it from the list (no need to return anything).

When calling the borrowBook method, catch the exception and print its message using echo.

Follow these steps:

  • Implement the borrowBook method inside the Library class.
  • In the provided code, try to borrow the book 'The Great Gatsby'.
  • Catch any exception and print its message.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 4
single

single

some-alt