0% found this document useful (0 votes)
8 views1 page

Using System

Java Coding Activity

Uploaded by

Pep Chibi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Using System

Java Coding Activity

Uploaded by

Pep Chibi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System; using System.Collections.

Generic;
using System.Collections.Generic; public class Book
public class Book {
{ public string Title { get; set; }
public string Title { get; set; } public string Author { get; set; }
public string Author { get; set; }
public Book(string title, string author)
public Book(string title, string author) {
{ Title = title;
Title = title; Author = author;
Author = author; }
} public void Display()
public void Display() {
{ Console.WriteLine($"Title: {Title},
Console.WriteLine($"Title: {Title}, Author: {Author}");
Author: {Author}"); }
} }
} public class Library
public class Library {
{ public string Name { get; set; }
public string Name { get; set; } private List<Book> books;
private List<Book> books;
public Library(string name)
public Library(string name) {
{ Name = name;
Name = name; books = new List<Book>();
books = new List<Book>(); }
}
public void AddBook(Book book)
public void AddBook(Book book) {
{ books.Add(book);
books.Add(book); }
}
public void DisplayBooks()
public void DisplayBooks() {
{ Console.WriteLine($"Library: {Name}");
Console.WriteLine($"Library: {Name}"); foreach (var book in books)
foreach (var book in books) {
{ book.Display();
book.Display(); }
} }
} }
} public class Program
public class Program {
{ public static void Main()
public static void Main() {
{ Book book1 = new Book("1984",
Book book1 = new Book("1984", "George Orwell");
"George Orwell"); Book book2 = new Book("To Kill a
Book book2 = new Book("To Kill a Mockingbird", "Harper Lee");
Mockingbird", "Harper Lee");
Library library = new Library("City
Library library = new Library("City Library");
Library");
library.AddBook(book1);
library.AddBook(book1); library.AddBook(book2);
library.AddBook(book2);
library.DisplayBooks();
library.DisplayBooks(); }
} }
}
using System;

You might also like